Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | natw2000F2 |
I am asking this question because beyond the cubemap object itself ( Cubemap — Godot Engine (stable) documentation in English ), I cannot seem to find information on a simple isolated cubemap reflection shader in Godot’s shader documentation.
If anyone knows of/has a sample project where a samplerCube uniform is used that would be ideal.
There appear to be some GLSL tutorials on the subject, but I am somewhat new to shaders and my attempts to translate the syntax used in these tutorials to that used by Godot has not worked well, and I think I may have missed something.
Unfortunately bookofshaders does not appear to have the cubemap chapter ready either.
I also thought a water shader demo may contain some details on this (for fake refraction), but it does not appear to concern itself with cubemaps.
I am under the impression the difference between a UV and a cubemap is that a uv uses two coordinates, u and v to determine the fragment colour for a 2D texture.
A cubemap is a 3D cube whose 2D surface surrounds a central origin, and the coordinates that determine the fragment colour are the points on the cube surface that 3d directional vectors intersect from the origin.
I am unsure how the shader decides where the fragment colour from the cubemap should go although I’m guessing it just maps the cubemap surface coordinates onto the UV somehow, and this is handled by the texture(cubemap, vector) function.
This being so, I thought I could test this using a normalised version of VERTEX in the fragment function, and a populated cubemap assigned to a samplerCube uniform on a shader attached to a cube:
uniform samplerCube cubemap; // Populated with 6 1024 x 1354 image resources
// via the editor
void fragment(){
ALBEDO = texture(cubemap, normalize(VERTEX))
}
As I understand, the texture function used like this returns a fragment colour from the cubemap depending on where the vector passed as the second argument points on the cube. Therefore, using this simple shader on a cube should project at least some colour on the cube interpolated between where the shader decides to put the fragment colours on the mesh.
However, when doing this I am left with a black (although not unshaded) cube, suggesting I am doing something wrong.
I think it may be something to do with the direct assignment of the texture function onto ALBEDO, as I am not sure how it would translate the cubemap colour coordinates onto the mesh surface, or maybe it was the attempt to use a directional vector in the fragment function (but I am new to shaders, so I am not entirely sure what the rules are).
Admittedly, this is a relatively simple cube and so I’m not sure the VERTEX function would return many points, but surely by this logic at least some interpolated colours should show up on the shader.