Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Order of the Shader  (Read 807 times)
Lyrical
Customers
Community Member
*****
Posts: 459


WWW
« on: January 29, 2008, 05:39:05 AM »

hi,

   I was just wondering, I'm just getting used to using shaders but still one thing escapes me. The shader is added to the TVMesh fair enough, when the mesh is rendered is the shader run once or is it run once per vertex/pixel. i'm getting a little confused with this concept.

I presume every vertex and every pixel will be past to the shader one by one and the shader will only be dealing with one vertex or pixel at a single moment. this being repeated until all the vertex/pixels have been processed for the TVMesh.

Please correct me if i'm wrong. I'm just looking for clarification.
Thank you
Logged
JukkaKevät
Customers
Community Member
*****
Posts: 182


« Reply #1 on: January 29, 2008, 05:59:55 AM »

Not too fond on the technology, but one thing I know is that the GPU runs several vertices and pixels simultaneously. They aren't called parallel pipelines for nothing!  Smiley

From what I understand setting shader to a mesh is only a pointer which gives the graphic hardware knowledge of which instructions to use for the mesh. The shader instructions are compiled into the graphics hardware when the shader is initialized.

-------------------------
www.studiohorisen.com
Logged
Zaknafein
Customers
Community Member
*****
Posts: 2599


WWW
« Reply #2 on: January 29, 2008, 10:10:36 AM »

Conceptually, the vertex shader is executed for each vertex of the mesh, and the pixel shader is executed for each pixel that the mesh occupies on the screen. But like JukkaKevät said, once on the GPU since the same program is applied to all vertices/pixels, it executes whole blocks at once... but it doesn't change anything to the result.
Logged

zaknafein.
>> the instruction limit : my blog & samples repository! <<
Waterman
Customers
Community Member
*****
Posts: 1141


« Reply #3 on: January 30, 2008, 03:31:20 AM »

Also to notice: If/when you create a value in the vs for the vertex currently being processed (say the vertex Y position), and pass it to the ps (vs_output -> ps_input): The pixel shader, for the current pixel being processed, will have that value handy so that if the pixel doesn't hit a vertex directly, the value is interpolated between the 3 values belonging to the triangle the pixel belongs to.

That's for example the way you craete vertex colors in a shader: Calculate a color value for each vertex, then pass to the pixel shader, which will interpolate the colors(values) smoothly over the triangles.
Logged

Things should be described as simply as possible - but not simpler [A. Einstein]
Raine
Customers
Community Member
*****
Posts: 1099


« Reply #4 on: January 30, 2008, 03:56:41 AM »

Also to notice: If/when you create a value in the vs for the vertex currently being processed (say the vertex Y position), and pass it to the ps (vs_output -> ps_input): The pixel shader, for the current pixel being processed, will have that value handy so that if the pixel doesn't hit a vertex directly, the value is interpolated between the 3 values belonging to the triangle the pixel belongs to.

That's for example the way you craete vertex colors in a shader: Calculate a color value for each vertex, then pass to the pixel shader, which will interpolate the colors(values) smoothly over the triangles.

I'm sure this can be used in a smart way, but right now I'm out of good ideas.
Is this step free*? (going through the interpolators before the PS?)

* computationally speaking, does it take much time?
« Last Edit: January 30, 2008, 04:00:28 AM by RaineC » Logged

Lyrical
Customers
Community Member
*****
Posts: 459


WWW
« Reply #5 on: January 30, 2008, 04:08:18 AM »

Thank you for your info, i am slowly getting used to this.


How would i go about moving say the 3rd vetex in a mesh to a new Y position
I have managed to move every vertex to a new Y position and i get a flat mesh
pretty neet but not what i was triing todo.

Say i have a box(as normal) i just want to make the 3rd vertex move up slowly
I am doing this as an excercise.

I suppose my main question is how do you know in the shader which vertex is currently being
processed so you can manually adjust it?

Thanks again
Logged
BlindSide
Customers
Community Member
*****
Posts: 758


WWW
« Reply #6 on: January 30, 2008, 03:33:40 PM »

Make sure you have the vertex in world space (the vertex comes in in model space, mul it by the world matrix), then move it, then mul it by the viewproj matrix.
Logged

Blind's Dev Blog - www.smithbower.com/devblog/

Irc.Desolation.Org :: #TV3DLicensed :: Moderated IRC channel for all your TV3D needs :: Non-Licensed users welcome.
Zaknafein
Customers
Community Member
*****
Posts: 2599


WWW
« Reply #7 on: January 30, 2008, 03:59:47 PM »

Is this step free*? (going through the interpolators before the PS?)
* computationally speaking, does it take much time?

I'd assume it's almost free, because most people don't even know that the nointerpolation keyword exists (an attribute of the vertex shader arguments IIRC), I haven't seen a shader with it yet. Which means that everybody assumes that interpolation is a given feature of pixel shaders.
Logged

zaknafein.
>> the instruction limit : my blog & samples repository! <<
Waterman
Customers
Community Member
*****
Posts: 1141


« Reply #8 on: January 31, 2008, 01:57:34 AM »

I suppose my main question is how do you know in the shader which vertex is currently being
processed so you can manually adjust it?

Thanks again

You don't know. Each vertex carries some information that you gave it when originally creating the mesh (position, texcoord, normal & such). You can use that to determine something about the vertex. You cannot assume any execution order in the shader (except by depth sorting probably, and that's mostly useless to know in vertex shader code). Just think as if there existed a single vertex only. The same shader code executes for each vertex independently of any other vertex.

The vertex shader alters the vertex position. You can additionally do calculations like  vs_output.something = f(vs_input.vertexdata, time, shaderconstants) and pass the result(s) to the pixel shader (which interpolates).

If you want to move the box up, you must pass "time" to the shader and then in the vertex shader write something like vs_output.Position.y = vs_input.Position.y + time * 0.01. And of course do the transform(s) as Blindy said above.
Logged

Things should be described as simply as possible - but not simpler [A. Einstein]
Lyrical
Customers
Community Member
*****
Posts: 459


WWW
« Reply #9 on: January 31, 2008, 06:27:17 AM »

Thank you for your responses i'm getting the picture,
I will now be looking for the right book to buy and i know
there are a few post to start looking deeper into HLSL.

Zaks tutorial on the Wiki is Excellent and i've even managed to make the
demo that works brilliantly with all 3 tutorial parts

Thanks again for your input much appreciated.

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks