Announcement

Collapse
No announcement yet.

GLSL animated parameters

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GLSL animated parameters

    Hey

    I've been having a quick play with GLSL trying to get a version of flowmaps / flow shaders working like this kind of thing - https://mtnphil.wordpress.com/2012/0...r-flow-shader/

    I managed to quickly modify a GLSL example that was posted in the comments and get it to do something but I cant seem to figure out how to pass an animated value to it. The general paramhave Animated time which is greyed out and the docs mentions using vr_FrameDataSettings to get frameTime but it doesnt seem to update.


    Here's the dodgy shader code as it is. Anyone got any handy hints... or does anyone out there write shaders for a living and working freelance at the moment, I might have some work for you.

    Code:
    #version 110
    
    uniform sampler2D tex0;    // flow field texture
    uniform sampler2D tex1; // texture A for swapping
    uniform sampler2D tex2; // texture B for swapping
    uniform float time;
    uniform float cycle;
    
    uniform vr_FrameDataSettings vr_FrameData;
    
    
    // VARIYNG FROM VERTEX SHADER
    //in vec2 vTexCoord; // uv coords
    //vec2 vTexCoord=vec2(gl_TexCoord[0]);
    
    // FRAGMENT SHADER OUTPUT
    //out vec4 outputColor;
    
    vec2 unpackFlowVector(vec2 flowVecData)
    {
        vec2 flowVector = flowVecData * 2.0 - 1.0;
        return flowVector;
    }
    
    
    void main()
    {
        vec2 vTexCoord=vec2(gl_TexCoord[0]);
    
        float halfCycle = cycle * 0.5;
        float flowMapOffset0 = mod(vr_FrameData.frameTime*8.0, (cycle));
        float flowMapOffset1 = mod((vr_FrameData.frameTime*8.0) + halfCycle, (cycle));
    
        vec4 color = vec4( 1.0, 0.0, 0.0, 1.0 );
    
        vec4 flowMapTexel = texture(tex0, vTexCoord);
        vec2 flowDir = unpackFlowVector(flowMapTexel.rg);
    
        vec4 texelA = texture(tex1, vTexCoord + flowDir * flowMapOffset0); // texture2D is deprecated since version 1.30
        vec4 texelB = texture(tex2, vTexCoord + flowDir * flowMapOffset1);
    
        float mixFactor = (abs(halfCycle - flowMapOffset0) / halfCycle);
        color = mix(texelA, texelB, mixFactor);
    
    #ifdef DEBUG_MODE
        gl_FragColor = mix(color, flowMapTexel, 0.3);
    #else
        gl_FragColor = color;
    #endif
    
    
    
    }
Working...
X