Archived

This topic is now archived and is closed to further replies.

Lode

Shaders

Recommended Posts

I hope shaders is the right word, but I'm referring to the programmable GPU. What can you actually program with it? Can you write software for it that then runs on the vidcard instead of the CPU? What kind of commands can you give with it? draw pixel? mathematical functions? Actually that's all I need. draw pixel and mathematical functions is all you need to do anything [edited by - Lode on August 31, 2002 8:03:16 PM]

Share this post


Link to post
Share on other sites
you can replace parts of the rastericer-pipeline with own code, written in some fancy assembler (or a highlevel language compiling down to this..)

essencially you can replace the standart t&l unit, as well as the texturing perpixel, so you can expose own perpixel functions there in..

you find much info about this on the web..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
quote:
Original post by Lode
I hope shaders is the right word, but I''m referring to the programmable GPU.

What can you actually program with it? Can you write software for it that then runs on the vidcard instead of the CPU?

What kind of commands can you give with it? draw pixel? mathematical functions? Actually that''s all I need. draw pixel and mathematical functions is all you need to do anything



The Vertex Shader replaces the first stage of the rendering pipeline. You use Draw(Indexed)Primitive to render a list of eg. 1000 triangles. Then the vertex shader gets called for each vertex (point). It basically transforms each point from world space to 2D viewspace. Every point gets lighting values and texture coordinates.

If you use a custom shader, you can adjust the values that are otherwise passed on from the definition of the vertices. Which means that you don''t have to calculate them themselves !

The limitations are that every point is transformed in one call to the shader. This means that it cannot create or delete points, and it cannot access other vertices.

For example, you have a 50x50 mesh of a flat square, the x and y vary between 0 and 5. The z value is always 0. Now your vertex shader takes as input the current time between 0 and 1. This goes from 0 to 1 every second. It can then adjust every z value to sin(x+2*y+t). This will create a rippling surface like water with waves. Add a few values with are combined with different waves, and the water is very natural.

You can also calculate the texture u an v, or the light values dynamically for every point, this saves you from doing it yourself. eg. the light source is passed in a constant, and every point''s light value becomes the dot product of the light vector and the point''s normal vector.

Share this post


Link to post
Share on other sites
Rock on! Thanks for the interesting replies, so that's how they create these rippling surfaces (like in 3DMark 2002) with vertex shaders.

Another question (with an eye on future cards - I'm wondering if I could ever write a raytracer using pixel shaders): how to get your assembly code loaded on that card? Do you have to use OpenGL or Direct3D for that, or will it work without these?

[edited by - Lode on September 7, 2002 1:13:52 PM]

Share this post


Link to post
Share on other sites
About the raytracer idea:

I don''t think it''d be possible with the current shaders. In a raytracer, you might need knowledge of the whole scenery for each point and in some cases you need knowledge of past and future frames for doing things like proper movement blur. Perhaps if ATi and nVidia had some more cold war, but not at the moment.

Hey, if you could implement a raytracer on shaders that''d run something only close to some movement for moderately comnplex scenes (implementing funky stuff like caustics, real mirror finish, algorithmic volumetric fog, volumetric lightsources, ...) without requiring a separate room and one or two generators for the card, you''d be something close to a god. Perhaps not "the" god, but some minor diety

Share this post


Link to post
Share on other sites
Well I still don't know much about shaders, but if you have access to video memory and can make some sort of variables that way - floating point ones by preference, and for the rest do basic math, and you can draw pixels... and have gotos so you can make functions, loops, if's, ..., you could basicly make a sort of raytracer I think. I may be wrong too.

Besides, NVidia's next card should be FULLY programmable :D

[edited by - Lode on September 7, 2002 1:57:39 PM]

Share this post


Link to post
Share on other sites
As far as i know about shaders:
You''ve only got a limited number of variables (16 i think)
''if'' statements are only supported in the latest 1.4 spec (only the high end ATI card at the moment)
Shaders are limited to 127 instructions
Instructions are almost all focused around matrix math.

You want a fully programmable hardware that can do what you want? Its called a CPU GPU''s are fast because they are hevily optimised and orientated on poly rendering, not for other rendering like voxels or raytracing.

_@/

Share this post


Link to post
Share on other sites
What is it actually that is patented by Microsoft (you know, that thing that will not be in opengl2 anymore)? The whole shader idea? or what? And does nvidia need to pay microsoft for that too?

Share this post


Link to post
Share on other sites
You don't have gotos, you only have a max of 8 arithmetic instructions (16, with limitations, in version 1.4, which is supported by Radeon 8*** and 9***) and have only two temporary registers (although you can abuse texture registers to get an additional 4) in pixel shaders.
The amount of math you can do is also pretty restrictive, you have to do most functions using texture lookup (i.e. the input parameters for your function are texture coordinates)

That doesn't mean you can't do cool stuff though, I'm currently working on an accurately per-pixel lit scene in realtime using vertex & pixel shaders, but it'll be a few weeks until I have it done. Ray tracers are still a bit too much though I'd say.

- JQ
Full Speed Games. Coming soon.

[edited by - JonnyQuest on September 9, 2002 4:57:47 AM]

Share this post


Link to post
Share on other sites
everyone always throws around the word "ray tracing", but ray tracing is hardly used in any film special effects. I think it''s a common misconception to think that ray tracing is the holy grail of graphics, because it''s not.

All the effects you see in films are done with the same tricks that we are using atm (albeit a few years ahead, and not real time)...

Infact i can only think of one ray traced scene off the top of my head, and thats from a bugs life when the camera swings around the glass bottle...

my 2c.

-jonnii

Share this post


Link to post
Share on other sites
quote:
Original post by jonnii
everyone always throws around the word "ray tracing", but ray tracing is hardly used in any film special effects. I think it's a common misconception to think that ray tracing is the holy grail of graphics, because it's not.

True. It doesn't mean it's not interesting though I guess, but I doubt it makes sense trying to make it run in real time, because you can do so much more with our plain ol' textured polygonal techniques.

Personally, I'm working on combining bump mapping and light mapping in realtime, which obviously isn't very raytracing-like.

- JQ
Full Speed Games. Coming soon.

[edited by - JonnyQuest on September 9, 2002 9:08:53 AM]

Share this post


Link to post
Share on other sites
Well even if the scenes for the movies are polygonal, the LIGHTING is still done with raytracing, no way around that.

**total number of error 500''s: 500**

Share this post


Link to post
Share on other sites
quote:
Original post by Lode
Well even if the scenes for the movies are polygonal, the LIGHTING is still done with raytracing, no way around that.

Errm, Pixar (created A Bug''s Life, Toy Story, etc.) actually use light and shadow mapping (for example) to speed it up and prevent the need for ray tracing. They''re obviously using more advanced versions of the technologies we''re using, but it''s the same idea in principle.

- JQ
Full Speed Games. Coming soon.

Share this post


Link to post
Share on other sites