PDA

View Full Version : Shader linking fails when editing a copy of gl_PointCoord



namespace
09-29-2007, 09:10 AM
Hi!

I try to fake rotatable pointsprites by rotating the calculated
gl_PointCoord in the fragment shader.
For some strange reason the linking of the program
fails as soon as I try to modify a _copy_ of the gl_PointCoord
values.
This is the error (including a typo from a nv dev ;) ):
error C7001: inconsitent use of semantic modifiers: "sin_a" and "gl_PointCoord"

This is my fragment shader:


uniform sampler2D u_base;

varying float sin_a;
varying float cos_a;

void main()
{
// apply rotation
vec2 coords = gl_PointCoord;
/*
coords = coords * 2.0 - 1.0; // [0, 1] ->[-1, 1]
float xx = cos_a * coords.x + sin_a * coords.y;
coords.y = -sin_a * coords.x + cos_a * coords.y;
coords.x = xx;
coords = (coords + 1.0) * 0.5; // [-1, 1] -> [0, 1]
*/

vec3 color = texture2D(u_base, coords).rgb;
gl_FragColor = vec4(color, 1.0) * gl_Color;
}
The vertex shader

varying float sin_a;
varying float cos_a;

void main()
{
vec4 vtx = gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0);

// distance attenuation
// add an epsilon 'cause zero size is undefined for pointsprites
gl_PointSize = VIEWPORT_WIDTH * gl_Vertex.w * 2.0 / -vtx.z + 0.01;

// decode color and rotation
vec4 tmp = gl_MultiTexCoord0;
gl_FrontColor = vec4(tmp.r, tmp.g, fract(tmp.b) * 10.0, fract(tmp.a) * 10.0);

sin_a = tmp.b / 1000000.0;
cos_a = tmp.a / 1000000.0;

gl_Position = gl_ProjectionMatrix * vtx;
}As soon as I remove the comments around the
codeblock that recalculates the coords, the linking fails.

Card used: Geforce 8 GTS
Version: 2.1.1 NVIDIA 100.14.19
OS is Linux

Trenki
09-29-2007, 12:33 PM
Just guessing: gl_PointCoord is olny available in GLSL 1.20. Maybe you should put a #version 120 at the top of your fragment shader source?

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

namespace
09-29-2007, 12:50 PM
I do that.
What I have posted is the raw shader-source,
my engine adds a set of preprocessor macros
and defines at the top of each shaderfile, with
"#version 120" beeing one of them.

namespace
10-03-2007, 08:00 AM
Anybody?

Y-tension
10-04-2007, 04:33 AM
Is it the linking or the compilation that fails?

yooyo
10-04-2007, 06:43 AM
I just tested in Shader Designer on WinXP-SP2 + 7600GT fw 163.69 and it works.

namespace
10-05-2007, 08:16 AM
Is it the linking or the compilation that fails? Linking fails.


Originally posted by yooyo:
I just tested in Shader Designer on WinXP-SP2 + 7600GT fw 163.69 and it works. That is good news, I guess I have to wait for a Linux driverupdate then.