Page 1 of 1

Shader hide triangles not directly facing camera

Posted: Thu Jun 25, 2015 4:20 pm
by kubatp
Hi,
I am not an expert in shaders, so I would like to ask, if here is anyone who can help me with following problem:
I have a mesh, with many triangles and I would like set opacity of triangles according to the angle they face camera - more they face the camera, more opaque they should be. Less they face camera, more transparent they should be.

I attach screenshots to explain the problem

Image

I would like to hide those triangles, which creates these "artefacts" in the smoke.

I am sure this has something to do with camera_position_object_space and normals, but not sure how to fix this and what is the easiest way.
Thank you for your help.

Re: Shader hide triangles not directly facing camera

Posted: Fri Jun 26, 2015 2:29 am
by areay
Multiply final output colour by saturated dot product of normal and camera(eye) direction.

That'll weaken triangles not directly facing the camera and eliminate back facing triangles.

If you want to show all triangles facing (say) 45degrees or squarer to the camera then you could use a step command. The fragment shader pieces might look like this

Code: Select all

//Fade pixels based on how much they are facing the camera
float NdotE = saturate(dot(normal, eyeVector));
outputColour *= NdotE;

Code: Select all

//Show only pixels facing directly at camera or at most 45degrees
float NdotE = dot(normal, eyeVector);
outputColour *= step(0.5, NdotE);
Note that by default you won't be rendering back facing triangles unless you've set 'cull_hardware none' in your material.

Re: Shader hide triangles not directly facing camera

Posted: Fri Jun 26, 2015 11:25 am
by kubatp
Hi areay,
thank you for reply and help. It works now as I required.
Thank you again!