More than one vertex/pixel shaders in one project

Started by
1 comment, last by leonard2012 11 years, 9 months ago
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:
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;
}
The vertex shader for textured object is
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;
}
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.
Advertisement
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.
Thanks Ripiz.

This topic is closed to new replies.

Advertisement