Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ariaci opened this issue Jan 16, 2025 · 0 comments

Comments

@ariaci
Copy link

ariaci commented Jan 16, 2025

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 ariaci changed the title Immediate, watches and vector watch is not able to extract columns/single values from matrix using mat[<column>][<row>]-operator Immediate, watches and vector watch is not able to extract columns/single values from matrix/vector using mat[<column>][<row>]- or vec[<index>]-operator Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant