Sign in to follow this  
leonard2012

OpenGL More than one vertex/pixel shaders in one project

Recommended Posts

I'm new to D3D11 and trying to port our OpenGL desktop application to Windows RT. In our project, we are inclined to write more than one vertex/pixel shaders. For now we have written two vertex shaders, one for solid color objects and the other for texture-mapped objects. And at runtime we switch vertex shaders for each type of objects using VSSetShader() method. The vertex shader for colored object is defined as:[CODE]
cbuffer cbPerObject : register(b0)
{
matrix model;
matrix view;
matrix projection;
float4 penColor;
};
struct VertexShaderInput
{
float3 pos : POSITION;
float4 color : COLOR;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float4 color : COLOR;
};
// Vertex shader for textureless object
PixelShaderInput ColorVertexShader(VertexShaderInput input)
{
PixelShaderInput output;
float4 pos = float4(input.pos, 1.0f);
pos = mul(pos, model);
pos = mul(pos, view);
pos = mul(pos, projection);
output.pos = pos;
output.color = penColor;
return output;
}
[/CODE]The vertex shader for textured object is[CODE]
cbuffer cbPerObject : register(b0)
{
matrix model;
matrix view;
matrix projection;
float4 penColor;
};
struct VertexShaderInput
{
float3 pos : POSITION;
float2 tex : TEXCOORD;
};
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD;
};
// Vertex shader for textureless object
PixelShaderInput TextureVertexShader(VertexShaderInput input)
{
PixelShaderInput output;
float4 pos = float4(input.pos, 1.0f);
pos = mul(pos, model);
pos = mul(pos, view);
pos = mul(pos, projection);
output.pos = pos;
output.tex = input.tex;
return output;
}
[/CODE]Although the build is successful, I am not sure whether it's the best way to solve our problem to draw graphics objects of different types. Would the redefinition of cbPerObject, VertexShaderInput, and PixelShaderInput cause potential issues? After all, most of the Windows 8 D3D code samples include one vertex shader in the project.

Share this post


Link to post
Share on other sites
As long there's no struct/cbuffer/function with same name in same file (assuming you have no include files) then there's no issues.

Share this post


Link to post
Share on other sites

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