본문으로 바로가기

GLSL Rotate image shader

category Technical Report/R&D test 2017. 7. 21. 09:47
반응형


원문링크 : http://glslsandbox.com/e#41555.0



#ifdef GL_ES
precision mediump float;
#endif

#extension GL_OES_standard_derivatives : enable

uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;



float map(vec3 p)
{   
    vec3 q = fract(p * 0.5) * 2.0 - 1.0;
    q.y = q.x * 0.5;
   
    return length(q) - 0.3;
}

float trace(vec3 origin, vec3 ray)
{   
    float t = 0.0;
    for (int i = 0; i < 18; i++) {
        vec3 p = origin + ray * t;
        float d = map(p);
        t += d * 0.5;
    }
    return t;
}


void main( void ) {

   
    vec2 uv = gl_FragCoord.xy / resolution.xy;   
    uv = uv * 2.0 - 1.0;
   
    // Aspect ratio.
    uv.x *= resolution.x / resolution.y;                       
   
    // RGB
    vec3 c;
   
    float s1 = sin(time * 0.5);
   
    // Compute RGB separately.
    for (int i = 0; i < 3; i++) {
       
        // Move origin.
        vec3 origin = vec3(0.0, 0.0, time);
       
        // Some kind of chromatic aberration.
        uv.x *= 0.97;
        uv.y *= 0.97;
       
        vec3 ray = normalize(vec3(uv, 0.5));
       
        // Spiral rotation (XY).
        float the = time + length(uv) * s1;
        ray.xy *= mat2(cos(the), -sin(the), sin(the), cos(the));
       
        // Normal rotation (XZ).
        the = time * 0.1;
        ray.xz *= mat2(cos(the), -sin(the), sin(the), cos(the));
               
        float t = trace(origin, ray);
       
        // Visualize depth.
        c[i] = 1.0 / (1.0 + t * t * 0.07);
    }   
      
       
    gl_FragColor = vec4(c, 1.0);
}



반응형

'Technical Report > R&D test' 카테고리의 다른 글

Unity SRP LightweightForward  (0) 2018.02.01
Unity fragment shader 구조 분석 정리  (0) 2017.09.26
Unity Bilboard shader  (0) 2017.07.13
approximate oren-nayar shader  (0) 2017.06.19
Texture Array  (0) 2016.08.02