Jump to content

Recommended Posts

Posted

Hey Josh how did you get the planar reflections to stop following the camera on the water? Seems like no matter what I do if I nod the cam "yes" the reflection wont' stay put. This is what I have. I'm stuck here:


vec2 coord = gl_FragCoord.xy/buffersize;

if (isbackbuffer) coord.y = 1-coord.y;

vec4 reflectcol = texture(texture10,coord);

fragData0 = reflectcol;

Posted

Try flipping signs until it starts working. That's what I usually do when I'm stuck. :D

Also remember, the reflection camera matrix is going to be the same as the render projection matrix, except the pitch is reversed. And the render camera's Y scale should be -1.

  • Like 1
  • Confused 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

The reflection camera also needs to draw the opposite side of all faces, since flipping one component of the scale reverses the triangle winding order.

  • Like 1
  • Confused 1

My job is to make tools you love, with the features you want, and performance you can't live without.

  • 4 months later...
Posted

How is the reflection being rendered in the first place? Are you just modifying the water shader?

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I was trying to make my own. So far I'm just using a shader. I'm basically just flipping the Y texcoord on the model so the image is flipped. But I can't seem to figure out how to make it move the opposite direction when I "yes" nod the camera.

Posted

This is what I have:

VERTEX:

void main()
{
    //entity matrix
    mat4 entitymatrix = entity.matrix[gl_InstanceID];
    mat4 entitymatrix_ = entitymatrix;
    entitymatrix_[0][3]=0.0;
    entitymatrix_[1][3]=0.0;
    entitymatrix_[2][3]=0.0;
    entitymatrix_[3][3]=1.0;
    
    //model position
    ex_vertexposition = entitymatrix_ * vec4(vertex_position,1);
    gl_Position = projectioncameramatrix * ex_vertexposition;

    //clip
    float cam = cameraposition.y;
    float c = 2 * (cam - ex_vertexposition.y);    
    vec4 e = ex_vertexposition;
    e.y += c;
    clipspace = projectioncameramatrix * e;

    //normals
    mat3 nmat = mat3(entitymatrix_);
    ex_normal = normalize(nmat * vertex_normal);
    ex_binormal = normalize(nmat * vertex_binormal);    
    ex_tangent = normalize(nmat * vertex_tangent);

    ex_texcoords0 = vertex_texcoords0;
}

 

FRAGMENT:

 

void main()
{

    //Normal
    vec3 normal = ex_normal;
    normal = normalize(texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0);
    normal = ex_tangent * normal.x + ex_binormal * normal.y + ex_normal * normal.z;    
    normal = normalize(normal);

    vec4 clip = clipspace;
    clip.xyz *= vec3(1,-1,1);
    clip.x = (clip.x / clip.w) * 0.5 + 0.5;
    clip.y = (clip.y / clip.w) * 0.5 + 0.5;

    //Reflection
    vec4 reflection = texture(texture10,clip.xy)*0.8;

    //Diffuse Output
    fragData0 = reflection;
}

 

 

Posted

You normally just need to do something like this:

 

vec3 screencoord = vec3(gl_FragCoord.x/buffersize.x,gl_FragCoord.y/buffersize.y,1.0);	
screencoord.y = 1.0 - screencoord.y;

vec3 reflectionvector = screencoord;
vec3 reflection = textureProj(texture10,(reflectionvector + normal)).rgb;

This is how i have done it.

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

All I get with that are these weird lines. I'm not sure what they are. Like the buffer or something? Even on the one I was using I was getting a similar thing.  Do you know what it is ? What's happening here?

 

 

weirdlines.jpg

Posted

How do you create the reflection texture? And how do you assign it? I am very sure that this will not work from within the editor as the scripts are not updated (except postprocessing).

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Posted

Those lines look like you are doing a texture lookup with texcoords outside the 0-1 range on a clamped texture.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
11 hours ago, klepto2 said:

How do you create the reflection texture? And how do you assign it? I am very sure that this will not work from within the editor as the scripts are not updated (except postprocessing).

Just using the shader from above.  That's why I'm wondering if I need to use a script like a Render function or something. It does look like that in game too. The one I was using has a similar problem it looks ok until I look down then I get this. I dont' know what it is but it looks like maybe it has to do with the buffer not fitting to the screen?

reflectionprob.jpg

Posted
19 hours ago, Josh said:

Those lines look like you are doing a texture lookup with texcoords outside the 0-1 range on a clamped texture.

I don't have anything clamped. I did try clamping stuff but nothing seemed to affect it.

Posted

Ok i have analysed the problem. 

You currently try to use the actual backbuffer as the reflection buffer. This will not work as the backbuffer will always align with the actual camera, where the reflection must be a real reflection texture based on the reflection-physics. The code would look something like this:

auto matrix = camera->GetMatrix(); // Save curent camera matrix
ocean->Hide(); // Hide the ocean, so it doesn't hide reflection geometry
camera->SetRotation(camera->GetRotation() * Vec3(-1.0, 1.0, -1.0)); 
camera->SetPosition(camera->position.x, -camera->position.y + 2 * waterheight, camera->position.z);
World::GetCurrent()->graphicsdriver->clipplane[0] = Vec4(0, -1.0, 0, waterheight); // Setup a clipplane to clip everything which is under water, otherwise you can see items under water in the reflection.

// Render World to reflection texture
// Reset camera, clipplane and show ocean
camera->SetMatrix(matrix);
World::GetCurrent()->graphicsdriver->clipplane[0] = Vec4(0.0);
ocean->Show();

//Render the scene as normal

As the clipplanes are only availabe in c++, this will not completely work from lua.

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...