"变量":在当前的 GLSL 版本中不可用gl_TexCoord



我已经在vizard IDE中编写了一个片段着色器,但它不起作用。该代码没有编译错误,除了一个说" 错误:0:?:"变量":在当前的 GLSL 版本 gl_TexCoord 中不可用。 仅供参考,gl_TexCoord是顶点着色器的输出,该着色器正在构建为Vizard。有人可以帮我修复它。这是代码:

#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;           
}
}

gl_TexCoord是一个已弃用的兼容性配置文件内置语言变量,在 GLSL 版本 1.20.
如果要使用gl_TexCoord之后删除,则必须使用 GLSL 版本 1.20 (#version 120(。

但是,您根本不需要已弃用的兼容性配置文件内置语言变量。定义顶点着色器输出texCoord并使用此输出而不是gl_TexCoord

#version 440
out vec2 texCoord;
void main()
{
texCoord = ...;
// [...]
}

在片段着色器中指定相应的输入:

#version 440
in vec2 texCoord;
void main()
{
vec4 color = texture2D(vizpp_InputTex, texCoord.st);
// [...]
}

最新更新