Rutt and shaders

Home Forums v002 v002 QC Plugins Support Rutt and shaders

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #58849

    Hello hello. Started to mess around with rutt and some shaders.

    I really got a hard time getting it to work combined with glsl shaders and a texture input. Displace works and lighting works fine. But when i send in the main “image” texture via an frag shader into rutt the tex coords gets all screwed up. I also cant get point attenuation and clipping to work thru glsl somehow.

    So i tried with a bunch from toneburst’s pack and really got a hard time getting them to work with a texture input to the main image input.

    I guess it has something to do with the normals and view.
    like this basic Gloss shader. How would i get this working?


    // Varyings (to Fragment Shader)
    varying vec3 LightVec, EyeView, EyeNormal;

    // Tweakable parameter
    uniform vec3 LightPosition;

    // Main Glossy Wet Hilight Vertex Shader function
    void glossyWetVS(in vec4 v, in vec3 n)
    LightVec = vec3( –;
    EyeView = normalize(gl_ProjectionMatrixInverse[3].xyz –;
    EyeNormal = gl_NormalMatrix * n;

    // Main Loop
    void main()

    //Transform vertex by modelview and projection matrices
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    //Forward current color and texture coordinates after applying texture matrix
    gl_FrontColor = gl_Color;
    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;


    Adapted from:
    ‘glossyWetHilight.fx’ from NVIDIA shader library
    NDVIDIA Corporation 2007

    HLSL > GLSL conversion and Quartz Composer setup
    toneburst 2008

    // Varyings (from Vertex Shader)
    varying vec3 LightVec, EyeView, EyeNormal;

    // Tweakable lighting parameters
    uniform float SpecularExponent, Specularity;
    uniform float GlossMax, GlossMin, GlossDrop;
    uniform vec4 SpecularColor, DiffuseColor, AmbientColor;

    // GLSL version of HLSL builtin LIT function
    vec3 lit (in float ndotl, in float ndoth, in float m)
    float ambient = 1.0;
    float diffuse = max(ndotl, 0.0);
    float specular = step(0.0,ndotl) * max(ndoth * m, 1.0);
    return vec3(ambient, diffuse, specular);

    // Calculates specular dropoff
    float glossy_drop(in float v, in float gMax, in float gMin, in float gDrop)
    return (gDrop+smoothstep(gMin,gMax,v)*(1.0-gDrop));

    // Main Glossy Wet Hilight Fragment Shader function
    vec4 glossyWetFS(in vec4 tex)
    // Normamlze varyings
    vec3 Ln = normalize(LightVec);
    vec3 Nn = normalize(EyeNormal);
    vec3 Vn = normalize(EyeView);
    vec3 Hn = normalize(Vn + Ln);
    // Specular component
    vec4 litV = vec4(lit(dot(Ln,Nn),dot(Hn,Nn),SpecularExponent),1.0);
    float spec = litV.y * litV.z;
    spec *= (Specularity * glossy_drop(spec,GlossMax,GlossMin,GlossDrop));
    vec4 SpecularContrib = spec * SpecularColor;
    // Diffuse component
    vec4 DiffuseContrib = litV.y * DiffuseColor + AmbientColor;
    // Combine lighting components and output result
    return SpecularContrib + (tex * DiffuseContrib);

    // Texture input
    uniform sampler2D Texture;

    // Main Loop
    void main()
    vec4 texmap = texture2D(Texture, gl_TexCoord[0].xy);

    //Multiply color by texture
    gl_FragColor = glossyWetFS(texmap);


    ok this was the evil bastard ..

    gl_TexCoord[0].xy); -> gl_TexCoord[1].xy);

    works now ..


    Yea, the texture coordinates can be tricky. Make sure the vertex shader is sending the appropriate coordinate as a varying, and ensure that your geometry provides viable texture coordinates if you aren’t calculating them by hand in the vertex shader. I recall QC had some weird gotchas with which gl_MultiTexcoord you sent in the past.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.