2
$\begingroup$

I am trying to mimic reflections in image composition using shaders.

I have gotten this far:

enter image description here

In this image the floor is "reflecting" the back wall, however the reflection is uncanny because the scale and the positions of the objects are very wrong.

For example the plant is nowhere even close to where it should be. Assuming I have a ground truth set of values for the camera parameters, is there a way I could "move" the reflections to better match what I expect to see? It doesn't have to be perfect, just better than what I have.

The way I am generating the image is the same as learnopengl's code:

void main()
{             
    float ratio = 1.00 / 1.52;
    vec3 I = normalize(Position - cameraPos);
    vec3 R = refract(I, normalize(Normal), ratio);
    FragColor = vec4(texture(skybox, R).rgb, 1.0);
}  

EDIT:

An important thing I should mention is, I don't have geometry, just a still image and information of where the floor is. So I don't have any depth, normals, or anything like that for most of the image.

$\endgroup$
2
$\begingroup$

Reflections based on a cubemap best represent a reflection at infinity. That is, since the only factor that a cubemap provides is direction, the cubemap acts as though it were at a distance from the reflective surface where only the direction to the reflecting objects matters. And that only happens if the reflecting objects are infinitely far from the reflective surface.

That works fine for reflecting distant environmental details like skies or distant landscapes. But it's not going to work with anything even remotely close to the reflective surface. And if the reflecting object and a reflective surface touch, then you can basically forget about it.

Cubemap reflections are simply not the right tool for this scene. You will instead have to employ other strategies for reflections, like rendering the back wall under the reflective surface (using transparency of the reflective surface to create the appearance of reflection), or doing screen-space reflections or something like that.


I don't have geometry, just a still image and information of where the floor is. So I don't have any depth, normals, or anything like that for most of the image.

If you don't have geometry information or any equivalent to it, then you're pretty much out of luck. Accurate reflection of a scene requires knowing where the scene being reflected is relative to each point on the reflective surface. Even if the surface of reflection itself is flat, the reflected scene isn't. If you don't have some approximation of geometry information, and you cannot generate such a thing, then you cannot generate an accurate reflection.

If computer vision algorithms are available to you, I would suggest trying to fine one that can reconstruct the depth information of the scene from a single image. If that's not feasible, then you're going to have to live with an inaccurate reflection in one way or another.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I won't be able to render the scene to mimick reflections more effectively (see the edit). As to SSRT I am not sure you can get a reflective effect if you don;t have the depth information of the image. $\endgroup$ – Makogan Mar 21 at 16:17
  • $\begingroup$ @Makogan: See my edits. $\endgroup$ – Nicol Bolas Mar 22 at 1:27
  • $\begingroup$ yes I understand that no matter what I do the image won;t be accurate, my intent is merely to try to change the "zoom" level just a little bit such that objects in the reflection are somewhat less distorted. Essentially if we say that currently it takes 10 seconds to figure out what;s wrong in the image, I am trying to push it so that it;s at least 30 seconds, maybe a minute if lucky. $\endgroup$ – Makogan Mar 22 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.