Archived

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

penetrator

Questions about Lesson47 and vertex shaders

Recommended Posts

I started to study cg today so forgive my noob questions. About Lesson47, i understand the .cg file is used to compute the sin wave function in order to achieve the "flag effect". This is done since vertex shaders are ran on GPU and therefore they should give better performances. Oddly, disabling the vertex shader provides the identical performances. Probably because the sin function is not such a cpu-killer ? I must say i''m very confused with the use of these shaders. For example, i don''t understand if drawing a high polygon count using vertex shader is possible. I suppose yes, but wouldn''t be the same than using VAR or VBO''s ? Also, Lesson47 is drawing a simple triangle strip, but i fail to see if it''s drawn directly to the GPU or via the vertex shader.

Share this post


Link to post
Share on other sites
all a vertex shader does is replaces parts of the T&L pipeline. The parts that takes an input vertex position (through glVertex or whatever) and transform it to screen corrdinates, and light it, etc. This is done on the video card (like the T&L pipeline) - T&L of course being transform and lighting. The CPU has nothing to do with it after the draw command.

The advantage comes in that vertex shaders are flexible. standard T&L isn''t, it used to ONLY transform and ONLY light the vertices passed to it. But now, you can do more, you can, for example, make the video card hardware apply a sine pattern to the vertices.. to make a flag effect. Because the video card is designed for this sort of operation, it''s extremly efficient, and should have no impact on performance. It''s certainly MUCH faster than uploading the new vertices to the video card every frame from the cpu (if it were to calculate the sine pattern).. So, effectivly, with VBO, the CPU never sees the vertex data. it just tells the video card to render the vertices IT has in IT''s memory, using a certain shader. Thats it. no work for the CPU.

CG is just a language that makes it easy to write shaders. There are many other ways you can write vertex/pixel shaders (I once counted up to 20 before stopping), CG just does a background conversion.

| - My (new) little website - | - email me - |

Share this post


Link to post
Share on other sites