UV Texturkoordinaten ergaenzt;

V2 struct fuer UV Koordinaten ergaenzt;

git-svn-id: svn://ammerhai.com/home/mike/pokemon_repo@16 24008968-59e6-ed4c-a10b-0b2c954b24ab
This commit is contained in:
mikeb 2021-06-30 16:00:14 +00:00
parent 0f6bfcdc4b
commit ce923a77fb
6 changed files with 33 additions and 19 deletions

View File

@ -1,17 +1,18 @@
struct VertexShaderInput {
// Per Vertex
float4 pos : VERTEX_POSITION;
float4 uvst : COORDINATES;
float2 uv : UV_VERTEX;
uint vid : SV_VertexID;
// Per Instance
float4 pos_size : INSTANCE_POSITION_SIZE;
uint tile_type : TILE_TYPE;
float4 uv0uv1 : UV_INSTANCE;
};
struct VertexShaderOutput {
float4 pos : SV_POSITION;
float4 uvst : COORDINATES;
float4 uv0uv1 : COORDINATES;
uint tile_type : TILE_TYPE;
};
@ -46,7 +47,9 @@ VertexShaderOutput main(VertexShaderInput input) {
//output.pos.xy = mul(pos, input.pos.xyz).xy;
output.pos.zw = float2(0, 1);
output.uvst = input.uvst;
output.uv0uv1.zw = float2(0, 0);
output.uv0uv1.xy = lerp(input.uv0uv1.xy, input.uv0uv1.zw, input.uv.xy);
output.tile_type = input.tile_type;
return output;

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -65,14 +65,14 @@ bool Running = true;
struct Vertex {
V4 pos;
V4 uvst;
V2 uv0uv1;
};
Vertex vertices[] = {
{{ -1, 1, 1, 1 } , { 0, 1, 0, 0 }},
{{ 1, -1, 1, 1 } , { 1, 0, 0, 0 }},
{{ -1, -1, 1, 1 } , { 0, 0, 0, 0 }},
{{ 1, 1, 1, 1 } , { 1, 1, 0, 0 }},
{{ -1, 1, 1, 1 }, {0, 1}},
{{ 1, -1, 1, 1 }, {1, 0}},
{{ -1, -1, 1, 1 }, {0, 0}},
{{ 1, 1, 1, 1 }, {1, 1}},
};
uint16 indices[] = {
@ -83,13 +83,14 @@ uint16 indices[] = {
struct Instance {
V4 pos_size;
uint32 tile_type;
V4 uv0uv1;
};
Instance tiles_instances[view_width * view_height] = {
};
Instance player_instance = { {0.5f, 0.5f, 1.0f / view_width, 1.0f / view_height } };
Instance player_instance = { {0.5f, 0.5f, 1.0f / view_width, 1.0f / view_height}, 0, {0, 0, 1, 1}};
struct Tile {
uint32 type;
@ -496,9 +497,10 @@ bool init_directx11(HWND Window) {
D3D11_INPUT_ELEMENT_DESC input_element_desc[] = {
{ "VERTEX_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COORDINATES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "UV_VERTEX", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "INSTANCE_POSITION_SIZE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "TILE_TYPE", 0, DXGI_FORMAT_R32_UINT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1},
{ "UV_INSTANCE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 20, D3D11_INPUT_PER_INSTANCE_DATA, 1 }
};
if (device->CreateInputLayout(input_element_desc, sizeof(input_element_desc) / sizeof(*input_element_desc), vertex_shader_code->GetBufferPointer(), vertex_shader_code->GetBufferSize(), &input_layout)) {
@ -676,12 +678,14 @@ ID3D11ShaderResourceView* create_shader_texture(char* bmp_texture_path) {
return resource_view;
}
void render_quad(V2 pos, V2 size, ID3D11ShaderResourceView* texture, bool is_animated) {
void render_quad(V2 pos, V2 size, ID3D11ShaderResourceView* texture, V2 uv0, V2 uv1) {
ID3D11ShaderResourceView* quad_texture = texture;
quad_instance.pos_size.xy = pos;
quad_instance.pos_size.zw = size;
quad_instance.uv0uv1.uv0 = uv0;
quad_instance.uv0uv1.uv1 = uv1;
//Grafikkarte updaten
D3D11_MAPPED_SUBRESOURCE quad_mapped_subressource;
@ -690,8 +694,8 @@ void render_quad(V2 pos, V2 size, ID3D11ShaderResourceView* texture, bool is_ani
devicecontext->Unmap(quad_instance_buffer, 0);
UINT input_strides[] = {
sizeof(Vertex),
sizeof(Instance),
sizeof(Vertex),
sizeof(Instance),
};
UINT input_offsets[] = {
@ -725,6 +729,7 @@ int main() {
tiles_instances[x + y * view_width].pos_size.zw = { 1.0f / view_width, 1.0f / view_height };
tiles_instances[x + y * view_width].pos_size.xy = { (float)x / view_width, (float)y / (float)view_height };
tiles_instances[x + y * view_width].pos_size.xy += tiles_instances[x + y * view_width].pos_size.zw * 0.5f;
tiles_instances[x + y * view_width].uv0uv1 = { 0, 0, 1, 1};
}
}
@ -753,7 +758,7 @@ int main() {
load_map();
V2 quad_pos = { 0.001f, 0.001f };
V2 quad_pos = { 0.101f, 0.101f };
V2 quad_size = { 0.1f, 0.1f };
MSG Message;
@ -832,10 +837,10 @@ int main() {
devicecontext->DrawIndexedInstanced(6, 1, 0, 0, 0);
//Moving Quad
quad_pos += {0.001f, 0.001f};
//quad_pos += {0.001f, 0.001f};
render_quad(quad_pos, quad_size, quad_texture, 1);
render_quad({ 0.1, 0.2 }, { 0.01, 0.01 }, quad_texture, 0);
render_quad(quad_pos, quad_size, quad_texture, { 0, 0 }, { 1, 1 });
render_quad({ 0.1, 0.2 }, { 0.01, 0.01 }, quad_texture, { 0, 0 }, { 1, 1 });
//
swap_chain->Present(1, 0);

View File

@ -423,13 +423,19 @@ union V4 {
float t;
};
//von V3 zu V2 ohne z
//von V4 zu V2 ohne z
struct {
V2 xy;
V2 zw;
};
//von V3 zu V2 ohne x
//V2 fuer Teiltexturenausgabe
struct {
V2 uv0;
V2 uv1;
};
//von V4 zu V2 ohne x
struct {
float _x;
V2 yz;