So I have a cubemap that I generated with depth values of a scene.

My understanding was that I could sample a cubemap to retrieve its values using a vec3 (see below fragment shader) but I have seen examples where a vec2 vector is being used instead??? Also I am assuming that to sample my cubemap all I need are vectors between (-1,1), is this correct???

here is the fragment shader I am using to sample my depth cubemap

#version 330 core
uniform vec3 hangle; // horizontal angular range and increment
uniform vec3 vangle; // vertical angular range and increment
uniform samplerCube cubetex;
out float depth;
void main(){
for (float theta = vangle.x; theta < float(vangle.y); theta+= vangle.z){
for (float psi = hangle.x; psi < float(hangle.y); psi+= hangle.z){
float x = sin(radians(theta)) * sin(radians(psi));
float z = cos(radians(theta)) * sin(radians(psi));
float y = cos(radians(theta));
depth = texture(cubetex, vec3(x,y,z)).r;
}
}
}

What is the purpose of the nested loops? You are overwriting depth on each iteration, so only the value calculated by the final iteration is used as the result of the fragment shader…

The purpose of these loops is to generate a vector that will be used to sample the values stored in a cubemap within certain horizontal and vertical angular range and at a certain angular step. In this case the cubemap holds the depth information for a scene surrounding a certain location. Hope this helps to clarify the intent.

Apologies @Alfonse_Reinheart. You are right! The routines I was looking treated the cubemap one side at a time. However, I am still uncertain whether the reason I am not getting a 2D ‘panorama’ of depths (obtained from using sampling using spherical coordinates a depth cubemap) is because of something wrong with my shader

int value = 0;
for (int i = 0; i < 10; ++i) {
value = i;
}
std::cout << "out: " << value << std::endl;

What is the output?
What is the point of executing the loop iterations when all but the final iteration’s value are overwritten?
Your fragment shader does the same thing, it runs a bunch of loops overwriting the depth variable in each iteration, so only the value from the final iteration becomes the output of your fragment shader.

The fragment shader is executed for each fragment produced by rasterization. As a first approximation “each fragment produced by rasterization” corresponds to each texel in your target image that are overlapped by what you are drawing - in your case probably a full size quad. The result of each execution of the fragment shader is written to the output texel it was executed for.
Assigning repeatedly to an out qualified variable in a fragment shader just overwrites the value and only the final value assigned is the output of the fragment shader.

You can. You just can’t do it all in one fragment shader invocation.

When doing rendering, it may help to think backwards. A fragment shader invocation sets the value of a single pixel on the screen. Where does that pixel’s value come from is the question the fragment shader answers.

The “loop” is something that happens to the fragment shader, not in the fragment shader.

Thanks @Alfonse_Reinheart ! I am trying to get my head around what you mentioned (I think that I was very confused about how a fragment shader operated )

I am wondering if the something like following would make sense,…

I would generate my display with the following dimensions