Refraction using Texture Map (Light Probe)

Hello community!

I am trying to create a realtime (not eevee) refraction shader which is using an environment map as input. I know that the world environment is the usual input for the refraction. But I want to create a realtime shader based on an indipendent environment map ( llike a light probe ).

So here is what I did:

  • I created this test scene and rendered an environment map with the camera being at the center.
  • I use this environment map as the color input for the diffuse shader to create a fake reflection.

  • now i want the shader to look like refraction. So I am flipping the x-axis and rotate the scene so that the orientation is like when refracted. but of course now this is representing a strange IOR. The upper sphere is a real glass shader which is the way it should look (for glass).

In what way do I need to manipulate the vectors so that is looks like glass? It should be way more distorted.

I know that the game development is using these technique to create refraction effects. But all I could find were coded shaders to calculate the refraction. The must be a way to get this done by tweaking the vectors in my opinion. I just cant figure it out. It must not be 100% physically accurate. Most important is that it looks right.

Find also attached the blend file EnviroMapCreator.blend (4.1 MB)

Thanks so much for your help

Just guessing.Not sure this is possible, because of the missing access to the light vectors.
However, refraction is a Fresnel effect due the Index of refraction the Material has.

The custom Fresnel calculation are usally based on the dot product of the Incoming Camera vector and the Normal Vector.
This is enough for calculating reflection.But as sayed with the closure shader, you dont have the light vector.

1 Like

Thanks for the answer first of all! I am not sure what you mean by “light vector”.
I think the object surface normal and the camera vector + IOR should be sufficient.
But i rather did some research. So I did the vector calculation according to this paper
where the refraction vector is being calculated (Page 6).
On the right is a glass ball with my calculation shader, on the left is an EEVEE refraction shader. As the formula represents refraction at one layer only (the ray doesnt exit the glass at the end) I cutted the rear of the comparison ball also away. So…I just rebuild the formula mentioned in the papr with vector math and boom…it works!!!

So basically I answered this question to myself now, but you pushed me into the right direction by mentioning how the refraction is calculated usually. So this way I was starting to investigate how to do it with vector calculation. I just didnt except it to be that complicated.

So thanks to you!!!

1 Like

Cool, I didn’t know this was possible. It would have been so much easier with a refracted coordinate though (with IOR value).

Yes I agree.

I just realized a small mistake though. I took the normal Vector from the Texture Coordinate. This way, it is only valid if the rotation of the object is at its origin. Using the Geometry Input instead is correct and will work also if the object gets rotated.

Now comparing against the real glass shader, the tinting is a bit different which makes it look off in some situations. I will tweak it some more and post the final result in case it could be useful for anyone later.