Jump to content

  • Log In with Google      Sign In   
  • Create Account


Plxel Shader: run every pixel or screen pixel?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 viper110110   Members   -  Reputation: 568

Like
0Likes
Like

Posted 24 January 2013 - 09:20 AM

Is the shader run once for every pixel a triangle covers or just the ones that are included in the screen?

 

The reason I'm asking is because I want to do a simple ground for a platformer, and I was thinking of using one giant pair of triangles (to make a rectangle) to do the ground, and then having the texture tile over it. If the pixel shader would only run for the pixels that appear on the screen, this would work fine, but if it is called for the entire rectangle, this could be a bad idea.



Sponsor:

#2 Milcho   Crossbones+   -  Reputation: 1171

Like
5Likes
Like

Posted 24 January 2013 - 09:32 AM

Shaders only run for what's on screen, due to how the graphical pipeline fills pixels (or fragments, as they're called, there's a small difference)

The shader optimization extends further, so to minimize what pixels need to be filled. In general:
a) Be on screen - what you're concerned about
b) Pass the depth test - this means that if you draw some object above ground first, and then draw the ground, the pixels of the ground that are hidden by the object will not be shaded (not rendered by shader). Note that if you draw ground first, and then the object, all the ground's pixels will be filled. In other words, if making huge optimizations, it pays off to draw nearby objects first, before drawing further away objects (or ground).
c) Pass the stencil test - unrelated to your question, but its yet another thing that is used to optimize which pixels get filled.

Edit: To add to that explanation, when you specify a triangle, there is no notion of a 'pixel' on the triangle.
Triangles are transformed into screen space, and those that lie partially outside the screen have their shape re-adjusted, as to 'clip' them. This means that no pixels that are off-screen will be rendered at all, which is what I meant by a) above.
After that they are rasterized into fragments/pixels and each fragment is subject to the two other tests (b and c above).

Edited by Milcho, 24 January 2013 - 09:39 AM.


#3 viper110110   Members   -  Reputation: 568

Like
0Likes
Like

Posted 24 January 2013 - 09:39 AM

Cool, thanks for the quick response



#4 BornToCode   Members   -  Reputation: 902

Like
0Likes
Like

Posted 24 January 2013 - 01:47 PM

To be a lot more clearer it only runs for every pixel that needs to be rasterized. So if you had scissor test enable and clip areas of the screen, then those part will not get process by the pixel shader.



#5 3Ddreamer   Crossbones+   -  Reputation: 2960

Like
0Likes
Like

Posted 24 January 2013 - 06:35 PM

Clip hint applies to every graphical element in existence which is meant to not be visible until needed, including all types of shaders.  As you get more experience then you will learn to optimize clip hint efficiently.


Edited by 3Ddreamer, 24 January 2013 - 06:38 PM.

Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software.  The better the workflow pipeline, then the greater the potential output for a quality game.  Completing projects is the last but finest order.

 

by Clinton, 3Ddreamer





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS