basic shader question...

Started by
7 comments, last by coreSOLO 15 years, 8 months ago
I am new to HLSL, but I am able to compile and run very basic shaders. Though I have a few questions, For example, if I have the following PS, ------------ float4 MyPixelShader( float2 Tex : TEXCOORD0 ) : COLOR0 { float4 Color; Color = tex2D( g_samSrcColor, Tex.xy); return Color; } ------------ - What is the frequency of execution of this shader? Will it run once per pixel or once frame and process all the pixels in one execution? - The same way, are vertex shaders run once per vertex, or once per frame? - Also, if I have 1 vertex shader in scene, and two objects, will it execute once for each 3d object, ie, twice per frame? sorry for the noobish questions, but i didnt get the answers anywhere :(
Advertisement
A vertex shader is run once for each vertex. The pixel shader is the same, except that it works with pixels :)
Btw have you read the tutorials in the DirectX SDK ? I know what I wrote above from there.
Thnaks, i am going thru the tutorials, but they are more like a reference manual :( anyways I have ordered a shaders book that i'll get in a few days. In the meanwile :

- is there a way to keep track of the vertex index in Vertex Shader while processing a vertex? For example, if I have a cube processed by VS and I want exactly the "N"th (eg 3rd) vertex to change its position (eg outPos.x = inPos.x + 1), how can I do it? Is there a code like...

void VS ( in float4 inPos : POSITION , out float4 outPos : POSITION )
{
outPos = inPos;

if (<this is the 3rd vertex of my cube>) // what do I do for this ???
outPos.x = inPos.x + 1;
}
Quote:Original post by coreSOLO
- is there a way to keep track of the vertex index in Vertex Shader while processing a vertex?


Yes. Just use different vertex shaders for your cube and other objects. Why check which vertex belongs ti which object in a vertex shader when you already know it?
If you want to chagne 1 specific vertex why can't you just do it before you feed it to the GPU? If you insist you can use Vertex Attributes or TexCoords to encode some information there and then use if ().
Actually I am already using different shaders for different objetcs, I just wanted to identify and mutate some special vertices of an object. I know I can do it in CPU, but I just wanted to know the shader way. Maybe create a shader to process a cube that converts into cuboid over time, or something similar...
In Direct3D 10 you have access to this. In D3D9 you can provide a count as another field in the vertex.
cool :) but then how do they create VS effects like cloths in DX 9? I just want to know the basic idea. Do they use external timers to control vertex movement randomly?
Cloth simulation is primarily a physics calculation - and is thus usually performed on the CPU. I imagine that the CPU would dynamically modify the position of the vertices in the cloth mesh - I doubt the actual physics simulation is done on the GPU in the vertex shader.
NextWar: The Quest for Earth available now for Windows Phone 7.
oops sorry, maybe I was wrong as I am new to shaders :P

Can someone please tell me some real time use of vertex shaders? The ones listed on various sites are too bookish. Maybe I can use them as some basic exercises...

This topic is closed to new replies.

Advertisement