Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'variable' : is not available in current GLSL version gl_TexCoord

I have coded a fragment shader in vizard IDE and its not working. The code is free of compilation errors except for one which says, " ERROR: 0:? : 'variable' : is not available in current GLSL version gl_TexCoord." FYI the gl_TexCoord is the output of the vertex shader which is in build to vizard. Can someone help me to fix it. here is the code:

#version 440
// All uniforms as provided by Vizard
uniform sampler2D vizpp_InputDepthTex;  // Depth texture
uniform sampler2D vizpp_InputTex;       // Color texture
uniform ivec2 vizpp_InputSize;          // Render size of screen in pixels
uniform ivec2 vizpp_InputPixelSize;     // Pixel size (1.0/vizpp_InputSize)
uniform mat4 osg_ViewMatrix;            // View matrix of camera
uniform mat4 osg_ViewMatrixInverse;     // Inverse of view matrix

// Your own uniforms
//uniform sampler2D u_texture;
//uniform sampler2D u_normalTexture;
uniform sampler2D   g_FinalSSAO;

const bool onlyAO = false;               //Only show AO pass for debugging
const bool externalBlur = false;         //Store AO in alpha slot for a later blur
struct ASSAOConstants
{
    vec2 ViewportPixelSize;                      // .zw == 1.0 / ViewportSize.xy
    vec2 HalfViewportPixelSize;                  // .zw == 1.0 / ViewportHalfSize.xy

    vec2 DepthUnpackConsts;
    vec2 CameraTanHalfFOV;

    vec2 NDCToViewMul;
    vec2 NDCToViewAdd;

    ivec2 PerPassFullResCoordOffset;
    vec2 PerPassFullResUVOffset;

    vec2 Viewport2xPixelSize;
    vec2 Viewport2xPixelSize_x_025;              // Viewport2xPixelSize * 0.25 (for fusing add+mul into mad)

    float EffectRadius;                           // world (viewspace) maximum size of the shadow
    float EffectShadowStrength;                   // global strength of the effect (0 - 5)
    float EffectShadowPow;
    float EffectShadowClamp;

    float EffectFadeOutMul;                       // effect fade out from distance (ex. 25)
    float EffectFadeOutAdd;                       // effect fade out to distance   (ex. 100)
    float EffectHorizonAngleThreshold;            // limit errors on slopes and caused by insufficient geometry tessellation (0.05 to 0.5)
    float EffectSamplingRadiusNearLimitRec;          // if viewspace pixel closer than this, don't enlarge shadow sampling radius anymore (makes no sense to grow beyond some distance, not enough samples to cover everything, so just limit the shadow growth; could be SSAOSettingsFadeOutFrom * 0.1 or less)

    float DepthPrecisionOffsetMod;
    float NegRecEffectRadius;                     // -1.0 / EffectRadius
    float LoadCounterAvgDiv;                      // 1.0 / ( halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeX * halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeY )
    float AdaptiveSampleCountLimit;

    float InvSharpness;
    int PassIndex;
    vec2 QuarterResPixelSize;                    // used for importance map only

    vec4 PatternRotScaleMatrices[5];

    float NormalsUnpackMul;
    float NormalsUnpackAdd;
    float DetailAOStrength;
    float Dummy0;
    mat4 NormalsWorldToViewspaceMatrix;
        

};

uniform ASSAOConstants g_ASSAOConsts;

float PSApply( in vec4 inPos, in vec2 inUV)
{   //inPos = gl_FragCoord;
    float ao;
    uvec2 pixPos  = uvec2(inPos.xy);
    uvec2 pixPosHalf = pixPos / uvec2(2, 2);

    // calculate index in the four deinterleaved source array texture
    int mx = int (pixPos.x % 2);
    int my = int (pixPos.y % 2);
    int ic = mx + my * 2;       // center index
    int ih = (1-mx) + my * 2;   // neighbouring, horizontal
    int iv = mx + (1-my) * 2;   // neighbouring, vertical
    int id = (1-mx) + (1-my)*2; // diagonal
    
    vec2 centerVal = texelFetchOffset( g_FinalSSAO, ivec2(pixPosHalf), 0, ivec2(ic, 0 ) ).xy;
    
    ao = centerVal.x;

    if (true){   // change to 0 if you want to disable last pass high-res blur (for debugging purposes, etc.)
        vec4 edgesLRTB = UnpackEdges( centerVal.y );

        

        // convert index shifts to sampling offsets
        float fmx   = mx;
        float fmy   = my;
        
        // in case of an edge, push sampling offsets away from the edge (towards pixel center)
        float fmxe  = (edgesLRTB.y - edgesLRTB.x);
        float fmye  = (edgesLRTB.w - edgesLRTB.z);

        // calculate final sampling offsets and sample using bilinear filter
        vec2  uvH = (inPos.xy + vec2( fmx + fmxe - 0.5, 0.5 - fmy ) ) * 0.5 * g_ASSAOConsts.HalfViewportPixelSize;
        float   aoH = textureLodOffset( g_FinalSSAO, uvH, 0, ivec2(ih , 0) ).x;
        vec2  uvV = (inPos.xy + vec2( 0.5 - fmx, fmy - 0.5 + fmye ) ) * 0.5 * g_ASSAOConsts.HalfViewportPixelSize;
        float   aoV = textureLodOffset( g_FinalSSAO, uvV, 0, ivec2( iv , 0) ).x;
        vec2  uvD = (inPos.xy + vec2( fmx - 0.5 + fmxe, fmy - 0.5 + fmye ) ) * 0.5 * g_ASSAOConsts.HalfViewportPixelSize;
        float   aoD = textureLodOffset( g_FinalSSAO, uvD, 0, ivec2( id , 0) ).x;

        // reduce weight for samples near edge - if the edge is on both sides, weight goes to 0
        vec4 blendWeights;
        blendWeights.x = 1.0;
        blendWeights.y = (edgesLRTB.x + edgesLRTB.y) * 0.5;
        blendWeights.z = (edgesLRTB.z + edgesLRTB.w) * 0.5;
        blendWeights.w = (blendWeights.y + blendWeights.z) * 0.5;

        // calculate weighted average
        float blendWeightsSum   = dot( blendWeights, vec4( 1.0, 1.0, 1.0, 1.0 ) );
        ao = dot( vec4( ao, aoH, aoV, aoD ), blendWeights ) / blendWeightsSum;
    }

    return ao;
}

void main(void)
{
    // Get base values
    vec2 texCoord = gl_TexCoord[0].st;
    vec4 color = texture2D(vizpp_InputTex,texCoord);
    float depth = texture2D(vizpp_InputDepthTex,texCoord).x;        
        
    // Do not calculate if nothing visible (for VR for instance)
    if (depth>=1.0)
    { 
        gl_FragColor = color;
        return;
    }                   
    
    float ao = PSApply(gl_FragCoord, texCoord);

    
    // Output the result
    if(externalBlur) {
        gl_FragColor.rgb = color.rgb;
        gl_FragColor.a = ao;
    } 
    else if(onlyAO) {
        gl_FragColor.rgb = vec3(ao,ao,ao);
        gl_FragColor.a = 1.0;
    }
    else {
        gl_FragColor.rgb = ao*color.rgb;
        gl_FragColor.a = 1.0;           
    }
}
like image 326
kevin23 Avatar asked Sep 15 '25 07:09

kevin23


1 Answers

gl_TexCoord is a deprecated Compatibility Profile Built-In Language Variables and is removed after GLSL Version 1.20.
If you want to use gl_TexCoord then you would have to use GLSL version 1.20 (#version 120).

But, you don't need the deprecated compatibility profile built-in language variable at all. Define a Vertex shader output texCoord and use this output rather than gl_TexCoord:

#version 440

out vec2 texCoord;

void main()
{
    texCoord = ...;

    // [...]
}

Specify a corresponding input in the fragment shader:

#version 440

in vec2 texCoord;

void main()
{
    vec4 color = texture2D(vizpp_InputTex, texCoord.st);

    // [...]
}
like image 185
Rabbid76 Avatar answered Sep 17 '25 19:09

Rabbid76