Having only just started playing about with pixel shaders, and not fully understanding all the functions yet. Can someone give me a few pointers on how I can optimize the following bit of shader code. I am currently using to many arithmetic slots for shader 2.0 and I would prefer to keep to shader 2.0 if possible.
The effect I am looking for is a wavy water effect, the attempt I have made still isn't ideal as it is still a bit too uniform in appearance.
Input = offset value to maintain the effect while the screen scrolls. (float2)
External = Radians that cycle. (float)
xWaveLength1 , 2 etc = Variable to adjust the wave effect (float), I usually set these between 30 - 50.
xWaveVar1 ,2 etc = as above (float), I usually set these between 0.5 - 2.5.
I also shade the waves for a bit of a lighting effect.
Its probably really obvious, but I just can't see it yet (the optimization I need to do that is)
If you have any tips on less uniform wave patterns I would appreciate the advice.
| float4 PixelShaderFunction(float2 Tex : TEXCOORD0) : COLOR0 |
| { |
| Tix.x = Tex.x + (Input.x/640); |
| Tix.y = Tex.y + (Input.y/480); |
| TexAdjustX1 = (Tix.x -(sin(Tix.y))+ sin(External * xWaveLength1))*xWaveVar1; |
| TexAdjustX2 = (Tix.x-(Tix.y*0.33) + sin(External * xWaveLength2))*xWaveVar2; |
| |
| TexAdjustY1 = (Tix.y -(cos(Tix.x))+ sin(External * yWaveLength1))*yWaveVar1; |
| TexAdjustY2 = (Tix.y-(Tix.x*0.75) - sin(External * yWaveLength2))*yWaveVar2; |
| |
| TexAdjustY1 = sin(TexAdjustY1)+sin(TexAdjustY2); |
| TexAdjustX1 = sin(TexAdjustX1)+sin(TexAdjustX2); |
| Tex.y = Tex.y + |
| ( |
| TexAdjustY1 |
| ) * 0.01f; |
| Tex.x = Tex.x + |
| ( |
| TexAdjustX1 |
| ) * 0.01f; |
| color = tex2D(TextureSampler, Tex); |
| color.a = color.a * 0.75; |
| color.r += 0.03 * |
| ( |
| TexAdjustY1 |
| + |
| TexAdjustX1 |
| ); |
| color.g += 0.04* |
| ( |
| TexAdjustY1 |
| + |
| TexAdjustX1 |
| ); |
| color.b += 0.05* |
| ( |
| TexAdjustY1 |
| + |
| TexAdjustX1 |
| ); |
| return color; |
| |
| } |