Jump to content

  • Log In with Google      Sign In   
  • Create Account


More than one vertex/pixel shaders in one project


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 leonard2012   Members   -  Reputation: 163

Like
0Likes
Like

Posted 30 July 2012 - 09:50 AM

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.

Sponsor:

#2 Ripiz   Members   -  Reputation: 525

Like
1Likes
Like

Posted 30 July 2012 - 10:42 AM

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.

#3 leonard2012   Members   -  Reputation: 163

Like
0Likes
Like

Posted 31 July 2012 - 11:06 AM

Thanks Ripiz.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS