On 12/08/2010 12:52 PM, Kenneth Waters wrote:
> I was looking at the wrong spec the GLSL_ES language spec makes this
> very clear, my comments are still correct though
>
> "Therefore if the vertex shader writes to a varying that the fragment
> shader doesn't declare or declared but doesn't read then this is not
> an error."
> "RESOLUTION: The only error case is when a varying is declared and
> read by the fragment shader but is not declared in the vertex
> shader." -- The OpenGL ES Shading Language 1.0.17 section 10.12
>
> -- Kenneth Waters
I have a test case for this at:
http://sjbaker.org/test/
...on Firefox and Chrome under Linux - and on Firefox on Windows 7 - you
see a white chair on a black background...which I believe is the correct
behavior.
With Chrome on Win7 - using a couple of different nVidia cards that I
could find to test with - and also with an Intel "GPU" on a Win7 netbook
- you get a shader linker error complaining that the varying "NeverUsed"
is needed in the frag shader and not present in the vert shader.
I presume that ANGLE/Direct3D aren't playing ball but OpenGL is doing OK.
The variable isn't mentioned in the Vert shader - and it's only used in
a function that's never called in the Frag shader. If I change the
vert shader to declare the varying - but not write to it, I get the same
error.
What makes this a pain in the butt is that I'm increasingly finding that
it's convenient to have a GLSL "library" of functions (in this case
shadow calculations) that I pre-pend to all of my shaders as they are
fed into the compiler...this works great until I have a shader that
doesn't need shadows - so the vertex shader doesn't call the function to
generate shadow map coordinates - and the fragment shader doesn't call
the function to use those coordinates...but then the darned thing errors
out in the linker.
I can't conditionally include the "varying" because if I leave it out
then the library code won't compile because it refers to it. So now I
have to conditionally include a bunch of stuff. But then if I have two
library functions that use the same varying, I end up including the same
varying declaration twice - and THAT fails too. I had really hoped that
I wouldn't need some really complicated pre-processor on the front end
of all of this...but it's beginning to look like I do. :-(
This is the vert shader:
------------------------------------------------------------------
#ifdef GL_ES
precision highp float;
#endif
attribute vec3 POSITION ;
uniform mat4 ModelToWorld ;
uniform mat4 WorldToCamera ;
uniform mat4 CameraToScreen ;
void main()
{
vec4 worldPos = ModelToWorld * vec4 ( POSITION,1) ;
vec4 cameraPos = WorldToCamera * worldPos ;
gl_Position = CameraToScreen * cameraPos ;
}
---------------------------------------------------------------
This is the frag shader:
---------------------------------------------------------------
#ifdef GL_ES
precision highp float;
#endif
varying vec3 NeverUsed ;
vec3 NeverCalled ()
{
return NeverUsed ;
}
void main ()
{
gl_FragColor = vec4(1,1,1,1);
}
------------------------------------------------------------------
-- Steve
-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: