PS 1.1 water - Adjusting RGB during runtime

Posted By: Thomas_Nitschke

PS 1.1 water - Adjusting RGB during runtime - 08/23/05 15:34

Hi@all!
Ok I've got the following code (by Steempipe) working and set to go:
Code:

technique drawWater
{
pass p0
{
AlphaBlendEnable = true;
ZwriteEnable = true;
ZEnable = true;
Sampler[0] = (s_Bump);
Sampler[3] = (s_Cube);
PixelShaderConstant[0] = float4(0.3,0.4,vecSkill1.x,0.75);
VertexShader = compile vs_1_1 WaterBump_VS();
PixelShader =
asm
{
ps.1.1
tex t0
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
mul r0, t3, c0
};
}
}


The question now is: How could I tell the pixelshader to accept vecSkill1 - 4 in the PixelShaderConstant[0] declaration? Strangely, it actually does accept the skills, but only one at a time, be it r,g,b or alpha. Any of the shader gurus who knows how to do this, any help is appreciated...
Posted By: ello

Re: PS 1.1 water - Adjusting RGB during runtime - 08/23/05 18:18

use vecSkill1.x, vecSkill1.y,vecSkill1.z and vecSkill1.w (or rgba)
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/23/05 19:05

Thx for your reply, I'll give it a try. I'll let you know if it doesn't work, however

EDIT: Oops, nearly forgot to ask... how then can I access these by script? In C-Script, I can only tell him mat_blabla.skill1 = float(blubb), but how would I make him understand I want to change the x,y,z and w components?


Ok here goes: ERROR invalid subscript 'w'.. just in case you didn't notice, I'm nOOb to shaders
Posted By: ello

Re: PS 1.1 water - Adjusting RGB during runtime - 08/24/05 06:24

did you try r,g,b and a instead of x,y,z and w?

if you want it to be modelspecific use vecSkill41 and set the models skill41 - 44(43) with floats
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/24/05 11:22

Yep just tried it, it's not working though. He keeps telling me "invalid subscript a" which seems logical to me because vecSkill1 is declared as float3, so, even from what I as a noOb do actually understand, it can't contain 4 values, can it?

Concerning vecSkill41-44, I know about those, but whyever only the value of vecskill41 seems to be passed to the shader, the rest is just ignored, no matter to what values I set them...
Posted By: ello

Re: PS 1.1 water - Adjusting RGB during runtime - 08/24/05 11:32

hmf, schick mir mal deinen code dann schau ichs mir heute abend an
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/25/05 13:54

Jap das is nett!

I'll post the code here just in case anyone else wants to have a go on it!
Code:

material mat_water
{
power = 10;
ambient_red = 0;
ambient_green = 0;
ambient_blue = 0;
diffuse_red = 200;
diffuse_blue = 200;
diffuse_green = 200;
albedo = 50;
specular_red = 0;
specular_green = 0;
specular_blue = 0;
emissive_red = 0;
emissive_blue = 0;
emissive_green = 0;
skin1 = sfx_waterBump0;
skin2 = sfx_cubemap0;
flags = tangent;
event = eff_initWater;
}

function eff_initWater()
{
bmap_to_cubemap(mtl.skin2);
//bmap_to_mipmap(mtl.Skin1);
return(false);
}

water.fx:

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldView;
float3 vecViewPos;
float3 vecSkill41;
float3 vecSkill1;
float4 vecFog;
Texture mtlSkin1;
Texture mtlSkin2;

sampler s_Bump = sampler_state
{
Texture = (mtlSkin1);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler s_Cube = sampler_state
{
Texture = (mtlSkin2);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};
struct VS_IN
{
float4 Pos: POSITION;
float3 Normal: NORMAL;
float2 Bump: TEXCOORD0;
float3 Tangent: TEXCOORD1;
};
struct VS_OUT
{
float4 Pos: POSITION;
float Fog: FOG;
float2 Bump: TEXCOORD0;
float4 TanToCube0: TEXCOORD1;
float4 TanToCube1: TEXCOORD2;
float4 TanToCube2: TEXCOORD3;
};
VS_OUT WaterBump_VS(VS_IN IN)
{
VS_OUT Out;
Out.Pos = mul(IN.Pos, matWorldViewProj);
float2 WaveDir;
WaveDir.x = 5*IN.Bump.x;
WaveDir.x += 0.01*vecSkill41.x;
WaveDir.y = 5*IN.Bump.y;
WaveDir.y += 0.01*vecSkill41.x;
Out.Bump = WaveDir.xy;
float3x3 ObjToTan;
ObjToTan[0] = IN.Tangent,
ObjToTan[1] = cross(IN.Normal, IN.Tangent);
ObjToTan[2] = 5*IN.Normal;
Out.TanToCube0.xyz = mul(ObjToTan, matWorld[0].xyz);
Out.TanToCube1.xyz = mul(ObjToTan, matWorld[1].xyz);
Out.TanToCube2.xyz = mul(ObjToTan, matWorld[2].xyz);
float3 PositionWorld = mul(IN.Pos, matWorld);
float3 ViewerDir = normalize(vecViewPos - PositionWorld);
Out.TanToCube0.w = ViewerDir.x;
Out.TanToCube1.w = ViewerDir.y;
Out.TanToCube2.w = ViewerDir.z;
float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * vecFog.z;
Out.Fog = ofog;
return Out;
}
technique drawWater
{
pass p0
{
AlphaBlendEnable = true;
ZwriteEnable = true;
ZEnable = true;
Sampler[0] = (s_Bump);
Sampler[3] = (s_Cube);
PixelShaderConstant[0] = {0.3,0.3,0.4,0.50};
//PixelShaderConstant[0] = float4(vecSkill1.r,vecSkill1.g,vecSkill1.b,vecSkill1.a);

VertexShader = compile vs_1_1 WaterBump_VS();
PixelShader =
asm
{
ps.1.1
tex t0
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
mul r0, t3, c0
};
}
}
technique fallback
{
pass p0
{
Texture[0] = <mtlSkin1>;
}
}


Posted By: ello

Re: PS 1.1 water - Adjusting RGB during runtime - 08/26/05 09:24

PixelShaderConstant[0] = float4(vecSkill41.r,vecSkill41.g,vecSkill41.b,1);

and what you have to do is to create an action for your model and set the skills there (my.skill41=float(... and so on)

i just did a quick test using random numbers and it works fine

and btw, you didnt assign the fx-file to the material (effect="water.fx";)
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/26/05 15:23

Yep, that works! Thanks a lot
Is there a way to do this with the alpha value, too? If I try using vecSkill1.a or something of the like, it keeps telling me "invalid subscript: a"... This is not too important, though.
BTW, I did assign the FX file, just I did it with a helper function and not directly.
Posted By: ello

Re: PS 1.1 water - Adjusting RGB during runtime - 08/26/05 20:20

use vecSkill41.a , this should work

you are much more flexible if u use the entities skill41-44 for passing colorvalues for example
because then you can use the shader on different models with different colors
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/28/05 14:15

Okay, everything working now.
Thanks!
Posted By: XNASorcerer

Re: PS 1.1 water - Adjusting RGB during runtime - 08/28/05 19:19

Put the code here for other people to use and to learn.
Posted By: Thomas_Nitschke

Re: PS 1.1 water - Adjusting RGB during runtime - 08/29/05 12:29

This is the code I already posted above, modified with what happens to work for me
Code:

material mat_water
{
power = 10;
ambient_red = 0;
ambient_green = 0;
ambient_blue = 0;
diffuse_red = 200;
diffuse_blue = 200;
diffuse_green = 200;
albedo = 50;
specular_red = 0;
specular_green = 0;
specular_blue = 0;
emissive_red = 0;
emissive_blue = 0;
emissive_green = 0;
skin1 = sfx_waterBump0;
skin2 = sfx_cubemap0;
flags = tangent;
event = eff_initWater;
}

function eff_initWater()
{
bmap_to_cubemap(mtl.skin2);
//bmap_to_mipmap(mtl.Skin1);
/* new: */ mtl.skill1 = float(waterColor_red);
/* new: */ mtl.skill2 = float(waterColor_green);
/* new: */ mtl.skill3 = float(waterColor_blue);
return(false);
}

water.fx:

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldView;
float3 vecViewPos;
float3 vecSkill41;
float3 vecSkill1;
float4 vecFog;
Texture mtlSkin1;
Texture mtlSkin2;

sampler s_Bump = sampler_state
{
Texture = (mtlSkin1);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};
sampler s_Cube = sampler_state
{
Texture = (mtlSkin2);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};
struct VS_IN
{
float4 Pos: POSITION;
float3 Normal: NORMAL;
float2 Bump: TEXCOORD0;
float3 Tangent: TEXCOORD1;
};
struct VS_OUT
{
float4 Pos: POSITION;
float Fog: FOG;
float2 Bump: TEXCOORD0;
float4 TanToCube0: TEXCOORD1;
float4 TanToCube1: TEXCOORD2;
float4 TanToCube2: TEXCOORD3;
};
VS_OUT WaterBump_VS(VS_IN IN)
{
VS_OUT Out;
Out.Pos = mul(IN.Pos, matWorldViewProj);
float2 WaveDir;
WaveDir.x = 5*IN.Bump.x;
WaveDir.x += 0.01*vecSkill41.x;
WaveDir.y = 5*IN.Bump.y;
WaveDir.y += 0.01*vecSkill41.x;
Out.Bump = WaveDir.xy;
float3x3 ObjToTan;
ObjToTan[0] = IN.Tangent,
ObjToTan[1] = cross(IN.Normal, IN.Tangent);
ObjToTan[2] = 5*IN.Normal;
Out.TanToCube0.xyz = mul(ObjToTan, matWorld[0].xyz);
Out.TanToCube1.xyz = mul(ObjToTan, matWorld[1].xyz);
Out.TanToCube2.xyz = mul(ObjToTan, matWorld[2].xyz);
float3 PositionWorld = mul(IN.Pos, matWorld);
float3 ViewerDir = normalize(vecViewPos - PositionWorld);
Out.TanToCube0.w = ViewerDir.x;
Out.TanToCube1.w = ViewerDir.y;
Out.TanToCube2.w = ViewerDir.z;
float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * vecFog.z;
Out.Fog = ofog;
return Out;
}
technique drawWater
{
pass p0
{
AlphaBlendEnable = true;
ZwriteEnable = true;
ZEnable = true;
Sampler[0] = (s_Bump);
Sampler[3] = (s_Cube);
/* new */ PixelShaderConstant[0] = float4(vecSkill1.r,vecSkill1.g,vecSkill1.b,0.8); //last value = alpha
VertexShader = compile vs_1_1 WaterBump_VS();
PixelShader =
asm
{
ps.1.1
tex t0
texm3x3pad t1, t0_bx2
texm3x3pad t2, t0_bx2
texm3x3vspec t3, t0_bx2
mul r0, t3, c0
};
}
}
technique fallback
{
pass p0
{
Texture[0] = <mtlSkin1>;
}
}



Have fun with it, and thanks again @ello ^^
© 2024 lite-C Forums