Sample sky and reflection probe texture in shader

Godot Version

v4.2.2.stable.official [15073afe3]

Question

Lowering roughness and increasing metallic on the standard material makes the surface reflect the sky or use the nearest reflection probe. How do I sample the sky / reflection probe texture in my own shader?

You can always export a material you have edited into shader code to see how it works.

When I convert that material to a shader this is what I get:

void fragment() {
	vec2 base_uv = UV;
	vec4 albedo_tex = texture(texture_albedo,base_uv);
	ALBEDO = albedo.rgb * albedo_tex.rgb;
	float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);
	METALLIC = metallic_tex * metallic;
	vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);
	float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);
	ROUGHNESS = roughness_tex * roughness;
	SPECULAR = specular;
}

This fragment shader code doesn’t sample the sky texture, it just sets roughness and metallic, and yet the sky is still reflected. I need a way to sample that same sky texture.

I think this can be done by messing with RADIANCE and IRRADIANCE. (I was looking at the sky shader doc, and it talks about radiance cubemap)

Also ambient_light_disabled render mode could be a quick test to see if it turns off the sky environment.

If those aren’t enough and ambient_light_disabled can turn of the reflection, I think you could then sample your own texture and set the radiance color to the texture sample.

RADIANCE doesn’t seem to be what I need, as it isn’t set to anything by default (it’s zero)
Sorry for not explaining very well, but this is what I’m talking about:
image

These meshes are using StandardMaterial3D with Roughness set to 0 and Metallic set to 1. You can see they reflect the sky, and if you add a reflection probe they can reflect the surrounding environment as well. This is the texture I’m trying to access - the reflection, so I can sample and use it myself.

As far as the docs go it isn’t available to sample from.

It’s seems like the environment and probes are backed into cubemap for metallic reflection.

Note:

The RADIANCE variable is an out only, and it will blend the color with whatever the current environment is based on the alpha you set.

There is also samplerCube type for shaders, maybe you could setup your own cubemap to sample from.