havenphillip Posted August 5, 2022 Share Posted August 5, 2022 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; Quote Link to comment Share on other sites More sharing options...
Josh Posted August 5, 2022 Share Posted August 5, 2022 Try flipping signs until it starts working. That's what I usually do when I'm stuck. 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. 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted August 5, 2022 Share Posted August 5, 2022 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. 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted December 7, 2022 Author Share Posted December 7, 2022 Would I need to use a script for this or can it be done entirely in the shader? Quote Link to comment Share on other sites More sharing options...
Josh Posted December 7, 2022 Share Posted December 7, 2022 How is the reflection being rendered in the first place? Are you just modifying the water shader? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted December 7, 2022 Author Share Posted December 7, 2022 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. Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 7, 2022 Author Share Posted December 7, 2022 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; } Quote Link to comment Share on other sites More sharing options...
klepto2 Posted December 8, 2022 Share Posted December 8, 2022 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. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
havenphillip Posted December 8, 2022 Author Share Posted December 8, 2022 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? Quote Link to comment Share on other sites More sharing options...
klepto2 Posted December 8, 2022 Share Posted December 8, 2022 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). Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted December 8, 2022 Share Posted December 8, 2022 Those lines look like you are doing a texture lookup with texcoords outside the 0-1 range on a clamped texture. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted December 9, 2022 Author Share Posted December 9, 2022 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? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted December 9, 2022 Author Share Posted December 9, 2022 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. Quote Link to comment Share on other sites More sharing options...
klepto2 Posted December 9, 2022 Share Posted December 9, 2022 If you want you can send me a sample project and I can look into it. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
havenphillip Posted December 9, 2022 Author Share Posted December 9, 2022 1 hour ago, klepto2 said: If you want you can send me a sample project and I can look into it. Yeah that'd be great. plane reflections.zip Quote Link to comment Share on other sites More sharing options...
klepto2 Posted December 9, 2022 Share Posted December 9, 2022 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. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
havenphillip Posted December 9, 2022 Author Share Posted December 9, 2022 Awesome. Thanks, man. I'll see what I can do with this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.