GLSL and RenderMonkey

RenderMonkey (1.5) can’t compile my shaders.

float res = dot(n,v);

n,v - vec3. At this line I get an error: assignment of incompatible types. What’s wrong?

RenderMonkey doesn’t compile your shaders, is your graphic driver who does. Read the GLSL spec and see if ‘n’ and ‘v’ variables are both of one of the allowed typed for one of dot built-in function overloads.

vec3 n,v;
n=.25;
v=.45;
float res=dot(n,v);

compile fine on my hardware (geforce fx5200)

[quote]Originally posted by divide:
[b]

n=.25; // ERROR: 'assign' : cannot convert from 'const float' to '3-component vector of float'
v=.45; // ERROR: 'assign' : cannot convert from 'const float' to '3-component vector of float'

The OpenGL Shading Language version of the above is:

n = vec3( .25 );
v = vec3( .45 );

-mr. bill

Originally posted by Ffelagund:
RenderMonkey doesn’t compile your shaders, is your graphic driver who does.
Agree. I see absoutely nothing wrong with the code fragment you posted, but there’s not enough of the code fragment to be certain.

What driver are you using?
Can you post more of the code?

-mr. bill

drivers: 61.77
video: GeForce FX 5200
more of the code:

uniform vec4 cam_pos;

varying vec4 vertex;
varying vec3 normal;

void main(void)
{
   vec3 e = normalize(vertex.xyz - cam_pos.xyz);
    
   float temp = dot(normal,e); // here I get an error
...

Originally posted by x0ras:
[b]drivers: 61.77
video: GeForce FX 5200
more of the code:

uniform vec4 cam_pos;

varying vec4 vertex;
varying vec3 normal;

void main(void)
{
vec3 e = normalize(vertex.xyz - cam_pos.xyz);

vec3 temp = dot(normal,e); // here I get an error

[/b]

dot returns a float, not a vec3.

It should be:

float temp = dot(normal,e);
// OR, less likely....
vec3 temp = vec3( dot(normal,e) );

On a side note, if your normals vary considerably across a primitive, you should consider normalizing the normal before the dot. It’s a quality/speed tradeoff of course.

-mr. bill

Sorry. I did a mistake. I’m using float. :slight_smile:

Which is too bad. It shouldn’t compile fine.
Oops ! Shame on me, I just so how weird was the code I posted :-/

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.