Shader hide triangles not directly facing camera

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Shader hide triangles not directly facing camera

Post by kubatp » Thu Jun 25, 2015 4:20 pm

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.
0 x

User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ

Re: Shader hide triangles not directly facing camera

Post by areay » Fri Jun 26, 2015 2:29 am

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.
0 x

kubatp
Gnome
Posts: 354
Joined: Tue Jan 06, 2009 1:12 pm
x 7

Re: Shader hide triangles not directly facing camera

Post by kubatp » Fri Jun 26, 2015 11:25 am

Hi areay,
thank you for reply and help. It works now as I required.
Thank you again!
0 x

Post Reply