<p>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.</p>

<p>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.</p>

<p>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.</p>

<hr>

<blockquote>
  <p>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.</p>
</blockquote>

<p>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 <em>scene</em> 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.</p>

<p>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.</p>

CC BY-SA 4.0
2020-03-21T16:17:39.683Z
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.
Makogan
CC BY-SA 4.0
2020-03-22T01:27:02.433Z
@Makogan: See my edits.
Nicol Bolas
CC BY-SA 4.0
2020-03-22T03:14:16.777Z
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.
Makogan
CC BY-SA 4.0
2020-03-21T14:57:57.880Z
2020-03-22T01:38:09.063Z
2020-03-22T01:38:09.063Z
Nicol Bolas
<p>I am trying to mimic reflections in image composition using shaders.</p>

<p>I have gotten this far:</p>

<p><a href="https://i.sstatic.net/xm92r.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xm92r.png" alt="enter image description here"></a></p>

<p>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. </p>

<p>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.</p>

<p>The way I am generating the image is the same as learnopengl's code:</p>

<pre><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);
}  
</code></pre>

<p>EDIT:</p>

<p>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. </p>

<rendering><image-processing><reflection><mapping>
Controlling "zoom" and "position" of a cubemap in shaders
Makogan
# Controlling "zoom" and "position" of a cubemap in shaders

(Asked by: username_0 on 2020-03-20)

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

I have gotten this far:

[![enter image description here](https://i.sstatic.net/xm92r.png)](https://i.sstatic.net/xm92r.png)

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.

**Tags:** rendering, image-processing, reflection, mapping


---

## 1 answers

### Answer by username_1 on 2020-03-21. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0: See my edits.  
> **username_0**: 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.  

---

