Commit be6a14ed authored by chili's avatar chili
Browse files

pyramid and cylinder independent meshes

parent 3164667b
...@@ -16,23 +16,12 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng, ...@@ -16,23 +16,12 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
if( !IsStaticInitialized() ) if( !IsStaticInitialized() )
{ {
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
};
auto model = Prism::MakeTesselatedIndependentCapNormals<Vertex>( tdist( rng ) );
AddStaticBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
auto pvs = std::make_unique<VertexShader>( gfx,L"PhongVS.cso" ); auto pvs = std::make_unique<VertexShader>( gfx,L"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode(); auto pvsbc = pvs->GetBytecode();
AddStaticBind( std::move( pvs ) ); AddStaticBind( std::move( pvs ) );
AddStaticBind( std::make_unique<PixelShader>( gfx,L"IndexedPhongPS.cso" ) ); AddStaticBind( std::make_unique<PixelShader>( gfx,L"IndexedPhongPS.cso" ) );
AddStaticIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied = const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{ {
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 }, { "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
...@@ -57,10 +46,15 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng, ...@@ -57,10 +46,15 @@ Cylinder::Cylinder( Graphics& gfx,std::mt19937& rng,
} matConst; } matConst;
AddStaticBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,matConst,1u ) ); AddStaticBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,matConst,1u ) );
} }
else
struct Vertex
{ {
SetIndexFromStatic(); dx::XMFLOAT3 pos;
} dx::XMFLOAT3 n;
};
const auto model = Prism::MakeTesselatedIndependentCapNormals<Vertex>( tdist( rng ) );
AddBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
AddIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) ); AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
} }
...@@ -18,39 +18,12 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng, ...@@ -18,39 +18,12 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
if( !IsStaticInitialized() ) if( !IsStaticInitialized() )
{ {
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
std::array<char,4> color;
char padding;
};
const auto tesselation = tdist( rng );
auto model = Cone::MakeTesselatedIndependentFaces<Vertex>( tesselation );
// set vertex colors for mesh (tip red blending to blue base)
for( auto& v : model.vertices )
{
v.color = { (char)10,(char)10,(char)255 };
}
for( int i = 0; i < tesselation; i++ )
{
model.vertices[i * 3].color = { (char)255,(char)10,(char)10 };
}
// squash mesh a bit in the z direction
model.Transform( dx::XMMatrixScaling( 1.0f,1.0f,0.7f ) );
// add normals
model.SetNormalsIndependentFlat();
AddStaticBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
auto pvs = std::make_unique<VertexShader>( gfx,L"BlendedPhongVS.cso" ); auto pvs = std::make_unique<VertexShader>( gfx,L"BlendedPhongVS.cso" );
auto pvsbc = pvs->GetBytecode(); auto pvsbc = pvs->GetBytecode();
AddStaticBind( std::move( pvs ) ); AddStaticBind( std::move( pvs ) );
AddStaticBind( std::make_unique<PixelShader>( gfx,L"BlendedPhongPS.cso" ) ); AddStaticBind( std::make_unique<PixelShader>( gfx,L"BlendedPhongPS.cso" ) );
AddStaticIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied = const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{ {
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 }, { "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
...@@ -69,10 +42,32 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng, ...@@ -69,10 +42,32 @@ Pyramid::Pyramid( Graphics& gfx,std::mt19937& rng,
} colorConst; } colorConst;
AddStaticBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,colorConst,1u ) ); AddStaticBind( std::make_unique<PixelConstantBuffer<PSMaterialConstant>>( gfx,colorConst,1u ) );
} }
else
struct Vertex
{
dx::XMFLOAT3 pos;
dx::XMFLOAT3 n;
std::array<char,4> color;
char padding;
};
const auto tesselation = tdist( rng );
auto model = Cone::MakeTesselatedIndependentFaces<Vertex>( tesselation );
// set vertex colors for mesh (tip red blending to blue base)
for( auto& v : model.vertices )
{
v.color = { (char)10,(char)10,(char)255 };
}
for( int i = 0; i < tesselation; i++ )
{ {
SetIndexFromStatic(); model.vertices[i * 3].color = { (char)255,(char)10,(char)10 };
} }
// squash mesh a bit in the z direction
model.Transform( dx::XMMatrixScaling( 1.0f,1.0f,0.7f ) );
// add normals
model.SetNormalsIndependentFlat();
AddBind( std::make_unique<VertexBuffer>( gfx,model.vertices ) );
AddIndexBuffer( std::make_unique<IndexBuffer>( gfx,model.indices ) );
AddBind( std::make_unique<TransformCbuf>( gfx,*this ) ); AddBind( std::make_unique<TransformCbuf>( gfx,*this ) );
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment