arithmetic – Texture house Raytracing of cylinder primitive in godot shader for Helix interception

arithmetic – Texture house Raytracing of cylinder primitive in godot shader for Helix interception

[ad_1]

I’ve been attempting to do raytracing of an helix in a spatial shader in godot 4.2, however apparently I missed one thing as a result of the result’s bloby and melty on the cylinder stage.

The fundamentals is that I hint a second circle within the depth aircraft alongside U, then attempt to extrude it as a cylinder by scaling the view vector by the t values given in second. However that did not prove as anticipated and I am a lack of the place it received flawed, the conventional additionally do not look right.

I’ve already strive many permutation, initially I used to be doing two cylinder packed in scorching, and eliminated one for copy and eradicating noise. I used the scratchpixel raytracing’s article notation.


uniform sampler2D textual content;

void fragment()
{
    mat3 TBN = mat3(TANGENT, BINORMAL, NORMAL);
    vec3 viewDirTangentSpace = TBN * VIEW;

    const float mydepth = 1.0;
    vec3 raydir = viewDirTangentSpace;///.5; // ray route/depth

    const vec2 facilities = vec2(-0.0,.5);//x and depth
    const float radius = 0.3;
    const float r2 = radius * radius;
    
    const vec2 UVsurfacePos = vec2(UV.x,0);

    //vector: second origine to circles middle in second alongside vertical depth aircraft
    const vec2 L = facilities.xy-UVsurfacePos.xy; const vec2 L2 = L*L;

    //dot projection: second facilities to second ray line
    vec2 raydir2d = normalize(raydir.xz);
    float tca = dot(L,raydir2d);

    //second distances to projected
    float distances = abs( (L2.x + L2.y) - (tca) );
    float d = sqrt( distances );float d2 = d * d;
    //float d2 = distances * distances;

    //second intersections factors
    float thcdiff = r2 - d2; float thc = sqrt (thcdiff);
    vec2 t = vec2(tca +thc, tca -thc);

    //get extrusion in y
    //vec3 p11 = vec3(UV,0) + raydir * t.x; //first affect column 1
    //vec3 p12 = vec3(UV,0) + raydir * t.y; //second affect column 1
    vec3 p11 = raydir * t.x; //first affect column 1
    vec3 p12 = raydir * t.y; //second affect column 1

    //get regular
    vec3 N11 = normalize( vec3(  (UV+p11.xz - facilities),0) );
    vec3 N12 = normalize( vec3( -(UV+p12.xz - facilities),0) );

    //get twist
    float twist11 = atan(N11.x, N11.y);
    float twist12 = atan(-N12.x, -N12.y);//reverse the N
    
    vec3 outcome = vec3(0.0); // black shade if not intersecting
    
    if( t.x > 0.0 && t.y > 0.0 )
    {
        outcome = vec3(1.0, 0.0, 0.0); // crimson shade if intersecting cylinder1
    }

    float ptmin = min(t.x,t.y);
    vec2 UVoffset = UV+raydir.xy * ptmin;

    
    NORMAL = N11.xzy;
    ALBEDO = texture(textual content, UVoffset).xyz;
    

}

The helix interception is meant to work on this approach:

  • we discover the hit level angle relative to the cylinder axis (utilizing the conventional orientation)
  • we discover at which top of the cylinder, the same angle of the spiral land (angle change linearly throughout top)
  • we compute if the hit level land with width of the spiral level on the identical angle. else we discard.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply