passing values from vertex to fragment shader

Apprentice
Posts: 14
Joined: 2010.01
Post: #1
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.
Quote this message in a reply
Apprentice
Posts: 11
Joined: 2010.07
Post: #2
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;
Quote this message in a reply
Member
Posts: 40
Joined: 2009.05
Post: #3
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;
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
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).

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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...
Quote this message in a reply
Member
Posts: 54
Joined: 2010.10
Post: #6
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!

Paul Johnson
Great Little War Game
Quote this message in a reply
Member
Posts: 142
Joined: 2002.11
Post: #7
(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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ios/mac shader - shared glsl source OptimisticMonkey 2 5,003 Jun 17, 2011 08:59 AM
Last Post: OptimisticMonkey
  Changing Pixel Values using CG LIPH700 1 4,314 Nov 25, 2010 03:17 PM
Last Post: SethWillits
  Changing Uniform Variables for a Single Shader reapz 3 5,199 Jul 15, 2010 01:29 AM
Last Post: dazza
  Vertex shader particle billboarding question TomorrowPlusX 3 5,366 Sep 15, 2008 06:46 AM
Last Post: TomorrowPlusX
  GLSL Shader getting corrupted Weebull 4 4,395 Jun 23, 2008 03:43 PM
Last Post: Weebull