iDevGames Forums
passing values from vertex to fragment shader - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: passing values from vertex to fragment shader (/thread-7979.html)



passing values from vertex to fragment shader - Sumaleth - Aug 12, 2010 08:11 AM

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.


RE: passing values from vertex to fragment shader - narpas - Aug 23, 2010 12:34 PM

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;


RE: passing values from vertex to fragment shader - iamflimflam1 - Aug 26, 2010 05:06 AM

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.

(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;



RE: passing values from vertex to fragment shader - Skorche - Aug 26, 2010 06:07 AM

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).


RE: passing values from vertex to fragment shader - OneSadCookie - Aug 26, 2010 11:52 AM

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...


RE: passing values from vertex to fragment shader - Applewood - Oct 8, 2010 03:40 PM

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 Smile

PS: Sorry, I just can't adopt the phrase fragment shader despite it being a while since I touched D3D!


RE: passing values from vertex to fragment shader - Holmes - Feb 18, 2011 01:54 AM

(Aug 26, 2010 11:52 AM)OneSadCookie Wrote:  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...

It might be valuable to him except that he stated he's using OpenGL ES 2.0.