1

I am having trouble in my pixel shader's reflections https://www.shadertoy.com/view/lsycD1, I cant get them to work, currently they are inside my main's render loop and are almost displaying what I want but not really, I have tried using reflect( rayDirection, position ) or reflect( rayDirection, normals ) but none of them seem to work, if anybody has an idea I'd be pleased, thanks!

// Normalized pixel coordinates (from -1 to 1)
vec2 uv = ( -iResolution.xy + 2.0 * fragCoord ) / iResolution.y;

vec2 mou = iMouse.xy / iResolution.xy;

if( mou.x == 0.0 ) mou = vec2( 0.4, 0.3 );

vec3 ro = 4.0 * vec3( sin( iTime * mou.x ), mou.y, cos( iTime * -mou.x ) );
vec3 ww = normalize( vec3( 0.0 ) - ro );
vec3 uu = normalize( cross( vec3( 0.0, 1.0, 0.0 ), ww ) );
vec3 vv = normalize( cross( ww, uu ) );
vec3 rd = normalize( uv.x * uu + uv.y * vv + 1.5 * ww );
//vec3 rd = normalize( vec3( uv, -1.0 ) );

float t = 0.0, d = EPS;
for( int i = 0; i < STEPS; ++i )
{

    d = 0.5 * map( ro + rd * t ).x;
    if( d < EPS || t > FAR ) break;
    t += d;

    // Here is where the problem is:
    if( map( ro + rd * t ).y == 0.0 )
    for( int j = 0; j < 64; j++ )
    {

        if( t > FAR ) break;
        rd = normalize( reflect( rd, norm( ro + rd * t ) ) );
        d = 0.5 * map( ro + rd * t ).x;
        t += d;

    }
genpfault
  • 51,148
  • 11
  • 85
  • 139
Felipe Gutierrez
  • 675
  • 6
  • 17
  • I have managed to somehow get it by implementing the ray marching routines in a separate function and adding them together in the main function. Please check the url in the original to see the updated, but I still cant get them to work as a material! – Felipe Gutierrez Mar 26 '18 at 23:11
  • Turns out the epsilon from the analytic normals should've been vec2( EPS, 0.0 ); and not vec2( 0.0, EPS ); – Felipe Gutierrez Apr 02 '18 at 18:07

0 Answers0