Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Problem with mapping a reflection texture

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 50_Cal   Members   

116
Like
0Likes
Like

Posted 30 August 2012 - 09:35 PM

Hello guys.
I used FBO to render the reflected stuff to a texture, after that I was confusing how to compute the correct texture coordinate for the texture?
Here is the main stuff I wrote in GLSL and it didnt give me the right thing:

// VERTEX SHADER
varying vec2 v;

vec4 vertex = gl_ModelVIewMatrix * gl_Vertex;
v.x = vertex.x/vertex.z;
v.y = vertex.y/vertex.z;


// FRAGMENT SHADER
texture2D( reflectTex, vec2((v.x+1) * 0.5, (v.y+1) * 0.5) );

What is wrong with the calculation? or is there another way to achieve it?

#2 Hodgman   Moderators   

50612
Like
1Likes
Like

Posted 30 August 2012 - 11:18 PM

You need to use the ModelViewProjection matrix, and divide by w, not z, to get it into screen space.

#3 BLM768   Members   

325
Like
1Likes
Like

Posted 30 August 2012 - 11:26 PM

To properly obtain the coordinates, I think that you need to multiply the vertex coordinates by the projection matrix and then divide the x/y values by -z.
However, I'd recommend considering using the stencil buffer to mask out the non-mirror areas, render the reflection, then render the unreflected scene. It's a bit more complex than that, but that's the general idea. The advantage to this method is that you don't need an additional texture, and the stencil test prevents some of the unnecessary fragment processing from happening.

#4 50_Cal   Members   

116
Like
0Likes
Like

Posted 30 August 2012 - 11:56 PM

You need to use the ModelViewProjection matrix, and divide by w, not z, to get it into screen space.

To properly obtain the coordinates, I think that you need to multiply the vertex coordinates by the projection matrix and then divide the x/y values by -z.
However, I'd recommend considering using the stencil buffer to mask out the non-mirror areas, render the reflection, then render the unreflected scene. It's a bit more complex than that, but that's the general idea. The advantage to this method is that you don't need an additional texture, and the stencil test prevents some of the unnecessary fragment processing from happening.

Thanks for your help, I will try these methods.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.