• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
home3d2001

Specular Animation shader (HLSL/GLSL)

6 posts in this topic

Hello,

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.

H
1

Share this post


Link to post
Share on other sites
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:
[url="http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2011.html"]http://www.arcsynthesis.org/gltut/Illumination/Tutorial%2011.html[/url]
HLSL:
[url="http://www.rastertek.com/dx10tut10.html"]http://www.rastertek.com/dx10tut10.html[/url]
[url="http://rbwhitaker.wikidot.com/specular-lighting-shader"]http://rbwhitaker.wikidot.com/specular-lighting-shader[/url]
[url="http://takinginitiative.net/2010/08/30/directx-10-tutorial-8-lighting-theory-and-hlsl/"]http://takinginitiative.net/2010/08/30/directx-10-tutorial-8-lighting-theory-and-hlsl/[/url]
GLSL:
[url="http://www.lighthouse3d.com/tutorials/glsl-tutorial/lighting/"]http://www.lighthouse3d.com/tutorials/glsl-tutorial/lighting/[/url]
[url="http://www.ozone3d.net/tutorials/glsl_lighting_phong.php"]http://www.ozone3d.net/tutorials/glsl_lighting_phong.php[/url]
0

Share this post


Link to post
Share on other sites
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.

Thanks,

H
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
What's the problem with "multitexturing" ? Just scroll the UVs for the 'specular' texture and draw it
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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.

[b]With Multi-Texturing[/b]
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).

[b]Without Multi-Texturing[/b]
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).


[CODE]
//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);
[/CODE] Edited by Koehler
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0