Reflective cubemap shader

Credits to Shadmar

How to make a reflective cubemap shader

1. Open up diffuse.shader in the shader editor :
2. Click Vertex in the left tab
3. Add under outputs

out vec4 ex_vertexposition;

4. Find :

vec4 modelvertexposition = entitymatrix_ *....

Add after :

ex_vertexposition = modelvertexposition;  //we need this position the fragment shader

5. Click Fragment in the left tab
6. Add under Uniforms

uniform samplerCube texture4; //cube map for reflection texture from material
uniform mat3 cameranormalmatrix;  //need normalmatrix from camera for correct reflection in relation to camera rotation
uniform vec3 cameraposition; //need camera position so we know the distance from the fragment. (pixel)

7. Add under Inputs

in vec4 ex_vertexposition;

8. find :

outcolor *= texture(texture0,ex_texcoords0);

after add :

vec3 cubecoord = reflect( normalize( - cameraposition ) , normalize(cameranormalmatrix * normal).xyz );  //this is industy standard cubecoordinates for reflection..
outcolor = mix(outcolor,texture(texture4,cubecoord),0.5); //mix diffuse with cubemap reflection 50%

See that it compiles, save

Make material with a diffusemap in texture0 and cubemap in texture4

End result looks like this:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License