Understanding cg

Started by
14 comments, last by gimp 21 years, 3 months ago
Yes, same here. i always hear of vertex/pixel shaders, but I have no idea whatsoever what they are. the only thing I know about them is that people talk about them to sound 1337 :D

Height Map Editor | Eternal lands
Advertisement
Shaders are little programs you write that the graphics card chip then executes. You have vertex and its elements like position, color, texture coordinate, etc. that can be modified by the vertex program you write. The pixel shader interpolates vertex color previously computed in vertex shader that it can now modify. I think output of pixel shader is pixel''s color and fog color. In new shaders ver.3, both the vertex and pixel shaders can load and sample or lookup textures and their encoded color or math function values. In older shaders only the pixel shader can sample texture. So texture is not simply something that is put onto polygons or is blended with other textures for final effect, it can contain math function that modify the vertex passed into vertex shader from your geometry. You can for example compute attenuated distance for your pixel lights by subtracting vertex''s world position from light''s world position then figure out if the geometry is in light''s radius or not. You can do this on cpu also but you can offload many ''cpu'' operations onto the gfx card''s shading hw. People are only now realizing the freedom that new shaders allow. The high level shading language (hlsl) simplifies writing vertex/pixel shaders because until now you had to write them in assembly like way with register twiddling and all that, ie. c vs. assembly. You don''t have to use shaders and instead can rely on fixed function vertex/texture blending pipeline. Shaders are more flexible though and I don''t think fixed function pipeline is going to be the ihv focus anymore. There will still be need for xforms to do on cpu like for tools, editors, etc. where shaders might not be appropriate. Though only time will tell where shaders really stand.
hm would it be possible to use shadow coordinates instead of lightmaps?

lets say you have a static geometry and you have around 25 points per polygon and define whether or not these points are covered with shadow if so you modify the shader so it draws shadows ....you know what i mean

but how would i get the shadow coordinates to the shader?
that would be interesting
can i use vertex shaders on GF2 ultra cards? cause i am planing to update my system next summer and i can t wait to test this
http://www.8ung.at/basiror/theironcross.html
You want to use stencil shadow volumes or shadow buffers. Lightmaps are going away because of their static nature. Instead of geometry being split up to accept max lightmap size for shadows or lights you instead let stencil buffer mask off areas where light can be drawn using per-pixel lights so no need to split your polys.

You can create degenerate vertices for your geometry and extrude them inside the vertex shader creating a shadow volume poly for stencil shadow volumes. I haven''t done this but there is an article on this site that talks about it. Ati has some docs on this as well, in theri sushi engine docs I think.

Vertices go first thru tesselator then if tesselator creates additional vertices these are then passed to your vertex shader as far as I understand it. You can''t create new vertices in vertex shader I don''t think. I haven''t thought about it fully so I might be wrong, but nvidia shader docs said you couldn''t. Maybe in later version shaders you will be able to, I think once we get the primitive engine into gpu. It won''t be in gffx 1.

You can use vertex shaders that are reading from system memory vertex buffers and which are done with simd/3dnow asm cpu instructions. Pixel shaders to my knowledge can only be done in hardware except d3d''s reference rasterizer which is just software emulated pipeline and too slow for shipping apps. Opengl arb_fragment_program extension might also emulate pixel shaders in software though I''m not sure.

Today''s gfx cards support various shader versions. Gf3 supports ps1.0-1.3, radeon 8500/9000/9100 have ps1.4 and emulate ps1.0-1.3, gffx can do vs/ps 2 extended while r9700 can do vs/ps 2 only. New hw shader engines can emulate older shaders from what I understand.

Gf2 can only use vertex shaders 1.1,2.0,3.0 emulated in software. No pixel shaders. You can still use the texture blending stages for per-pixel lights and stencil support for shadows, I''ve done this but it can be slow with many dynamic lights casting shadows all over the place. The gf2 hw can also do dot3 for bump mapping and other stuff but it''s definitely not as flexible or feature rich as pixel shaders.
Thanks for clarifying this to us I guess shaders are too fancy for me I mean, I am perfectly happy with the way OpenGL takes care of things, and I don''t need (at least, not for my engine) anything I can''t do with GL 1.1

Height Map Editor | Eternal lands
well casting dynamic shadows on a brush base map ala halflife would be very difficult i stick with lightmaps for static geometry and use stencil shadows for the playermodels and entities

are there book about vertex programming?
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement