Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
PracticeDx
Commits
9dac251e
"PracticeDx/Lines.h" did not exist on "67bf391cbc19188d54aef1fa5ab8e1519ac37d98"
Commit
9dac251e
authored
Dec 24, 2022
by
Administrator
Browse files
draw with vertex index and color constant buffer
parent
d40ceedc
Changes
4
Hide whitespace changes
Inline
Side-by-side
PracticeDx/PixelShader.hlsl
View file @
9dac251e
float4
main
(
float3
color
:
Color
)
:
SV_Target
cbuffer
CBuf
{
return
float4
(
color
,
1
.
0
f
);
}
float4
face_color
[
6
];
};
//float4 main( float3 color : Color) : SV_Target
float4
main
(
uint
tid
:
SV_PrimitiveID
)
:
SV_Target
{
//return float4(color, 1.0f);
return
face_color
[
tid
/
2
];
}
\ No newline at end of file
PracticeDx/PracticeDx.vcxproj
View file @
9dac251e
...
...
@@ -138,6 +138,8 @@
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
Pixel
</ShaderType>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ObjectFileOutput
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
$(ProjectDir)%(Filename).cso
</ObjectFileOutput>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
4.0
</ShaderModel>
<ShaderModel
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
4.0
</ShaderModel>
</FxCompile>
<FxCompile
Include=
"VertexShader.hlsl"
>
<ShaderType
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
Vertex
</ShaderType>
...
...
PracticeDx/VertexShader.hlsl
View file @
9dac251e
struct
VSOut
{
float3
color
:
Color
;
float4
pos
:
SV_Position
;
};
cbuffer
CBuf
{
matrix
transform
;
};
VSOut
main
(
float3
pos
:
Position
,
float3
color
:
Color
)
float4
main
(
float3
pos
:
Position
)
:
SV_Position
{
VSOut
vso
;
vso
.
pos
=
mul
(
float4
(
pos
,
1
.
0
f
),
transform
);
vso
.
color
=
color
;
return
vso
;
return
mul
(
float4
(
pos
,
1
.
0
f
),
transform
);
}
\ No newline at end of file
PracticeDx/WinMain.cpp
View file @
9dac251e
...
...
@@ -114,6 +114,32 @@ ConstantBuffer cb =
)
};
// Define color constant buffer
Microsoft
::
WRL
::
ComPtr
<
ID3D11Buffer
>
pColorConstantBuffer
;
// Create constant buffer for color
struct
ColorConstantBuffer
{
struct
{
float
r
;
float
g
;
float
b
;
float
a
;
}
face_colors
[
6
];
};
const
ColorConstantBuffer
ccb
=
{
{
{
1.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
0.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
0.0
f
,
1.0
f
},
{
1.0
f
,
1.0
f
,
0.0
f
},
{
0.0
f
,
1.0
f
,
1.0
f
},
}
};
// Define input layout
ID3D11InputLayout
*
pInputLayout
;
...
...
@@ -206,6 +232,24 @@ void DefineConstantBuffer(float angle)
devcon
->
VSSetConstantBuffers
(
0u
,
1u
,
pConstantBuffer
.
GetAddressOf
());
}
void
DefineColorConstantBuffer
()
{
D3D11_BUFFER_DESC
ccbd
=
{};
ccbd
.
BindFlags
=
D3D11_BIND_CONSTANT_BUFFER
;
ccbd
.
Usage
=
D3D11_USAGE_DEFAULT
;
ccbd
.
CPUAccessFlags
=
0u
;
ccbd
.
MiscFlags
=
0u
;
ccbd
.
ByteWidth
=
sizeof
(
ccb
);
ccbd
.
StructureByteStride
=
0u
;
D3D11_SUBRESOURCE_DATA
ccsd
=
{};
ccsd
.
pSysMem
=
&
ccb
;
dev
->
CreateBuffer
(
&
ccbd
,
&
ccsd
,
&
pColorConstantBuffer
);
// Bind constant buffer to vertex
devcon
->
PSSetConstantBuffers
(
0u
,
1u
,
pColorConstantBuffer
.
GetAddressOf
());
}
void
DefineInputLayout
()
{
// Create input elements description, choosing whatever need to send to GPU
...
...
@@ -214,7 +258,7 @@ void DefineInputLayout()
//{ "Position",0,DXGI_FORMAT_R32G32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{
"Position"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
0
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
//{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,8,D3D11_INPUT_PER_VERTEX_DATA,0 },
{
"Color"
,
0
,
DXGI_FORMAT_R32G32B32_FLOAT
,
0
,
12
,
D3D11_INPUT_PER_VERTEX_DATA
,
0
},
//
{ "Color",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
// Create input layout, using the description Defined above
...
...
@@ -257,6 +301,7 @@ void drawTriangle()
DefineVertexBuffer
();
DefineIndexBuffer
();
DefineConstantBuffer
(
timer
.
Peek
());
DefineColorConstantBuffer
();
DefineInputLayout
();
DrawPrimitive
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment