Hello Community,
I am very new to game engines and shaders in general and to Godot in particular. I am currently trying to use it in order to create a virtual environment for training Reinforcement Learning agents on visual navigation tasks. In order to do so, I need to extract a spherical 'all around' view of the world around the agents current position, preferably as a planar projection of the spherical view into a rectangle (e.g. Mercator projection)
So far I have managed to create a Cubemap from 6 ViewportTextures (associated with 6 cameras pointing in all directions), passing this Cubemap to a 3d shader as a samplerCube and use this shader to project the Cubemap onto the sphere surface like so
`shader_type spatial;
uniform samplerCube cubemap;
void vertex() {
}
void fragment() {
// get normalized vertex vectors in world coordinates
vec3 direction = normalize(INV_VIEW_MATRIX * vec4(VERTEX,1.0)).xyz;
// Sample from the cube map using the direction
vec3 color = texture(cubemap, direction).rgb;
// Output the color
ALBEDO = color/10.;
}`
This works fine so far. As far as I understand, the ALBEDO attribute now holds the color information of each fragment, whereas the UV attribute should hold the position of each fragment on the sphere in spherical (unit radius) coordinates.
Now comes the part where I am utterly stuck: Mathematically, it should be trivial to use these UV coordinates in order to draw the planar projection of the spherical surface, but I can't seem to manage to do so with shaders in Godot.
How do I access the UV coordinates of the shader?
Do I have to pass them to a secondary 2d shader? And if so, how do I do that?
In case this is very trivial, I apologise, as I said I am very new to all of this, but any help or hints would be very much appreciated.