Sign in to follow this  

Passing arguments to vertex shader?

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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??

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1298244763' post='4776832']
[quote name='Waaayoff' timestamp='1298225159' post='4776737']
Isn't this how you set global variables?
[/quote]
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)[/size][/color]
[color=#1C2837][size=2]
[/size][/color]
[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..[/size][/color]

Share this post


Link to post
Share on other sites
Which SDK example are you looking at?

In any case, it's commonly done through a particular technique.
[code]
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 );
}
}
[/code]
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.

Share this post


Link to post
Share on other sites
[quote name='Waaayoff' timestamp='1298304649' post='4777062']
Oh! Thanks :)

[quote name='Buckeye' timestamp='1298302940' post='4777048']
Which SDK example are you looking at?
[/quote]
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. ;)

Share this post


Link to post
Share on other sites

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this