- Home /
Question by
miketucker · Nov 11, 2011 at 01:15 PM ·
shaderiphoneglsl
iPhone: Use of undeclared identifier '_patchFragColor'
A shader works in preview, but fails when launching. Below is the original shader. Following that is the error and generated shader by Unity.
Since this code is generated, is it possible to circumvent the problem?
Shader "RH/EfficientDot" {
Properties {
_MainTex ("Main", 2D) = "white" {}
_GridTex ("Grid", 2D) = "white" {}
}
SubShader {
Pass{
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off ZWrite Off
GLSLPROGRAM
#ifdef VERTEX
varying vec2 the_uv;
varying vec4 color;
void main()
{
color = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
the_uv = gl_MultiTexCoord0.st;
}
#endif
#ifdef FRAGMENT
uniform sampler2D _MainTex;
uniform sampler2D _GridTex;
varying vec2 the_uv;
varying vec4 color;
void main()
{
if (texture2D(_MainTex, the_uv).a * color.a > texture2D(_GridTex, vec2(gl_FragCoord.x, gl_FragCoord.y)*.25).a){
gl_FragColor = color;
} else {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
}
#endif
ENDGLSL
}
}
}
When compiling, Xcode spits out an error below.
-------- GLSL info log: ERROR: 0:31: Use of undeclared identifier '_patchFragColor'
GLES20: failed to compile fragment shader:
#define IN_HIGHP highp
#define IN_MEDIUMP mediump
#define IN_LOWP lowp
precision mediump float;
uniform lowp vec4 _unity_FogColor;
varying lowp float _unity_FogVar;
#define SHADER_API_GLES 1
#define tex2D texture2D
#line 13
uniform sampler2D _MainTex;
uniform sampler2D _GridTex;
varying vec2 the_uv;
varying vec4 color;
void main()
{
if (texture2D(_MainTex, the_uv).a * color.a > texture2D(_GridTex, vec2(gl_FragCoord.x, gl_FragCoord.y)*.25).a){
lowp vec4 _patchFragColor;
_patchFragColor = color; _patchFragColor.rgb = mix (_unity_FogColor.rgb, _patchFragColor.rgb, _unity_FogVar); gl_FragColor = _patchFragColor;
} else {
_patchFragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
}
Comment
Best Answer
Answer by miketucker · Nov 11, 2011 at 01:29 PM
by moving the first instance of gl_FragColor out of the IF statement, the error no longer occurs.
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
if (texture2D(_MainTex, the_uv).a * color.a > texture2D(_GridTex, vec2(gl_FragCoord.x, gl_FragCoord.y)*.25).a){
gl_FragColor = color;
}