About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
Custom Shader Learning Project
Author Message
3DRaddict Offline
Member

Post: #31
RE: Custom Shader Learning Project
Worked hard on completing the 'BlendDemo' today, but no real problems.
Three more custom shaders 'basic_land2.cpp', 'basic_water2.cpp' and 'basic_box2.cpp' were added.

These shaders incorporated two more Technique parameter options: 'gAlphaClip' and 'gFogEnabled'
This increases the number of Technique choices significantly... one can now compile the shaders with 1,2 or 3 directional lights, texture or no texture, alphaclipping or not, fog or no fog (see the 'CompileShaders()' function in the code)

Added a transparency parameter ('water_AlphaFactor') to the 'basic_water2.cpp' shader to control the amount of water transparency required
[Image: BlendDemo_1.jpg]

Added a wire cage box with a 'WireFence.dds' alpha texture.
[Image: wiretexture.jpg]

When 'gAlphaClip' is set then the intrinsic HLSL function 'clip(x)' is activated.This function can only be called in a pixel shader,
and it discards the current pixel from further processing if x < 0.1, where x is the current pixel's alpha value.
[Image: BlendDemo_2.jpg]
I noticed that the inside back face of the box cage was not showing. After perusing the EE documentation I found that the Material applied to a mesh controls, via the Material '.clip' method, whether the back faces of meshes are clipped or not. The default is 'true' (clipping applied). So I set it to 'false', and I could then see the backside of the wire cage through the front face.
[Image: BlendDemo_3.jpg]

The final addition to this demo is the activation of fogging in the pixel shader, depending whether 'gFogEnabled' is true or not.
This makes use of the HLSL 'lerp()' function which blends the fog color in with the water, land and box colors according to camera distance from the current pixel.
The following shader fog parameters can be set in the 'Main' code and passed down to the shaders.
Flt gFogStart;
Flt gFogRange;
Vec4 gFogColor;


[Image: BlendDemo_4.jpg]
Sky background set to same color as fog, so that fog blends in with the sky.

BlendDemo_executable
12-09-2014 06:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #32
RE: Custom Shader Learning Project
Wow! You're churning these out at a great rate of knots! Many thanks again, really appreciate this series of tutorials/illustrations. I'm hoping I will eventually be able to put the knowledge you are imparting to good use smile
12-09-2014 11:39 PM
Find all posts by this user Quote this message in a reply
Post Reply