Sign in to follow this  

what exactly is a shader instruction?

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A pixel shader (also known as a fragment) is like a little mini-program that's run for every pixel on the screen, to determine its final color. It allows you to perform all sorts of neat effects not possible with the fixed-function pipeline. So the number of instructions per pixel is just that, the number of instructions the GPU performs on each pixel to get the final color value.

A shader instruction itself is like a CPU assembly instruction, although it runs on the GPU and the instruction set is more specialized to perform common graphics tasks like dot products, clamping, etc. You even have higher level languages like Cg, GLSL, HLSL, etc. that compile into the lower-level vertex/pixel instruction sets. However there are differences between the three that make them more suited for different hardware or APIs. That's just a general overview, I'm sure you can find more detailed information online.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thanks for the clarification. So the instruction is like a blend effect then?

So if I had 3 layers of materials on a polygon each with their own specular coefficient, gloss map, bump, and diffuse that would equal 12 instructions on the pixels not including the lighting? If I then blended a lightmap over it all that would be instruction number 13?


Also, is the performance(number of pixels being drawn) dependant on screen resolution or the amount of tiling on the polygon?




best wishes,




Share this post


Link to post
Share on other sites
No, it's an instruction like multiply, add, or something. You can use these instructions to create your own types of blending effects, though :)

So if you were blending between three layers of materials, well, I can't say how many instructions you'd be using, because you could write it in a number of ways.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
so a "blend" may involve multiple instructions I suppose.

ack!

I am not an engineer so would not be sure how many "instructions" are required for a particular "blend" effect(and in my current situation, the engineer isnt too helpful not to say he/she is a bad person).

Is there a web site you know of that might list the "instruction" amount needed for common shader blends such as texture/vertex alpha blends/ or texture/specular adds etc etc ?)


I am a technical artist/lighting TD so don't understand a lot of this to the degree a graphics engineer would.


thanks for any assistance,

Share this post


Link to post
Share on other sites
Does there have to be a fragment shader for each vertex shader? Or can you have a vertex shader all by itself?

And, you have to do all the transformation of the vertex position by yourself?

Share this post


Link to post
Share on other sites
Hmmm. Being programmers, we often overlook concepts that may only be known within our circle and seem very common knowledge to us. May I ask, do you understand the concept that all colors on the screen are nothing more than numbers? Numbers representing the intensities of red green and blue? These shader instructions then are used to calculate what the ratio of the intensities will be in order to produce a final output.

I don't mean to insult any intelligences here, but I've often found friends of mine don't understand what I'm rambling to them until I've explained this bit.

Share this post


Link to post
Share on other sites
Why do you need to know the number of instructions anyway?

When you compile a shader, you can get the compiler to generate some info on how many instructions it requires, or you could just tell your programmer to get off his/her ass and tell you what you need to know. [wink]

Other than that, well, an instruction is usually (but not always) just a single mathematical operations. Like add, subtract, divide, square root or sin or cos.
Other instructions might be texture lookups (get the color from one pixel on some texture), branches (if some comparison (>, < or =) is true, jump to instruction A, otherwise jump to instruction B)

Just to confuse things, there are a handful more complex instructions too (like multiply-add), and most, if not all, work on up to 4 numbers at a time (Which for example means that you can compute an entire color at once, instead of doing red, green and blue separately). But don't worry too much about that. If you just follow the first bit, you should get a reasonable estimate.

So if you (or the programmer) knows what's supposed to happen, that is, how the blend is performed, then it's not too difficult to estimate the number of instructions.
If you're doing nothing more than blending two colors, then it sounds like something like this:
multiply color A with some ratio (1 instruction)
multiply color B with 1 - that ratio (so one instruction to subtract the ratio from 1, then another for the multiply)
Add A and B together (1 instruction)
These two colors might come from textures, in which case you need an extra instruction to look up each color.
Of course, the operation performed might be *a lot* more complex than this, so this estimate is probably too low. Then again, I don't know what is actually done in your shader... :)

But hopefully it at least gives you some kind of rough idea of what shader instructions are.
Try to work out *roughly* what needs to be done to perform the effect you want, then write it down in a list. That'll give you a rough estimate. It might be too low (you'll probably forget to take something into account), or it might be too high (the programmer or compiler can optimize it), but at least it should give you a rough idea of whether the effect you want is possible.
That's usually the best anyone can hope for anyway. That's true even for programmers.

Quote:

Also, is the performance(number of pixels being drawn) dependant on screen resolution or the amount of tiling on the polygon?

Yep. Keep in mind that this has to be performed for every pixel (at least once).
Higher resolution means more pixels, means the shader has to be executed more times.
As for the polygons, it depends. Basically, every pixel on every polygon (even the ones that are behind other polygons) would have to be computed, meaning the shader might be run a dozen times for every screen pixel.
Of course, there are lots of clever tricks to prevent this (If you know which polygon is going to end up actually being *visible* at a certain pixel, then there's no point wasting time computing the color of the polygons behind it), so it's usually not so much of a problem. It's impossible to answer in general though.

[Edited by - Spoonbender on January 28, 2006 10:40:48 PM]

Share this post


Link to post
Share on other sites

This topic is 4341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this