Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Specular Animation shader (HLSL/GLSL)

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 home3d2001   Members   


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.


Attached Thumbnails

  • shield.jpg

#2 Daniel Wilson   Members   


Posted 02 July 2012 - 09:55 AM

Generally specular reflection would behave in the manner you described by animating the mesh, or the light, or the camera (eye direction). For example the specular highlight would move from the left to the right of the object if you rotate it say in the range -15 to +15 degrees around its up axis. Do you have a specular shader in place? If not some nice tips/examples include:

An intro to shader lighting is here:

#3 home3d2001   Members   


Posted 02 July 2012 - 02:49 PM

Hi Daniel,

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:

1-Texture1(Specular HighLight)
2-Texture2(Diffuse Color)
3-Texture3(Alpha Map)

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.



Attached Thumbnails

  • Image.jpg
  • image2.jpg

#4 InvalidPointer   Members   


Posted 02 July 2012 - 09:59 PM

You can just do a simple multiply-add; it works out to ( diffuse + ( color * alpha ) ). Animating things isn't too difficult either, just add some goofed-with time-based offset to the X coordinate of the specular highlight texture.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#5 rdragon1   Members   


Posted 03 July 2012 - 12:17 AM

What's the problem with "multitexturing" ? Just scroll the UVs for the 'specular' texture and draw it

#6 Labrasones   Members   


Posted 03 July 2012 - 03:24 PM

I would probably just try an animated image. Like a .gif. Or just use a series of images to do the animation. Personally, I think that would be the most simple method of doing that. I'm sure it has many downsides but if you have a deadline and you can't find a better solution, this could be a fallback idea.

#7 Koehler   Members   


Posted 05 July 2012 - 11:37 PM

This can be accomplished very simply. Just pass in a float uniform (Let's call it "Offset") that you increase by a little bit each frame.

With Multi-Texturing
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).

Without Multi-Texturing
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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.