Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 470 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Shaders: Changing the ambient color at runtime #392652
01/25/12 14:02
01/25/12 14:02
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Hello guys.

I`m searching for a possibility to change the ambient (/lighting) values (RGB) of a specific waving grass shader at runtime.

Therefore I included the shader this way, but the shader doesn`t seem to react to ambient values at all.

Code:
function mtl_veg_event()
{
	set(mtl,ENABLE_RENDER);	
	vec_set(mtl.ambient_blue,vector((d3d_fogcolor1.blue/2)+(mat_model.ambient_blue)+objekt_blau,(d3d_fogcolor1.green/2)+(mat_model.ambient_green)+objekt_gruen,objekt_rot+(d3d_fogcolor1.red/2)+(mat_model.ambient_red)));
}

MATERIAL* mtl_veg =
{
	event = mtl_veg_event;
	effect = "vegetation.fx";
}
action shader_vegetation()
{
   my.material = mtl_veg;
}



And this is shader in asm language. Maybe anybody of you is able to find a solution for my problem? I would really apperciate it.
Code:
texture entSkin1;
		
matrix matWorldViewProj;
matrix matWorldView;
		
vector vecFog;
vector vecTime;
		
technique Grass
{
	pass p0
	{
		texture[0]=<entSkin1>;
		zWriteEnable=true;
		alphaTestEnable=true;
		cullMode=none;
		
		vertexShaderConstant[0]=<matWorldViewProj>;
		vertexShaderConstant[8]=<matWorldView>;
		vertexShaderConstant[16]=<vecFog>;
		vertexShaderConstant[32]=<vecTime>;
		vertexShaderConstant[33]={0.0f,0.5f,1.0f,2.0f};										// common constants
		vertexShaderConstant[34]={-0.16161616f,0.0083333f,-0.00019841f,0.000002755731f};	// {-1/3!,1/5!,-1/7!,1/9!}
		vertexShaderConstant[35]={4.0f,1.57079632f,3.14159265f,6.28318530f};				// {4.0,pi/2,pi,pi*2}
		vertexShaderConstant[36]={1.07f,0.0f,0.0f,0.0f};									// fixup factor
		
		vertexShaderConstant[40]={3.5f,1.2f,0.8f,0.1f};										// wave distort x
		vertexShaderConstant[41]={1.0f,2.0f,1.6f,0.1f};									// wave distort y
		vertexShaderConstant[42]={-0.4f,-0.9f,-0.9f,-0.01f};								// wave distort z
		vertexShaderConstant[43]={-0.1f,-0.2f,0.1f,0.05f};									// wave dir x
		vertexShaderConstant[44]={-0.005f,-0.01f,-0.005f,-0.0025f};							// wave dir y
				//vertexShaderConstant[45]={0.01f,0.02f,0.025f,0.05f};									// wave speed
		vertexShaderConstant[45]={0.004f,0.006f,0.006f,0.06f};									// wave speed
		vertexShaderConstant[46]={0.25f,0.05f,0.05f,0.02f};									// lighting wave scale
		vertexShaderConstant[47]={0.3f,0.4f,0.2f,0.0f};										// lighting scale bias
		
		vertexShader=
		asm
		{
			vs.1.1
		
			dcl_position  v0
			dcl_normal    v3
			dcl_texcoord0 v7
			dcl_texcoord1 v8
		
			mov r1.w,c16.w                  // r1.w=1
			dp4 r0,v0,c10                   // distance to camera position (v0 is the position without sinusodial warping!)
			add r0,r0,-c16.x                // distance-fog_start
			mad r0.x,-r0.x,c16.z,r1.w       // 1-(distance-fog_start)*(1/(fog_end-fog_start))
			max oFog,r0.x,c33.x           // clamp with custom max value
		
			mul r0,c43,v0.x                 // use vertex pos x as inputs to sinusoidal warp
			mad r0,c44,v0.y,r0              // use vertex pos y as inputs to sinusoidal warp
		
			mov r1,c32.w                    // get current time
			mad r0,r1,c45,r0                // add scaled time
			frc r0.xy,r0                    // take fraction of all 4 components
			frc r1.xy,r0.zwzw
			mov r0.zw,r1.xyxy
		
			mul r0,r0,c36.x                 // multiply by fixup factor (due to inaccuracy of taylor series)
			sub r0,r0,c33.y                 // subtract 0.5
			mul r1,r0,c35.w                 // range -pi to pi
		
			mul r2,r1,r1                    // wave_vec^2
			mul r3,r2,r1                    // wave_vec^3
			mul r5,r3,r2                    // wave_vec^5
			mul r7,r5,r2                    // wave_vec^7
			mul r9,r7,r2                    // wave_vec^9
		
			mad r0,r3,c34.x,r1              // wave_vec-(wave_vec^3)/3!
			mad r0,r5,c34.y,r0              // +(wave_vec^5)/5!
			mad r0,r7,c34.z,r0              // -(wave_vec^7)/7!
			mad r0,r9,c34.w,r0              // +(wave_vec^9)/9!
		
			dp4 r3.x,r0,c40
			dp4 r3.y,r0,c41
			dp4 r3.zw,r0,c42
		
			sub r4,c33.z,v7.y               // attenuate sinusoidal warping by (1-uv.y)^2
			mul r4,r4,r4
			mul r3,r3,r4
		
			mov r2.w,v0
			add r2.xyz,r3,v0                // add sinusoidal warping to grass position
			m4x4 oPos,r2,c0                 // transform position to clip space
		
			dp4 r1.x,r0,c46                 // scale and add sin waves together
			mad oD0,c47.xzxz,-r1.x,c47.y    // scale and bias color values (green is scaled more than red and blue)
			mov oT0.xy,v7.xy                // output uvs
		};
		
		pixelShader=
		asm
		{
			ps.1.3
			def c0,1,1,1,1
			def c1,0,0,0,0
			tex t0                  // sample t0
			mov r0,t0
			cnd r0.a,r0.a,c0,c1     // if(r0.a>0.5){r0.a=1;}else{r0.a=0;}
			mul_x2 r0.rgb,r0,v0     // modulate with lighting
		};
	}
}



Thanks a lot for helping me out with this!

- Robin

Re: Shaders: Changing the ambient color at runtime [Re: Rondidon] #392659
01/25/12 15:26
01/25/12 15:26
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Alternatively: Who knows a nice waving grass shader that also works for big meshes with the possibility to change the RGB values at runtime? laugh

Re: Shaders: Changing the ambient color at runtime [Re: Rondidon] #392667
01/25/12 17:10
01/25/12 17:10
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
The problem is that your event is only executed once, you have to set an appropriate Material flag (ENABLE_TREE, ENABLE_RENDER, I don't know, check the manual). It's already set.

Last edited by Superku; 01/25/12 18:05.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Shaders: Changing the ambient color at runtime [Re: Superku] #392802
01/27/12 16:19
01/27/12 16:19
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
How about fx_animTree?

Re: Shaders: Changing the ambient color at runtime [Re: Emre] #392804
01/27/12 16:25
01/27/12 16:25
Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Rondidon Offline OP
Expert
Rondidon  Offline OP
Expert

Joined: Aug 2002
Posts: 2,183
Germany, BaW�
Fx-animTree is not suited for my project. But Slin helped me with the implemention of the grass shader from "Project ship". So I`ve got a good solution now laugh


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1