6 registered members (TipmyPip, Niels, dBc, Ed_Love, 3run, 1 invisible),
17,843
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
water -> sin() wave + normals?
#355906
01/29/11 20:39
01/29/11 20:39
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
i haven't done any shader programming since a long time...  i have to do a very simple water shader with a sin() wave. my question is, does anyone have any tips about how to handle the normals? how should i transform them to still get a correct lighting? rotate them with sin()/cos() somehow or is there a better way? this is what i have so far (it needs to be shader model 1.1 unfortunately):
MATERIAL* mtl_water =
{
effect =
"
float3 vecSunDir;
float4 vecTime;
float4x4 matWorld;
float4x4 matWorldViewProj;
texture entSkin1;
sampler SKIN1 = sampler_state {texture = <entSkin1>;};
//----------------------------------------------------------------------- color
void p0mainVS(
in float4 inPosition : POSITION0,
in float2 inTexCoord : TEXCOORD0,
in float3 inNormal : NORMAL,
out float4 outPosition : POSITION0,
out float2 outTexCoord : TEXCOORD0,
out float3 outDiffuse : COLOR0)
{
inPosition.y += sin((vecTime.w + inPosition.x) * 0.1) * 8;
outPosition = mul(inPosition, matWorldViewProj);
outTexCoord = inTexCoord;
outDiffuse = saturate(dot(mul(inNormal, matWorld), -vecSunDir)) * 0.6 + 0.4;
}
void p0mainPS(
in float4 inTexCoord: TEXCOORD0,
in float3 inDiffuse : COLOR0,
out float4 outColor : COLOR0)
{
float4 color = tex2D(SKIN1, inTexCoord);
outColor = color * float4(inDiffuse, 0.8);
}
//----------------------------------------------------------------------- technique
technique t0
{
pass p0
{
//zWriteEnable = false;
VertexShader = compile vs_1_1 p0mainVS();
PixelShader = compile ps_1_1 p0mainPS();
}
}
";
}
|
|
|
Re: water -> sin() wave + normals?
[Re: ventilator]
#355914
01/29/11 21:01
01/29/11 21:01
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
I usually use the cross product of the directions to two other points close to the current vertex. In your case one could of course simplify that a bit. No idea if it fits into the shadermodel though... If I didn´t confuse a1-3 and b1-3 something like this should do the job:
float height = sin((vecTime.w + inPosition.x) * 0.1) * 8;
float heightnext = sin((vecTime.w + inPosition.x+VERTDISTINX) * 0.1) * 8;
inPosition.y += height;
inNormal = normalize(float3((heightnext-height)*VERTDISTINX, -VERTDISTINX*VERTDISTINX, 0.0));
Last edited by Slin; 01/29/11 21:43.
|
|
|
Re: simple 1.1 hatching shader?
[Re: Slin]
#355943
01/29/11 23:00
01/29/11 23:00
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
if(inDiffuse.x < 0.15) outColor = float4(color2.b, color2.b, color2.b, 1.0); else if(inDiffuse.x < 0.3) outColor = float4(color2.g, color2.g, color2.g, 1.0); else if(inDiffuse.x < 0.45) outColor = float4(color2.r, color2.r, color2.r, 1.0); else if(inDiffuse.x < 0.6) outColor = float4(color1.b, color1.b, color1.b, 1.0); else if(inDiffuse.x < 0.75) outColor = float4(color1.g, color1.g, color1.g, 1.0); else outColor = float4(color1.r, color1.r, color1.r, 1.0);
with if it works nicely, even with shader model 1.1. what does this get translated into? does this have any disadvantages? edit: weird! how can so many ifs work with 1.1 (which just supported 8 assembler instructions if i remember correctly)? could it be that ps_1_1 gets ignored and the shader model of the gpu always gets used? which would be really stupid since my card supports 4.0 and i have to develop for 1.1. is there some way to force 1.1? The problem there is interpolation, but I doubt that you will stay wthin the limits otherwize. the hard borders don't look as well as i had imagined. so interpolation probably would be better anyway.
|
|
|
Re: simple 1.1 hatching shader?
[Re: ventilator]
#355963
01/30/11 02:29
01/30/11 02:29
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
crap, it seems like 1.1 pixel shaders aren't supported anymore with hlsl and it silently compiles to 2.0 instead. i hate assembler.  Really? Where'd you find that? Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: simple 1.1 hatching shader?
[Re: ventilator]
#355966
01/30/11 02:39
01/30/11 02:39
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Wow. That makes sense. I was surprised to not need to write 1.1 fallbacks for KarBOOM, since compiling for 1.1 appeared to work.
Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|