SHADERed icon indicating copy to clipboard operation
SHADERed copied to clipboard

Immediate, watches and vector watch is not able to extract columns/single values from matrix/vector using mat[<column>][<row>]- or vec[<index>]-operator

Open ariaci opened this issue 11 months ago • 0 comments

Description

First of all let me say that SHADERed is an amazing project. I'm regularly using it to test and check my shaders before using them in my own projects.

Sometimes I want to visualize my matrices and that's why I've tried to extract single columns by using glsl-matrix-array-operator. Unfortunately this is not working in general. Shader is executed in right way but debugging matrices doesn't work under all circumstances.

Read out the whole matrix/vector (using tooltip, watches or immediate) is working perfectly and without problems.

Example

#version 450

uniform vec2 iResolution;
uniform vec2 iMouse;
uniform mat4 iView;
uniform sampler2D iChannel0;

out vec4 fragColor;

#define PI 3.14159265

const float hfovDegrees = 60.0;
const float vfovDegrees = 30.0;

void main()
{
    vec2 uv = gl_FragCoord.xy * 2./iResolution.xy - 1.;
    vec2 surfaceSize = vec2(-tan(radians(.5 * hfovDegrees)), tan(radians(.5 * vfovDegrees)));
    
    vec3 camDir = normalize(vec3(uv.xy * surfaceSize, 1.0));
    
    const vec2 angle = vec2(radians(-90), radians(0));
    
    mat4 modelViewX;
    modelViewX[0] = vec4(cos(angle.x), 0.0, sin(angle.x), 0.0);
    modelViewX[1] = vec4(0.0, 1.0, 0.0, 0.0);
    modelViewX[2] = vec4(-sin(angle.x), 0.0, cos(angle.x), 0.0);
    modelViewX[3] = vec4(0.0, 0.0, 0.0, 1.0);
    
    mat4 modelViewY;
    modelViewY[0] = vec4(1.0, 0.0, 0.0, 0.0);
    modelViewY[1] = vec4(0.0, cos(angle.y), -sin(angle.y), 0.0);
    modelViewY[2] = vec4(0.0, sin(angle.y), cos(angle.y), 0.0);
    modelViewY[3] = vec4(0.0, 0.0, 0.0, 1.0);
    
    vec3 rd = (modelViewX * modelViewY * vec4(camDir, 1.0)).xyz;
    vec2 texCoord = vec2(atan(rd.z, rd.x) + PI, acos(-rd.y)) / vec2(2.0 * PI, PI);
    
    fragColor = texture(iChannel0, texCoord);
}

Using for example modelView[0] in immediate, watches or vector watch is not working and results in vec4(0.0,0.0,0.0,0.0)

ariaci avatar Jan 16 '25 10:01 ariaci