Page 1 of 1

projection

Posted: Fri Jan 26, 2007 9:04 am
by esaptonor
well, i was having a look at shadow mapping, and that started me thinking on all the stuff i don't know..
and that led me to wondering how on earth the texture is projected.

from this wikipedia page: http://en.wikipedia.org/wiki/Shadow_mapping

there is this picture:
Image

as you can see (or maybe not, look at the page for more), they have taken what a camera sees, and then put that onto an image that another camera sees...they made it look correct!
I think this is to do with texture projection done with a shader, but i have no idea how it works, and despite searching around all i find is bits of code that relate to one project and not another, and none actually explain how it works!

so although this may not be an easy thing to ask, i would like to know (in detail) how texture projection (or whatever they did) works.
If you have some good links that explain it, or maybe if someone knows and can explain it themselves, that would be great.

Posted: Fri Jan 26, 2007 4:42 pm
by TheC
you need to write a shader that does two scene passes.

In pass one, you build a like projection matrix (like a camera projection matrix, but from the lights point of view) You then renderer that scene to texture. the PS output will be the "depth" of the pixel in the scene.

In the second scene pass, you use the RTT to calculate the shadows on each object.

There should be some examples in the DX or Nvidia SDK's

Posted: Fri Jan 26, 2007 10:24 pm
by esaptonor
it wasn't the shadows i was concerned about, i just want to know how they managed to overlay the lights point of view correctly onto the cameras point of view...but i will check out some examples in the mean time

Posted: Sat Jan 27, 2007 4:45 pm
by nomad
This might help...
http://www.riemers.net/eng/Tutorials/XN ... eries3.php
It's XNA / C#, but it shows the principals behind shadow mapping (although not a very good implementation)

Posted: Sat Jan 27, 2007 11:20 pm
by esaptonor
thanks, i will check it out

Posted: Tue Jan 30, 2007 9:47 am
by esaptonor
I have figured out the projection stuff.
For the next bit i have run into another problem. I have created a render target of the depth of the scene...now i need to access it from a shader.
How can i send texture data to a shader without having it on the model?

I am sure this is possible as it seems to happen on that reimers site.
He has in his HLSL code this:

Code: Select all

Texture xShadowMap;

sampler ShadowMapSampler = sampler_state { texture = <xShadowMap> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};
and in his directx code he has this:

Code: Select all

effect.SetValue("xShadowMap", RenderTexture);
Therefore i am sure it is possible to make a render target texture available to my shaders. But with irrlicht and the MyShaderCallBack thing, it appears to only allow me to send floating point values.

can someone point me in the right direction? Does it involve sending a pointer somehow?

Posted: Tue Jan 30, 2007 11:27 am
by sio2
There's source code on my website that may be of help to you. I do stuff like render into a texture and then use that texture as input to a shader. Irrlicht makes it real easy to do.

http://sio2.g0dsoft.com

Posted: Tue Jan 30, 2007 10:34 pm
by esaptonor
which one is it? i downloaded the hardware ray trace 2 one but it had no source, and i downloaded the per pixel lighting example with water one, and it sent the texture normally by putting it on a model (as far as i can tell anyway).
I have slow internet so i would rather not download them all just to find this one.

Posted: Tue Jan 30, 2007 11:44 pm
by sio2
esaptonor wrote:which one is it? i downloaded the hardware ray trace 2 one but it had no source, and i downloaded the per pixel lighting example with water one, and it sent the texture normally by putting it on a model (as far as i can tell anyway).
I have slow internet so i would rather not download them all just to find this one.
What do you mean "which one is it"? How about the one that says "rendered into an Irrlicht-managed rendertarget" and "source code included". :evil:

Posted: Wed Jan 31, 2007 12:09 am
by esaptonor
I did download that one (the water and perpixel lighting one), but from what i could see the render target texture is put on the mesh and used that way ...i may be wrong though, but if that is the case, then that is not what i was after:

I don't want to have to add my shadow map texture as a 3rd texture to every model and then update it for every model every frame. What i need is a way for me to update the render target within irrlicht, and then send it to the shader, the same way you can send mWorldViewProj variable etc.

am i making sense? is there a way to do it that way? or did you already do it that way and i have missed it? :oops:
if i did miss it somehow can you explain where it is and how you did it so that i can't possibly miss it next time....

thanks for taking the time to help,
esaptonor