Project

General

Profile

« Previous | Next » 

Revision 5f76092f

Added by Leszek Koltunski about 5 years ago

Add (simplified, approximated) shading to the Sink effect, i.e. move the normal vectors.

View differences:

src/main/java/org/distorted/library/effect/VertexEffectSink.java
60 60
    {
61 61
    addEffect(EffectName.SINK,
62 62

  
63
        "vec3 center = vUniforms[effect+1].yzw; \n"
64
      + "vec3 ps = center-v; \n"
65
      + "float h = vUniforms[effect].x; \n"
66
      + "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n"
63
        "vec3 center = vUniforms[effect+1].yzw;            \n"
64
      + "vec3 ps = center-v;                               \n"
65
      + "float h = vUniforms[effect].x;                    \n"
66
      + "float deg = degree(vUniforms[effect+2],center,ps);\n"
67
      + "float t = deg * (1.0-h)/max(1.0,h);               \n"
68
      + "v += t*ps;                                        \n"
67 69

  
68
      + "v += t*ps;"
70
      + "const float A = 1.6;                              \n" // max amount of change in normal vector when pulling
71
      + "const float B = 10.0;                             \n" // when pushing
72
      + "vec3 nx = dot(ps,n)*ps;                           \n" // nx = (component of n that's parallel to ps) * |ps|^2 (=dot(ps,ps))
73
      + "float dot_ps = dot(ps,ps);                        \n"
74
      + "float sign_ps= sign(dot_ps);                      \n"
75
      + "nx = (sign_ps*nx)/(dot_ps-(sign_ps-1.0));         \n" // uff! now nx is the parallel to ps component of n, even if ps==0
76
      + "float move = deg*(h-1.0)/(h/B+1.0/A);             \n" // move(0)=-A*deg, move(1)=0, move(inf)=B*deg
77
      + "n += move*nx;                                     \n"
78
      + "n = normalize(n);"
69 79
      );
70 80
    }
71 81

  

Also available in: Unified diff