Weird effect in simple 3d texture ray marching shader in OpenTK and GLSL

38 views Asked by At

I get this effect and can't fix.Any ideas? [example image of the problem]another example(https://i.stack.imgur.com/udxVw.png)another example

Fragment shader:

#version 440 core

in vec3 TexCoord;

uniform sampler3D tex;

uniform mat4 view;
uniform mat4 projection;

uniform vec3 camOrigin;
uniform vec3 camDirection;

out vec4 Frag;

void main(){
    vec3 o = camOrigin;
    vec3 des = TexCoord;

    vec3 d = des - o;

    for (int i = 0; i < 100; i++) {
        vec3 p = o + (d * float(i * 0.1)) / 10;
        vec4 texel = texture(tex, p);
        
        if (texel.a != 0) {
            Frag = texel;
            return;
        }
    }

    Frag = vec4(1,1,1,0);
}

Texture wraps are set to ClampToBorder. Note that i am rendering only the back faces of the cube(inside faces) that way i can go inside the cube. For reference materials you can look at this video

I tried changing ray marching parameters, texture wrap methods, changing ray origin and ray direction calculations. Nothing work

0

There are 0 answers