Page 1 of 1
little help with shaders
Posted: Sat Apr 18, 2009 11:31 am
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???
Posted: Sat Apr 18, 2009 7:18 pm
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:
As to your particular application, reflection and refraction are common topics for shaders;
a quick google would yield a lot of useful results.
Posted: Sat Apr 18, 2009 8:11 pm
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]
Posted: Sat Apr 18, 2009 10:20 pm
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....
Posted: Sun Apr 19, 2009 10:25 am
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
Posted: Sun Apr 19, 2009 10:58 am
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.