Hello everyone,
I wrote a vertex and fragment shader that works just fine on Direct3D, but when it compiles on a Mac gives strange vertex errors. I tried forcing it to compile to glsl, to see if that would fix the problem, and I get the following problem in the compiled shader:
varying vec4 xlv_;
varying vec2 xlv_;
varying float xlv_;
varying vec4 xlv_;
varying float xlv_;
void main() {
v2f xl_retval;
appdata_img xlt_v;
xlt_v.vertex = vec4( gl_Vertex);
xlt_v.texcoord = vec2( gl_MultiTexCoord0);
xl_retval = vert( xlt_v);
gl_Position = vec4( xl_retval.pos);
xlv_ = vec4( xl_retval.pos2);
xlv_ = vec2( xl_retval.uv1);
xlv_ = float( xl_retval.svc);
xlv_ = vec4( xl_retval.vr);
xlv_ = float( xl_retval.draw);
}
/* NOTE: GLSL optimization failed
0:0(0): error: `xlv_' redeclared
0:0(0): error: `xlv_' redeclared
0:0(0): error: `xlv_' redeclared
0:0(0): error: `xlv_' redeclared
0:450(7): error: type mismatch
0:451(7): error: type mismatch
0:453(7): error: type mismatch
*/
What is the solution to this error? Is there a way to force the compiler to not redeclare a variable? Is there a misconception I have about writing shaders that is causing this problem? I declared this struct for the vertex shader, this is what it’s having trouble with I think?
struct v2f
{
float4 pos : POSITION; //internal, used for display
float4 pos2; //Position in world, relative to player position in world
float2 uv1; //Used to specify what part of the texture to grab in the fragment shader(not relativity specific, general shader variable)
float svc; //sqrt( 1 - (v-c)^2), calculated in vertex shader to save operations in fragment. It's a term used often in lorenz and doppler shift calculations, so we need to keep it cached to save computing
float4 vr; //Relative velocity of object vpc - viw
float draw; //Draw the vertex? Used to not draw objects that are calculated to be seen before they were created. Object's start time is used to determine this. If something comes out of a building, it should not draw behind the building.
};
Any help would be appreciated!
Thanks