EDIT: SOLVED and code updated.
This is my first GLSL shader so I’m not sure if there’s something obvious I’m missing here.
The shader displays correctly in the editor, but not on my device (Galaxy Nexus) the display is pink.
I’m getting no errors in the console.
Shader "openGL_ES_2_LM" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex1 ("Texture 1 (RGB)", 2D) = "white" {}
}
SubShader{
Tags { "Queue" = "Geometry" }
Pass{
GLSLPROGRAM
uniform sampler2D _MainTex1, unity_Lightmap;
uniform lowp vec4 _Color;
varying lowp vec4 color;
uniform vec4 unity_LightmapST;
#ifdef VERTEX
void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
color = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1].xy = gl_MultiTexCoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
}
#endif
#ifdef FRAGMENT
void main(){
vec4 col = texture2D( _MainTex1,gl_TexCoord[0].st);
col *= texture2D( unity_Lightmap,gl_TexCoord[1].st) * 2.;
gl_FragColor = col;
}
#endif
ENDGLSL
}
}
}
Jessy
April 24, 2013, 3:45pm
2
http://stackoverflow.com/questions/11678769/whats-the-counterpart-for-gl-texcoord-in-opengl-es-2-0
Also, your color variable is useless.
I’d like it if you reported this as a bug to Unity. I don’t like things working in the Editor when they won’t on a device, when the right graphics emulation is chosen. They may not care, because it’s GLSL, but if enough people care, their hand will be forced.
Thanks Jesse, I tried that suggestion, but still no change.
I tried commenting out the two lines referencing the beast lightmaps (one in the vertex shader and one in the fragment shader), and it displays the diffuse texture just fine.
So, something in one of those two lines is causing the problem.
Shader "openGL_ES_2_LM" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex1 ("Texture 1 (RGB)", 2D) = "white" {}
}
SubShader{
Tags { "Queue" = "Geometry" }
Pass{
GLSLPROGRAM
uniform sampler2D _MainTex1, unity_Lightmap;
uniform lowp vec4 _Color;
uniform vec4 unity_LightmapST;
varying lowp vec4 color,texColor;
varying highp vec4 uv_MainTex1, uv_LM;
#ifdef VERTEX
void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
color = gl_Color;
uv_MainTex1 = gl_MultiTexCoord0;
//this line causing issues ------------------------------------------------------------------------------------
uv_LM.xy = gl_MultiTexCoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
//-----------------------------------------------------------------------------------------------------------------------
}
#endif
#ifdef FRAGMENT
void main(){
texColor = texture2D( _MainTex1,uv_MainTex1.xy);
//this line causing issues ------------------------------------------------------------------------------------
texColor *= texture2D( unity_Lightmap,uv_LM.xy) * 2;
//-----------------------------------------------------------------------------------------------------------------------
gl_FragColor = texColor;
}
#endif
ENDGLSL
}
}
}
Jessy
April 24, 2013, 5:01pm
4
That won’t compile because you didn’t put a period after your 2.
Don’t use vec4s for texture coordinates. That’s a dependent texture read on the device you’re using.
I edited it for readability so disregard the lack of punctuation. (EDIT: what 2?)
It compiles just fine, and runs (and displays) with those lines commented out.
Thanks for the tip on vec4s, I will look at it.
EDIT: Added #pragma debug and it appears to be converted to OpenGL ES 1 for some reason:
“#define SHADER_API_GLES 1”
that means it’s converted to OpenGL ES ?
OK, I see what you mean. I saw another shader you wrote and you placed a period after the 2 in the fragment shader.
I tried that but still no luck.
EDIT: No! That works!!
Thanks for your time Jessy, it was the period after the 2 in the fragment shader.
Jessy
April 24, 2013, 9:15pm
7
I’m assuming you’re on Windows? I’ve had teammates write in GLSL on Windows, and when brought to OS X, the code wouldn’t compile. The explicit floating point problem is one of the differences.
That’s exactly it. I am on Windows.