passing values from vertex to fragment shader
What's the best way to pass non-varying values from a vertex shader to the fragment shader?
I'm using OpenGL ES 2.0, if it makes a difference.
I've tried floats and vectors, which both work almost all of the time, but every now and again the float arrives at the fragment shader with a very slightly different value. And when it's wrong, it's wrong across the whole triangle so I can't blame the "varying" algorithm.
It's not an issue on colors, where you don't notice the tiny difference, but I'd like to use if(var == ?) in the fragment shader. I can get around it, but it made me wonder if there is a better way?
Also, is it generally faster to pass separate floats, one for each parameters, or pack everything into one float and use bit testing?
Rowan.
I'm using OpenGL ES 2.0, if it makes a difference.
I've tried floats and vectors, which both work almost all of the time, but every now and again the float arrives at the fragment shader with a very slightly different value. And when it's wrong, it's wrong across the whole triangle so I can't blame the "varying" algorithm.
It's not an issue on colors, where you don't notice the tiny difference, but I'd like to use if(var == ?) in the fragment shader. I can get around it, but it made me wonder if there is a better way?
Also, is it generally faster to pass separate floats, one for each parameters, or pack everything into one float and use bit testing?
Rowan.
It's my understanding that uniforms are passed in from outside.
You can't pass a uniform value from a vertex shader to the fragment shader. You can only pass varying values.
You can't pass a uniform value from a vertex shader to the fragment shader. You can only pass varying values.
(Aug 23, 2010 12:34 PM)narpas Wrote: You should be using uniforms to pass it to the shader and if the precision is not high enough you could try highp uniform vec3 point;
Yes though you did say: "What's the best way to pass non-varying values from a vertex shader to the fragment shader"
Which sounds a lot like you really want a uniform variable. What do you need to do a floating point equality for anyway? Applying floating point equality to calculated variables (like varying shader variables) without using a range is always a bad idea. The few cases where you can be sure that the equality check will work is when you are multiplying by 0.0 or are substituting a constant value like in MAX(1.0, x).
Which sounds a lot like you really want a uniform variable. What do you need to do a floating point equality for anyway? Applying floating point equality to calculated variables (like varying shader variables) without using a range is always a bad idea. The few cases where you can be sure that the equality check will work is when you are multiplying by 0.0 or are substituting a constant value like in MAX(1.0, x).
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
With EXT_gpu_shader4 you can mark a varying variable "flat", that is, not to be interpolated across a triangle. Whether that's any use to you is a different question...
I think he might be looking for a way to send vertex attribute data straight to the ps as he isn't going to use it in the vs.
If that's the case, there's nothing to help you. Just make it a varying and don't vary it
PS: Sorry, I just can't adopt the phrase fragment shader despite it being a while since I touched D3D!
If that's the case, there's nothing to help you. Just make it a varying and don't vary it

PS: Sorry, I just can't adopt the phrase fragment shader despite it being a while since I touched D3D!
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
ios/mac shader - shared glsl source | OptimisticMonkey | 2 | 7,261 |
Jun 17, 2011 08:59 AM Last Post: OptimisticMonkey |
|
Changing Pixel Values using CG | LIPH700 | 1 | 6,034 |
Nov 25, 2010 03:17 PM Last Post: SethWillits |
|
Changing Uniform Variables for a Single Shader | reapz | 3 | 8,888 |
Jul 15, 2010 01:29 AM Last Post: dazza |
|
Vertex shader particle billboarding question | TomorrowPlusX | 3 | 7,856 |
Sep 15, 2008 06:46 AM Last Post: TomorrowPlusX |
|
GLSL Shader getting corrupted | Weebull | 4 | 7,173 |
Jun 23, 2008 03:43 PM Last Post: Weebull |