Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Controlling normal strength in a shader

Author
Message
Rain Man
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location:
Posted: 13th Jul 2011 10:09 Edited at: 13th Jul 2011 10:10
I have a shader that creates specular highlights on an object. It uses normal maps and works fine. The images below show the shader applied to a red plane:



The images show the plane with four different normal maps applied. All of the normal maps were made from the same bump map but made with different normal scales.

What I want to do is to use only one normal map and use a 0.0 - 1.0 range variable to control the strength of the normals in the shader. A value of 0.0 would look like the top image. A value of 1.0 would look like the bottom image. This is the pixel shader code that generates the specular highlight:



The normal color is derived from a tex2D() texture lookup. The view and light vectors are passed from the vertex shader. SpecularPower is a float variable defined at the beginning of the shader file.

My question is: How do I use a variable to control the normal strength in the shader?

Thanks for reading and for any thoughts.

Ten minutes to Wapner.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jul 2011 12:05 Edited at: 13th Jul 2011 12:08
In standard normal mapping the blue component corresponds to the axis which is perpendicular to the surface. For a rough surface that value needs to be low and high for a smooth surface. The way I do it is to pass a vector4 to the shader as follows:



then use the vector in the shader as follows.

Add the declaration to the "tweaks" at the start:



then change your normal map code to



That should be it - apart from giving roughness# a suitable value in DBPro.

[Health warning: untested. ]

Edit: the variable roughness# should not be restricted, just keep it non-negative. The normalization step takes care of the rest.
Rain Man
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location:
Posted: 14th Jul 2011 07:52
GG: Once again, your the man!

It works perfectly. Thank you.

Ten minutes to Wapner.

Login to post a reply

Server time is: 2026-07-11 02:37:05
Your offset time is: 2026-07-11 02:37:05