Passing arguments to vertex shader?

Started by
6 comments, last by Buckeye 13 years, 1 month ago
I'm new to this shader stuff so bear with me.

Let's say i have a VS with these parameters :

float4 Pos : POSITION,
float3 Normal : NORMAL,
float2 TexCoord0 : TEXCOORD0,

To use it, in my c++ code i create my vertices using a suitable FVF (In this case, Position, normal and texture coords), store them in a vertex buffer and render them using DrawPrimitive for example.

But what if i want for example to add a paramter to the VS like:

uniform bool bTexture

How do i pass a boolean to the shader??
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Advertisement
Assuming you're using an ID3DXEffect for your shader, effect->SetBool(...).

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Isn't this how you set global variables?
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

Isn't this how you set global variables?

Yep. Isn't that your question?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


[quote name='Waaayoff' timestamp='1298225159' post='4776737']
Isn't this how you set global variables?

Yep. Isn't that your question?
[/quote]

Nope, i meant how do i pass a parameter to the shader function. Like:

VS_OUTPUT VertexShader([color=#1C2837][size=2]float4 Pos : POSITION, uniform bool Whatever)
[color=#1C2837][size=2]

[color=#1C2837][size=2]I saw it in an SDK sample but couldn't figure out how they passed the boolean in the source code..
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Which SDK example are you looking at?

In any case, it's commonly done through a particular technique.

VS_OUTPUT RenderSceneVS( float4 pos: POSITION, uniform bool Whatever )
{
//...
}

technique RenderSceneWithWhatever
{
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS( true );
}
}
technique RenderSceneWithoutWhatever
{
pass P0
{
VertexShader = compile vs_2_0 RenderSceneVS( false );
}
}

Then set the technique depending on whether you want Whatever to be true or false. Whatever (either true or false) will then persist for the life of the technique.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Oh! Thanks :)


Which SDK example are you looking at?

Basic HLSL
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

Oh! Thanks :)

[quote name='Buckeye' timestamp='1298302940' post='4777048']
Which SDK example are you looking at?

Basic HLSL
[/quote]
Good. Maybe you just missed the technique definitions at the end of the fx file. Actually, that's what I looked at to provide you the example. ;)

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement