0
votes

I try to simulate reflection on a plane with render to texture. My only problem is how to adjust the texture coordinates correctly to the current view.

In the shader i multiply the texture coordinates with a rotation matrix. The rotation matrix is set with:

glm::vec3 v1 = glm::vec3(0.0f,1.0f,0.0f);
glm::vec3 v2=glm::vec3(camlocation[0],camlocation[1],0.0);
if(glm::length(v2)!=0.0f)
{
    v2=glm::normalize(v2);
}
float alpha=glm::angle(v1,v2);
texturematrix=glm::mat4(1.0f);
texturematrix = glm::translate(texturematrix,glm::vec3(0.5f,0.5f,0.0f));
texturematrix = glm::rotate(texturematrix,alpha,glm::vec3(0.0f,0.0f,1.0f));
texturematrix = glm::translate(texturematrix,glm::vec3(-0.5f,-0.5f,0.0f));

I dont know if its the right way, but the reflection looks wrong.

edit:

Step 1: i bind a framebuffer and my reflection texture and render my model, a teapot for example. in the shader i invert Z-position.

Step 2: i bind the texture again and draw the plane. in the shader i use

vec4 texcoord = texturematrix*vec4(VertexIn.texcoord,1.0,1.0);
vec4 firsttex = texture(reflectionMap,texcoord.xy);

Step 3: i draw the real model

1
Can you elaborate on how your scene is constructed, what you want to mirror and what you rendered to your texture?` - Nico Schertler

1 Answers

0
votes
vec4 texcoord = texturematrix*vec4(VertexIn.texcoord,1.0,1.0);

ok, one mistake was the third coordinate. it must be 0.0. now it looks better, but still wrong. i have to add the current eye direction to the camera location angle

http://fs1.directupload.net/images/141207/temp/7wk8lvms.png