godot
godot copied to clipboard
Implement CAMERA_VISIBLE_LAYERS as built-in shader variable
Adds a built-in variable for shaders which exposes the cull mask of the camera rendering the current pass.
In this example, each camera has a different cull mask and the cube's shader outputs a different albedo for each.
Implements godotengine/godot-proposals#5563 Tested with render methods forward_plus, gl_compatibility, and mobile
uints should be used in place of ints. In my mind it is preferable to be consistent and use
uint32_t
s throughout instead of switching toint
s when passing the data to the renderer.uints
are supported in both GLSL 330 and 450 so using them should be fine in all shaders.
@clayjohn I originally made that decision because I thought godot's shader translation couldn't handle uints as I was getting errors, but I have discovered that it was just that uints have their own literal suffix, so all your suggested changes have been implemented. Thank you for the review!
An example shader now:
uint layers = CAMERA_VISIBLE_LAYERS;
if ((layers & 3u) == 3u) { // Both layers 1 and 2, render blue
ALBEDO = vec3(0.0,0.0,1.0);
}
else if ((layers & 1u) == 1u) { // Only layer 1, render red
ALBEDO = vec3(1.0,0.0,0.0);
}
else if ((layers & 2u) == 2u) { // Only layer 2, render green
ALBEDO = vec3(0.0,1.0,0.0);
}
Approved with respect to implementation
This looks ok to me.
Thanks! And congrats for your first merged Godot contribution :tada: