问题遇到的现象和发生背景
我在尝试做阴影贴图得过程中。遇到一个问题。
precision lowp float;
uniform bool useTexture;
uniform sampler2D texture0;
uniform lowp sampler2D shadowMap;
in vec4 v_color;
in vec2 v_texCoords;
in vec4 v_shadowTexCoords;
layout(location = 0) out vec4 outColor;
float lookup (float x, float y)
{
float pixelSize = 0.002; // 1/500
vec4 offset = vec4 (x * pixelSize * v_shadowTexCoords.w,
y * pixelSize * v_shadowTexCoords.w,
-0.005 * v_shadowTexCoords.w,
0.0);
return textureProj (shadowMap, v_shadowTexCoords + offset);
}
void main()
{
float _shadow=0.0;
vec2 texDepth = textureProj(shadowMap, v_shadowTexCoords).xy;
float depth = (texDepth.x * 10.0 + texDepth.y);
float lightDepth = (15.0 - v_shadowTexCoords.z) + 0.1 - depth ;
float intensity = 1.0;
if(depth > 0.0 && lightDepth < 0.0){
intensity=0.5;
}
vec4 finalColor;
if(useTexture)
finalColor = vec4(v_color.rgb * intensity, v_color.a) * texture(texture0, v_texCoords);
else
finalColor = vec4(v_color.rgb * intensity, v_color.a);
outColor = finalColor;
}
运行结果及报错内容
S0042: Type mismatch, cannot convert from 'vec4' to 'float'
我想要达到的结果
为什么 textureProj() ,别人得得案例返回值都是float,我得确是VEC4呢?