little help with shaders

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

little help with shaders

Post by devsh »

excuse me but i don't quite get the normals from vectors like the viewproj and stuff in shaders.

it's a GLSL question

I know where the camera is vec3(0.0,0.0,1.0) but for example how do i get a vector to vec3(0.0,0.0,1.0) from every single vertex???

I need it to implement a FAKED fresnel effect


And one more, how do i project textures??

like shadows and water caustics???
Nimrod
Posts: 8
Joined: Sun Feb 22, 2009 8:10 pm

Post by Nimrod »

If you are wondering about how to send a variable to your GLSL codes, the answer is in example/tutorial 10.
In short, set the variable with setVertexShaderConstant in the callback.
for example if this is in the callback:

Code: Select all

irr::core::vector3df pos(0,0,1);
services->setVertexShaderConstant("mLightPos", reinterpret_cast<irr::f32*>(&pos), 3);
the variable can be "retrieved" in the GLSL code like this:

Code: Select all

uniform vec3 mLightPos;
As to your particular application, reflection and refraction are common topics for shaders;
a quick google would yield a lot of useful results.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

oh well i know about passing these but i think for you to under stand i would need to draw a diagram

the fact of the matter is that...

lets take a look at this the | symbolises normal
the / symbolises the vector towards the camera vec3(0.0,0.0,1.0)
C is the cam

Code: Select all

                                        C
 / / / /  /  /  /  / /  /  /  /  /  / /  / / /  /
/ / / /  /  /  /  / /  /  /  /  /  / /  /  / /  /
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
as you can see only on vector towards the camera meets it, all the others shooting from other vertexes are parallel but miss it

What I am trying to achieve is to get a vector for each vertex, that meets the camera i.e.

Code: Select all

  C
 /|\
/_|_\
[/code]
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

google vector math...

2 position vectors....
make one direction vector
do something to it
do something with it and the normal.


That should be enough hints....
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

i just cant get it in my head how to get a vector from gl_Position to the camera and then compare it to the normal vector
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Search these topics...

1-vector math (hint subtraction)
2-normalisation
3-dot product

Shaders have built in functions for all of them but you must understand what they do.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Post Reply