Changeset 1855


Ignore:
Timestamp:
Sep 1, 2012, 1:15:51 PM (7 years ago)
Author:
sam
Message:

tutorial: tweak noise shader once more, and add a few code comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tutorial/03_noise.lolfx

    r1854 r1855  
    77attribute vec2 in_Position;
    88
    9 varying vec2 pass_Position;
    10 varying mat2 pass_Rotation;
     9varying vec4 pass_Position;
    1110varying vec3 water[4];
    1211varying vec3 fire[4];
     
    3130    /* Noise sampling points for fire */
    3231    p_pos = 16.0 * p_pos - r * vec3(0.0, mod289(u_Time) * 128.0, 0.0);
    33     fire[0] = p_pos / 2.0 + p_time;
    34     fire[1] = p_pos / 4.0 + p_time;
     32    fire[0] = p_pos / 2.0 + p_time * 2.0;
     33    fire[1] = p_pos / 4.0 + p_time * 1.5;
    3534    fire[2] = p_pos / 8.0 + p_time;
    3635    fire[3] = p_pos / 16.0 + p_time;
    3736
    38     pass_Position = in_Position;
    39     pass_Rotation = mat2(cos(u_Time), sin(u_Time), -sin(u_Time), cos(u_Time));
     37    /* Pass rotated screen coordinates */
     38    pass_Position.xy = in_Position;
     39    mat2 rot = mat2(cos(u_Time), sin(u_Time), -sin(u_Time), cos(u_Time));
     40    pass_Position.zw = rot * in_Position;
    4041
    4142    gl_Position = vec4(in_Position, 0.0, 1.0);
     
    4849uniform float u_Time;
    4950
    50 varying vec2 pass_Position;
    51 varying mat2 pass_Rotation;
     51varying vec4 pass_Position;
    5252varying vec3 water[4];
    5353varying vec3 fire[4];
     
    8888void main(void)
    8989{
    90     vec2 tmp = pass_Rotation * pass_Position;
    91     float test = tmp.x * tmp.y + sin(3.0 * u_Time);
    92 
    93     /* Add some garbage noise */
    94     vec2 d = vec2(16.0, 9.0) * pass_Position;
     90    /* Dither the transition between water and fire */
     91    float test = pass_Position.z * pass_Position.w + sin(2.0 * u_Time);
     92    vec2 d = vec2(16.0, 9.0) * pass_Position.xy;
    9593    test += 0.5 * (length(fract(d) - 0.5) - length(fract(d + 0.5) - 0.5));
    9694
     95    /* Compute 4 octaves of noise */
    9796    vec3 points[4] = (test > 0.0) ? fire : water;
    98 
    9997    vec4 n = vec4(noise3d(points[0]),
    10098                  noise3d(points[1]),
     
    106104    if (test > 0.0)
    107105    {
     106        /* Use noise results for fire */
    108107        float p = dot(n, vec4(0.125, 0.125, 0.25, 0.5));
    109108
    110         /* Fade out by adding [-.5,.5] */
     109        /* Fade to black on top of screen */
    111110        p -= pass_Position.y * 0.8 + 0.25;
    112111        p = max(p, 0.0);
     
    122121    else
    123122    {
     123        /* Use noise results for water */
    124124        float p = dot(abs(2.0 * n - 1.0),
    125125                      vec4(0.5, 0.25, 0.125, 0.125));
Note: See TracChangeset for help on using the changeset viewer.