Jump to content
  • Advertisement
Sign in to follow this  
Lakshmi Narayan

Help Regarding hlsl shaders

This topic is 2236 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

float4x4 World;
float4x4 View;float4x4 Projection;

float4 AmbientColor = float4(1, 1, 1, 1);
float AmbientIntensity = 0.1;

struct VertexShaderInput
{
float4 Position : POSITION0;
};

struct VertexShaderOutput
{
float4 Position : POSITION0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;

float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);

return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
return AmbientColor * AmbientIntensity;
}

technique Ambient
{
pass Pass1
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}



i am trying to learn how to use shaders with directx and i found this code over d net

icould not understand the following thingsin above code

float4 Position : (POSITION0)?;

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 ?

Also how these function works
technique Ambient
{
pass Pass1(wt is this)
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}

Also, let me know if there is any video tutorial on shaders with directx.

Share this post


Link to post
Share on other sites
Advertisement
What about those 2 lines do you not understand? They map vertex data to variables inside the shader. In this case position and a diffuse colour I guess.
As for the technique thingy it's a d3dx utility to use and manage shaders at a higher level.

Share this post


Link to post
Share on other sites
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]float4 Position : (POSITION0)?;[/background]

[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 ?[/background]

[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[background=rgb(250, 251, 252)]so the above functions are used to [/background]

[/font]

[background=rgb(250, 251, 252)][font="helvetica, arial, verdana, tahoma, sans-serif"][size="2"][color="#282828"]map vertex data to variables inside the shader but what is the vertex data in the above two lines of code. (can you elaborate)[/font][/background]



[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=1]

[background=rgb(250, 251, 252)]Also suggest me a site or a tutorial where i can start learning to program shaders [/background]

[/font]

Share this post


Link to post
Share on other sites
The first line you ask about is not a function. It is part of a struct definition. I think what is confusing you are the semantics at the end of the line. They serve to describe the intended use of a variable or a function's return value. I'm not familiar of a site from which to learn other MSDN.

Oh, and vertex data is mapped to the vertex shader's input. The way the vertex data is structured and sent is defined in the application using the DirectX API. The vertex shader needs to be written to expect it's input the same format the app is written to send it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!