Specular Animation shader (HLSL/GLSL)
Members - Reputation: 107
Posted 01 July 2012 - 08:52 AM
I am trying to make a Shader that simulates the specular animation on a surface(e.g shield) and was wondering if someone could help me out.
Please see the attachment for a better visualization. I would like the Specular section to move slightly from left to right and repeats again after a few seconds.
Thank you again in advance.
Members - Reputation: 159
Posted 02 July 2012 - 09:55 AM
An intro to shader lighting is here:
Members - Reputation: 107
Posted 02 July 2012 - 02:49 PM
Thank you for your respond. Yes, you are right.However, I am not doing 3D and also I don't think any of the standard specular effects (Blinn,Phog, etc...) can give me the results I want.
My scene doesn't have a light and I need this shader to work as a post processing effect.
Here is how I think is possible to achieve this using 3 textures:
Then we can pan the Specular highlight from right to left or what not. Please see the attachment for the screenshots.
I am new to HLSL and would appreciate it if someone could post a pseudo code or suggest a way to achieve this without doing any multitexturing.
Members - Reputation: 1807
Posted 02 July 2012 - 09:59 PM
Members - Reputation: 354
Posted 03 July 2012 - 03:24 PM
Members - Reputation: 228
Posted 05 July 2012 - 11:37 PM
When you call Tex2D to sample a texture, you pass it a 2D vector of texture coordinates (U,V). All you have to do is add Offset to the U component of your texture coordinates when sampling the specular texture, add that result to the color sampled from your color texture (Without "offset" added to the coordinates), and multiply the sum of those two values by the value sampled from your alpha texture (Again at the original texture coordinates, To keep everything shield-shaped).
You could just use one texture, with RGB and alpha of your shield in it (say that one on the left in your Photoshop window). We know that your texture coordinates are probably a value from 0 to 1. This means that multiplying the U value of your texture coordinate by pi, or 3.14, and taking the sine of the resulting value will yield a nice smooth value ranging from 0 to 1 and back to 0 across the middle of the shield.
To make the effect "move" across the shield, we just have to add the offset to the texture coordinate before multiplying by pi. Now the peak of the sine curve "moves". Multiplying this value by a color vector, then by the original texture's alpha, and adding the result to your output color yields the moving glare effect you're looking for.
Since we're only increasing Offset, we should clamp the value of the sine to [0,1] to make sure we don't add corresponding dark spots (since the sine of pi to 2*pi is negative). Finally, we can multiply the resulting value by some scale amount (<1 to make it fall off sharply, > 1 to make it wider).
//Pass in the offset and color you want the "glare" effect to be... Uniform float Offset; Uniform float3 GlareRGB; //pass in a value for how sharply you want the glare to fall off. 2 = twice as fast as a normal sine curve Uniform float Glare_Sharpness; //get our color and alpha from the shield texture float4 color = Tex2D(colorSampler, texCoords.uv); //Calculate how bright the glare is at this pixel float glare_amount =(1/Glare_Sharpness)*clamp(sin(3.14*(texCoords.u + Offset)),0.0,1.0); float4 OUT_COLOR = float4(color.rgb + glare_amount*GlareRGB), color.a);
Edited by Koehler, 05 July 2012 - 11:41 PM.