mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-01-05 15:11:16 +00:00
Port 2cycle/lightmap code to dx11
This commit is contained in:
parent
ab2cbb2dbc
commit
a191884c28
8 changed files with 118 additions and 121 deletions
|
@ -20,7 +20,7 @@ enum {
|
||||||
CC_PRIMA,
|
CC_PRIMA,
|
||||||
CC_SHADEA,
|
CC_SHADEA,
|
||||||
CC_ENVA,
|
CC_ENVA,
|
||||||
CC_MAX,
|
CC_ENUM_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
|
@ -68,7 +68,7 @@ struct ShaderProgramD3D11 {
|
||||||
ComPtr<ID3D11InputLayout> input_layout;
|
ComPtr<ID3D11InputLayout> input_layout;
|
||||||
ComPtr<ID3D11BlendState> blend_state;
|
ComPtr<ID3D11BlendState> blend_state;
|
||||||
|
|
||||||
uint32_t shader_id;
|
uint64_t hash;
|
||||||
uint8_t num_inputs;
|
uint8_t num_inputs;
|
||||||
uint8_t num_floats;
|
uint8_t num_floats;
|
||||||
bool used_textures[2];
|
bool used_textures[2];
|
||||||
|
@ -323,14 +323,14 @@ static void gfx_d3d11_load_shader(struct ShaderProgram *new_prg) {
|
||||||
d3d.shader_program = (struct ShaderProgramD3D11 *)new_prg;
|
d3d.shader_program = (struct ShaderProgramD3D11 *)new_prg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint32_t shader_id) {
|
static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(struct ColorCombiner* cc) {
|
||||||
CCFeatures cc_features;
|
CCFeatures cc_features = { 0 };
|
||||||
gfx_cc_get_features(shader_id, &cc_features);
|
gfx_cc_get_features(cc, &cc_features);
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
size_t len, num_floats;
|
size_t len, num_floats;
|
||||||
|
|
||||||
gfx_direct3d_common_build_shader(buf, len, num_floats, cc_features, false, THREE_POINT_FILTERING);
|
gfx_direct3d_common_build_shader(buf, len, num_floats, *cc, cc_features, false, THREE_POINT_FILTERING);
|
||||||
|
|
||||||
ComPtr<ID3DBlob> vs, ps;
|
ComPtr<ID3DBlob> vs, ps;
|
||||||
ComPtr<ID3DBlob> error_blob;
|
ComPtr<ID3DBlob> error_blob;
|
||||||
|
@ -368,11 +368,14 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint32_t shade
|
||||||
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
|
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
|
||||||
ied[ied_index++] = { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
ied[ied_index++] = { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
||||||
}
|
}
|
||||||
if (cc_features.opt_fog) {
|
if (cc->cm.use_fog) {
|
||||||
ied[ied_index++] = { "FOG", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
ied[ied_index++] = { "FOG", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
||||||
}
|
}
|
||||||
|
if (cc->cm.light_map) {
|
||||||
|
ied[ied_index++] = { "LIGHTMAP", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
||||||
|
}
|
||||||
for (uint32_t i = 0; i < cc_features.num_inputs; i++) {
|
for (uint32_t i = 0; i < cc_features.num_inputs; i++) {
|
||||||
DXGI_FORMAT format = cc_features.opt_alpha ? DXGI_FORMAT_R32G32B32A32_FLOAT : DXGI_FORMAT_R32G32B32_FLOAT;
|
DXGI_FORMAT format = cc->cm.use_alpha ? DXGI_FORMAT_R32G32B32A32_FLOAT : DXGI_FORMAT_R32G32B32_FLOAT;
|
||||||
ied[ied_index++] = { "INPUT", i, format, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
ied[ied_index++] = { "INPUT", i, format, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +386,7 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint32_t shade
|
||||||
D3D11_BLEND_DESC blend_desc;
|
D3D11_BLEND_DESC blend_desc;
|
||||||
ZeroMemory(&blend_desc, sizeof(D3D11_BLEND_DESC));
|
ZeroMemory(&blend_desc, sizeof(D3D11_BLEND_DESC));
|
||||||
|
|
||||||
if (cc_features.opt_alpha) {
|
if (cc->cm.use_alpha) {
|
||||||
blend_desc.RenderTarget[0].BlendEnable = true;
|
blend_desc.RenderTarget[0].BlendEnable = true;
|
||||||
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||||
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||||
|
@ -401,7 +404,7 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint32_t shade
|
||||||
|
|
||||||
// Save some values
|
// Save some values
|
||||||
|
|
||||||
prg->shader_id = shader_id;
|
prg->hash = cc->hash;
|
||||||
prg->num_inputs = cc_features.num_inputs;
|
prg->num_inputs = cc_features.num_inputs;
|
||||||
prg->num_floats = num_floats;
|
prg->num_floats = num_floats;
|
||||||
prg->used_textures[0] = cc_features.used_textures[0];
|
prg->used_textures[0] = cc_features.used_textures[0];
|
||||||
|
@ -410,9 +413,9 @@ static struct ShaderProgram *gfx_d3d11_create_and_load_new_shader(uint32_t shade
|
||||||
return (struct ShaderProgram *)(d3d.shader_program = prg);
|
return (struct ShaderProgram *)(d3d.shader_program = prg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ShaderProgram *gfx_d3d11_lookup_shader(uint32_t shader_id) {
|
static struct ShaderProgram *gfx_d3d11_lookup_shader(struct ColorCombiner* cc) {
|
||||||
for (size_t i = 0; i < d3d.shader_program_pool_size; i++) {
|
for (size_t i = 0; i < d3d.shader_program_pool_size; i++) {
|
||||||
if (d3d.shader_program_pool[i].shader_id == shader_id) {
|
if (d3d.shader_program_pool[i].hash == cc->hash) {
|
||||||
return (struct ShaderProgram *)&d3d.shader_program_pool[i];
|
return (struct ShaderProgram *)&d3d.shader_program_pool[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ static struct ShaderProgram *gfx_direct3d12_create_and_load_new_shader(uint32_t
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
size_t len, num_floats;
|
size_t len, num_floats;
|
||||||
|
|
||||||
gfx_direct3d_common_build_shader(buf, len, num_floats, cc_features, true, false);
|
gfx_direct3d_common_build_shader(buf, len, num_floats, *cc, cc_features, true, false);
|
||||||
|
|
||||||
//fwrite(buf, 1, len, stdout);
|
//fwrite(buf, 1, len, stdout);
|
||||||
|
|
||||||
|
|
|
@ -5,46 +5,6 @@
|
||||||
#include "gfx_direct3d_common.h"
|
#include "gfx_direct3d_common.h"
|
||||||
#include "gfx_cc.h"
|
#include "gfx_cc.h"
|
||||||
|
|
||||||
void get_cc_features(uint32_t shader_id, CCFeatures *cc_features) {
|
|
||||||
for (int32_t i = 0; i < 4; i++) {
|
|
||||||
cc_features->c[0][i] = (shader_id >> (i * 3)) & 7;
|
|
||||||
cc_features->c[1][i] = (shader_id >> (12 + i * 3)) & 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_features->opt_alpha = (shader_id & SHADER_OPT_ALPHA) != 0;
|
|
||||||
cc_features->opt_fog = (shader_id & SHADER_OPT_FOG) != 0;
|
|
||||||
cc_features->opt_texture_edge = (shader_id & SHADER_OPT_TEXTURE_EDGE) != 0;
|
|
||||||
cc_features->opt_noise = (shader_id & SHADER_OPT_NOISE) != 0;
|
|
||||||
|
|
||||||
cc_features->used_textures[0] = false;
|
|
||||||
cc_features->used_textures[1] = false;
|
|
||||||
cc_features->num_inputs = 0;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < 2; i++) {
|
|
||||||
for (int32_t j = 0; j < 4; j++) {
|
|
||||||
if (cc_features->c[i][j] >= SHADER_INPUT_1 && cc_features->c[i][j] <= SHADER_INPUT_8) {
|
|
||||||
if (cc_features->c[i][j] > cc_features->num_inputs) {
|
|
||||||
cc_features->num_inputs = cc_features->c[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cc_features->c[i][j] == SHADER_TEXEL0 || cc_features->c[i][j] == SHADER_TEXEL0A) {
|
|
||||||
cc_features->used_textures[0] = true;
|
|
||||||
}
|
|
||||||
if (cc_features->c[i][j] == SHADER_TEXEL1 || cc_features->c[i][j] == SHADER_TEXEL1A) {
|
|
||||||
cc_features->used_textures[1] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cc_features->do_single[0] = cc_features->c[0][2] == 0;
|
|
||||||
cc_features->do_single[1] = cc_features->c[1][2] == 0;
|
|
||||||
cc_features->do_multiply[0] = cc_features->c[0][1] == 0 && cc_features->c[0][3] == 0;
|
|
||||||
cc_features->do_multiply[1] = cc_features->c[1][1] == 0 && cc_features->c[1][3] == 0;
|
|
||||||
cc_features->do_mix[0] = cc_features->c[0][1] == cc_features->c[0][3];
|
|
||||||
cc_features->do_mix[1] = cc_features->c[1][1] == cc_features->c[1][3];
|
|
||||||
cc_features->color_alpha_same = (shader_id & 0xfff) == ((shader_id >> 12) & 0xfff);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void append_str(char *buf, size_t *len, const char *str) {
|
static void append_str(char *buf, size_t *len, const char *str) {
|
||||||
while (*str != '\0') buf[(*len)++] = *str++;
|
while (*str != '\0') buf[(*len)++] = *str++;
|
||||||
}
|
}
|
||||||
|
@ -72,13 +32,13 @@ static const char *shader_item_to_str(int32_t item, bool with_alpha, bool only_a
|
||||||
case SHADER_INPUT_4:
|
case SHADER_INPUT_4:
|
||||||
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input4.rgb";
|
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input4.rgb";
|
||||||
case SHADER_INPUT_5:
|
case SHADER_INPUT_5:
|
||||||
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input5.rgb";
|
return with_alpha || !inputs_have_alpha ? "input.input5" : "input.input5.rgb";
|
||||||
case SHADER_INPUT_6:
|
case SHADER_INPUT_6:
|
||||||
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input6.rgb";
|
return with_alpha || !inputs_have_alpha ? "input.input6" : "input.input6.rgb";
|
||||||
case SHADER_INPUT_7:
|
case SHADER_INPUT_7:
|
||||||
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input7.rgb";
|
return with_alpha || !inputs_have_alpha ? "input.input7" : "input.input7.rgb";
|
||||||
case SHADER_INPUT_8:
|
case SHADER_INPUT_8:
|
||||||
return with_alpha || !inputs_have_alpha ? "input.input4" : "input.input8.rgb";
|
return with_alpha || !inputs_have_alpha ? "input.input8" : "input.input8.rgb";
|
||||||
case SHADER_TEXEL0:
|
case SHADER_TEXEL0:
|
||||||
return with_alpha ? "texVal0" : "texVal0.rgb";
|
return with_alpha ? "texVal0" : "texVal0.rgb";
|
||||||
case SHADER_TEXEL0A:
|
case SHADER_TEXEL0A:
|
||||||
|
@ -131,34 +91,34 @@ static const char *shader_item_to_str(int32_t item, bool with_alpha, bool only_a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void append_formula(char *buf, size_t *len, const uint8_t c[2][4], bool do_single, bool do_multiply, bool do_mix, bool with_alpha, bool only_alpha, bool opt_alpha) {
|
static void append_formula(char *buf, size_t *len, const uint8_t* c, bool do_single, bool do_multiply, bool do_mix, bool with_alpha, bool only_alpha, bool opt_alpha) {
|
||||||
if (do_single) {
|
if (do_single) {
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][3], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 3], with_alpha, only_alpha, opt_alpha, false));
|
||||||
} else if (do_multiply) {
|
} else if (do_multiply) {
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 0], with_alpha, only_alpha, opt_alpha, false));
|
||||||
append_str(buf, len, " * ");
|
append_str(buf, len, " * ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 2], with_alpha, only_alpha, opt_alpha, true));
|
||||||
} else if (do_mix) {
|
} else if (do_mix) {
|
||||||
append_str(buf, len, "lerp(");
|
append_str(buf, len, "lerp(");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][1], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 1], with_alpha, only_alpha, opt_alpha, false));
|
||||||
append_str(buf, len, ", ");
|
append_str(buf, len, ", ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 0], with_alpha, only_alpha, opt_alpha, false));
|
||||||
append_str(buf, len, ", ");
|
append_str(buf, len, ", ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 2], with_alpha, only_alpha, opt_alpha, true));
|
||||||
append_str(buf, len, ")");
|
append_str(buf, len, ")");
|
||||||
} else {
|
} else {
|
||||||
append_str(buf, len, "(");
|
append_str(buf, len, "(");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][0], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 0], with_alpha, only_alpha, opt_alpha, false));
|
||||||
append_str(buf, len, " - ");
|
append_str(buf, len, " - ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][1], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 1], with_alpha, only_alpha, opt_alpha, false));
|
||||||
append_str(buf, len, ") * ");
|
append_str(buf, len, ") * ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][2], with_alpha, only_alpha, opt_alpha, true));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 2], with_alpha, only_alpha, opt_alpha, true));
|
||||||
append_str(buf, len, " + ");
|
append_str(buf, len, " + ");
|
||||||
append_str(buf, len, shader_item_to_str(c[only_alpha][3], with_alpha, only_alpha, opt_alpha, false));
|
append_str(buf, len, shader_item_to_str(c[only_alpha * 4 + 3], with_alpha, only_alpha, opt_alpha, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_floats, const CCFeatures& cc_features, bool include_root_signature, bool three_point_filtering) {
|
void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_floats, struct ColorCombiner& cc, const CCFeatures& ccf, bool include_root_signature, bool three_point_filtering) {
|
||||||
len = 0;
|
len = 0;
|
||||||
num_floats = 4;
|
num_floats = 4;
|
||||||
|
|
||||||
|
@ -166,14 +126,14 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
|
|
||||||
if (include_root_signature) {
|
if (include_root_signature) {
|
||||||
append_str(buf, &len, "#define RS \"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_VERTEX_SHADER_ROOT_ACCESS)");
|
append_str(buf, &len, "#define RS \"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | DENY_VERTEX_SHADER_ROOT_ACCESS)");
|
||||||
if (cc_features.opt_alpha && cc_features.opt_noise) {
|
if (cc.cm.use_alpha && cc.cm.use_noise) {
|
||||||
append_str(buf, &len, ",CBV(b0, visibility = SHADER_VISIBILITY_PIXEL)");
|
append_str(buf, &len, ",CBV(b0, visibility = SHADER_VISIBILITY_PIXEL)");
|
||||||
}
|
}
|
||||||
if (cc_features.used_textures[0]) {
|
if (ccf.used_textures[0]) {
|
||||||
append_str(buf, &len, ",DescriptorTable(SRV(t0), visibility = SHADER_VISIBILITY_PIXEL)");
|
append_str(buf, &len, ",DescriptorTable(SRV(t0), visibility = SHADER_VISIBILITY_PIXEL)");
|
||||||
append_str(buf, &len, ",DescriptorTable(Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL)");
|
append_str(buf, &len, ",DescriptorTable(Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL)");
|
||||||
}
|
}
|
||||||
if (cc_features.used_textures[1]) {
|
if (ccf.used_textures[1]) {
|
||||||
append_str(buf, &len, ",DescriptorTable(SRV(t1), visibility = SHADER_VISIBILITY_PIXEL)");
|
append_str(buf, &len, ",DescriptorTable(SRV(t1), visibility = SHADER_VISIBILITY_PIXEL)");
|
||||||
append_str(buf, &len, ",DescriptorTable(Sampler(s1), visibility = SHADER_VISIBILITY_PIXEL)");
|
append_str(buf, &len, ",DescriptorTable(Sampler(s1), visibility = SHADER_VISIBILITY_PIXEL)");
|
||||||
}
|
}
|
||||||
|
@ -182,37 +142,41 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
|
|
||||||
append_line(buf, &len, "struct PSInput {");
|
append_line(buf, &len, "struct PSInput {");
|
||||||
append_line(buf, &len, " float4 position : SV_POSITION;");
|
append_line(buf, &len, " float4 position : SV_POSITION;");
|
||||||
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
|
if (ccf.used_textures[0] || ccf.used_textures[1]) {
|
||||||
append_line(buf, &len, " float2 uv : TEXCOORD;");
|
append_line(buf, &len, " float2 uv : TEXCOORD;");
|
||||||
num_floats += 2;
|
num_floats += 2;
|
||||||
}
|
}
|
||||||
if (cc_features.opt_alpha && cc_features.opt_noise) {
|
if (cc.cm.use_alpha && cc.cm.use_noise) {
|
||||||
append_line(buf, &len, " float4 screenPos : TEXCOORD1;");
|
append_line(buf, &len, " float4 screenPos : TEXCOORD1;");
|
||||||
}
|
}
|
||||||
if (cc_features.opt_fog) {
|
if (cc.cm.use_fog) {
|
||||||
append_line(buf, &len, " float4 fog : FOG;");
|
append_line(buf, &len, " float4 fog : FOG;");
|
||||||
num_floats += 4;
|
num_floats += 4;
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < cc_features.num_inputs; i++) {
|
if (cc.cm.light_map) {
|
||||||
len += sprintf(buf + len, " float%d input%d : INPUT%d;\r\n", cc_features.opt_alpha ? 4 : 3, i + 1, i);
|
append_line(buf, &len, " float2 lightmap : LIGHTMAP;");
|
||||||
num_floats += cc_features.opt_alpha ? 4 : 3;
|
num_floats += 2;
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < ccf.num_inputs; i++) {
|
||||||
|
len += sprintf(buf + len, " float%d input%d : INPUT%d;\r\n", cc.cm.use_alpha ? 4 : 3, i + 1, i);
|
||||||
|
num_floats += cc.cm.use_alpha ? 4 : 3;
|
||||||
}
|
}
|
||||||
append_line(buf, &len, "};");
|
append_line(buf, &len, "};");
|
||||||
|
|
||||||
// Textures and samplers
|
// Textures and samplers
|
||||||
|
|
||||||
if (cc_features.used_textures[0]) {
|
if (ccf.used_textures[0]) {
|
||||||
append_line(buf, &len, "Texture2D g_texture0 : register(t0);");
|
append_line(buf, &len, "Texture2D g_texture0 : register(t0);");
|
||||||
append_line(buf, &len, "SamplerState g_sampler0 : register(s0);");
|
append_line(buf, &len, "SamplerState g_sampler0 : register(s0);");
|
||||||
}
|
}
|
||||||
if (cc_features.used_textures[1]) {
|
if (ccf.used_textures[1]) {
|
||||||
append_line(buf, &len, "Texture2D g_texture1 : register(t1);");
|
append_line(buf, &len, "Texture2D g_texture1 : register(t1);");
|
||||||
append_line(buf, &len, "SamplerState g_sampler1 : register(s1);");
|
append_line(buf, &len, "SamplerState g_sampler1 : register(s1);");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constant buffer and random function
|
// Constant buffer and random function
|
||||||
|
|
||||||
if (cc_features.opt_alpha && cc_features.opt_noise) {
|
if (cc.cm.use_alpha && cc.cm.use_noise) {
|
||||||
append_line(buf, &len, "cbuffer PerFrameCB : register(b0) {");
|
append_line(buf, &len, "cbuffer PerFrameCB : register(b0) {");
|
||||||
append_line(buf, &len, " uint noise_frame;");
|
append_line(buf, &len, " uint noise_frame;");
|
||||||
append_line(buf, &len, " float2 noise_scale;");
|
append_line(buf, &len, " float2 noise_scale;");
|
||||||
|
@ -228,7 +192,7 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
// Original author: ArthurCarvalho
|
// Original author: ArthurCarvalho
|
||||||
// Based on GLSL implementation by twinaphex, mupen64plus-libretro project.
|
// Based on GLSL implementation by twinaphex, mupen64plus-libretro project.
|
||||||
|
|
||||||
if (three_point_filtering && (cc_features.used_textures[0] || cc_features.used_textures[1])) {
|
if (three_point_filtering && (ccf.used_textures[0] || ccf.used_textures[1])) {
|
||||||
append_line(buf, &len, "cbuffer PerDrawCB : register(b1) {");
|
append_line(buf, &len, "cbuffer PerDrawCB : register(b1) {");
|
||||||
append_line(buf, &len, " struct {");
|
append_line(buf, &len, " struct {");
|
||||||
append_line(buf, &len, " uint width;");
|
append_line(buf, &len, " uint width;");
|
||||||
|
@ -250,28 +214,34 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
// Vertex shader
|
// Vertex shader
|
||||||
|
|
||||||
append_str(buf, &len, "PSInput VSMain(float4 position : POSITION");
|
append_str(buf, &len, "PSInput VSMain(float4 position : POSITION");
|
||||||
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
|
if (ccf.used_textures[0] || ccf.used_textures[1]) {
|
||||||
append_str(buf, &len, ", float2 uv : TEXCOORD");
|
append_str(buf, &len, ", float2 uv : TEXCOORD");
|
||||||
}
|
}
|
||||||
if (cc_features.opt_fog) {
|
if (cc.cm.use_fog) {
|
||||||
append_str(buf, &len, ", float4 fog : FOG");
|
append_str(buf, &len, ", float4 fog : FOG");
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < cc_features.num_inputs; i++) {
|
if (cc.cm.light_map) {
|
||||||
len += sprintf(buf + len, ", float%d input%d : INPUT%d", cc_features.opt_alpha ? 4 : 3, i + 1, i);
|
append_str(buf, &len, ", float2 lightmap : LIGHTMAP");
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < ccf.num_inputs; i++) {
|
||||||
|
len += sprintf(buf + len, ", float%d input%d : INPUT%d", cc.cm.use_alpha ? 4 : 3, i + 1, i);
|
||||||
}
|
}
|
||||||
append_line(buf, &len, ") {");
|
append_line(buf, &len, ") {");
|
||||||
append_line(buf, &len, " PSInput result;");
|
append_line(buf, &len, " PSInput result;");
|
||||||
append_line(buf, &len, " result.position = position;");
|
append_line(buf, &len, " result.position = position;");
|
||||||
if (cc_features.opt_alpha && cc_features.opt_noise) {
|
if (cc.cm.use_alpha && cc.cm.use_noise) {
|
||||||
append_line(buf, &len, " result.screenPos = position;");
|
append_line(buf, &len, " result.screenPos = position;");
|
||||||
}
|
}
|
||||||
if (cc_features.used_textures[0] || cc_features.used_textures[1]) {
|
if (ccf.used_textures[0] || ccf.used_textures[1]) {
|
||||||
append_line(buf, &len, " result.uv = uv;");
|
append_line(buf, &len, " result.uv = uv;");
|
||||||
}
|
}
|
||||||
if (cc_features.opt_fog) {
|
if (cc.cm.use_fog) {
|
||||||
append_line(buf, &len, " result.fog = fog;");
|
append_line(buf, &len, " result.fog = fog;");
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < cc_features.num_inputs; i++) {
|
if (cc.cm.light_map) {
|
||||||
|
append_line(buf, &len, " result.lightmap = lightmap;");
|
||||||
|
}
|
||||||
|
for (int32_t i = 0; i < ccf.num_inputs; i++) {
|
||||||
len += sprintf(buf + len, " result.input%d = input%d;\r\n", i + 1, i + 1);
|
len += sprintf(buf + len, " result.input%d = input%d;\r\n", i + 1, i + 1);
|
||||||
}
|
}
|
||||||
append_line(buf, &len, " return result;");
|
append_line(buf, &len, " return result;");
|
||||||
|
@ -282,7 +252,7 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
append_line(buf, &len, "[RootSignature(RS)]");
|
append_line(buf, &len, "[RootSignature(RS)]");
|
||||||
}
|
}
|
||||||
append_line(buf, &len, "float4 PSMain(PSInput input) : SV_TARGET {");
|
append_line(buf, &len, "float4 PSMain(PSInput input) : SV_TARGET {");
|
||||||
if (cc_features.used_textures[0]) {
|
if (ccf.used_textures[0]) {
|
||||||
if (three_point_filtering) {
|
if (three_point_filtering) {
|
||||||
append_line(buf, &len, " float4 texVal0;");
|
append_line(buf, &len, " float4 texVal0;");
|
||||||
append_line(buf, &len, " if (textures[0].linear_filtering)");
|
append_line(buf, &len, " if (textures[0].linear_filtering)");
|
||||||
|
@ -293,48 +263,67 @@ void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_f
|
||||||
append_line(buf, &len, " float4 texVal0 = g_texture0.Sample(g_sampler0, input.uv);");
|
append_line(buf, &len, " float4 texVal0 = g_texture0.Sample(g_sampler0, input.uv);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cc_features.used_textures[1]) {
|
if (ccf.used_textures[1]) {
|
||||||
if (three_point_filtering) {
|
if (cc.cm.light_map) {
|
||||||
append_line(buf, &len, " float4 texVal1;");
|
if (three_point_filtering) {
|
||||||
append_line(buf, &len, " if (textures[1].linear_filtering)");
|
append_line(buf, &len, " float4 texVal1;");
|
||||||
append_line(buf, &len, " texVal1 = tex2D3PointFilter(g_texture1, g_sampler1, input.uv, float2(textures[1].width, textures[1].height));");
|
append_line(buf, &len, " if (textures[1].linear_filtering)");
|
||||||
append_line(buf, &len, " else");
|
append_line(buf, &len, " texVal1 = tex2D3PointFilter(g_texture1, g_sampler1, input.lightmap, float2(textures[1].width, textures[1].height));");
|
||||||
append_line(buf, &len, " texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
|
append_line(buf, &len, " else");
|
||||||
|
append_line(buf, &len, " texVal1 = g_texture1.Sample(g_sampler1, input.lightmap);");
|
||||||
|
} else {
|
||||||
|
append_line(buf, &len, " float4 texVal1 = g_texture1.Sample(g_sampler1, input.lightmap);");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
append_line(buf, &len, " float4 texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
|
if (three_point_filtering) {
|
||||||
|
append_line(buf, &len, " float4 texVal1;");
|
||||||
|
append_line(buf, &len, " if (textures[1].linear_filtering)");
|
||||||
|
append_line(buf, &len, " texVal1 = tex2D3PointFilter(g_texture1, g_sampler1, input.uv, float2(textures[1].width, textures[1].height));");
|
||||||
|
append_line(buf, &len, " else");
|
||||||
|
append_line(buf, &len, " texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
|
||||||
|
} else {
|
||||||
|
append_line(buf, &len, " float4 texVal1 = g_texture1.Sample(g_sampler1, input.uv);");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
append_str(buf, &len, cc_features.opt_alpha ? " float4 texel = " : " float3 texel = ");
|
append_str(buf, &len, cc.cm.use_alpha ? " float4 texel = " : " float3 texel = ");
|
||||||
if (!cc_features.color_alpha_same && cc_features.opt_alpha) {
|
for (int i = 0; i < (cc.cm.use_2cycle + 1); i++) {
|
||||||
append_str(buf, &len, "float4(");
|
uint8_t* cmd = &cc.shader_commands[i * 8];
|
||||||
append_formula(buf, &len, cc_features.c, cc_features.do_single[0], cc_features.do_multiply[0], cc_features.do_mix[0], false, false, true);
|
if (!ccf.color_alpha_same[i] && cc.cm.use_alpha) {
|
||||||
append_str(buf, &len, ", ");
|
append_str(buf, &len, "float4(");
|
||||||
append_formula(buf, &len, cc_features.c, cc_features.do_single[1], cc_features.do_multiply[1], cc_features.do_mix[1], true, true, true);
|
append_formula(buf, &len, cmd, ccf.do_single[i*2+0], ccf.do_multiply[i*2+0], ccf.do_mix[i*2+0], false, false, true);
|
||||||
append_str(buf, &len, ")");
|
append_str(buf, &len, ", ");
|
||||||
} else {
|
append_formula(buf, &len, cmd, ccf.do_single[i*2+1], ccf.do_multiply[i*2+1], ccf.do_mix[i*2+1], true, true, true);
|
||||||
append_formula(buf, &len, cc_features.c, cc_features.do_single[0], cc_features.do_multiply[0], cc_features.do_mix[0], cc_features.opt_alpha, false, cc_features.opt_alpha);
|
append_str(buf, &len, ")");
|
||||||
}
|
} else {
|
||||||
append_line(buf, &len, ";");
|
append_formula(buf, &len, cmd, ccf.do_single[i*2+0], ccf.do_multiply[i*2+0], ccf.do_mix[i*2+0], cc.cm.use_alpha, false, cc.cm.use_alpha);
|
||||||
|
}
|
||||||
|
append_line(buf, &len, ";");
|
||||||
|
|
||||||
if (cc_features.opt_texture_edge && cc_features.opt_alpha) {
|
if (i == 0 && cc.cm.use_2cycle) {
|
||||||
|
append_str(buf, &len, "texel = ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cc.cm.texture_edge && cc.cm.use_alpha) {
|
||||||
append_line(buf, &len, " if (texel.a > 0.3) texel.a = 1.0; else discard;");
|
append_line(buf, &len, " if (texel.a > 0.3) texel.a = 1.0; else discard;");
|
||||||
}
|
}
|
||||||
// TODO discard if alpha is 0?
|
// TODO discard if alpha is 0?
|
||||||
if (cc_features.opt_fog) {
|
if (cc.cm.use_fog) {
|
||||||
if (cc_features.opt_alpha) {
|
if (cc.cm.use_alpha) {
|
||||||
append_line(buf, &len, " texel = float4(lerp(texel.rgb, input.fog.rgb, input.fog.a), texel.a);");
|
append_line(buf, &len, " texel = float4(lerp(texel.rgb, input.fog.rgb, input.fog.a), texel.a);");
|
||||||
} else {
|
} else {
|
||||||
append_line(buf, &len, " texel = lerp(texel, input.fog.rgb, input.fog.a);");
|
append_line(buf, &len, " texel = lerp(texel, input.fog.rgb, input.fog.a);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc_features.opt_alpha && cc_features.opt_noise) {
|
if (cc.cm.use_alpha && cc.cm.use_noise) {
|
||||||
append_line(buf, &len, " float2 coords = (input.screenPos.xy / input.screenPos.w) * noise_scale;");
|
append_line(buf, &len, " float2 coords = (input.screenPos.xy / input.screenPos.w) * noise_scale;");
|
||||||
append_line(buf, &len, " texel.a *= round(random(float3(floor(coords), noise_frame)));");
|
append_line(buf, &len, " texel.a *= round(random(float3(floor(coords), noise_frame)));");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc_features.opt_alpha) {
|
if (cc.cm.use_alpha) {
|
||||||
append_line(buf, &len, " return texel;");
|
append_line(buf, &len, " return texel;");
|
||||||
} else {
|
} else {
|
||||||
append_line(buf, &len, " return float4(texel, 1.0);");
|
append_line(buf, &len, " return float4(texel, 1.0);");
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include "gfx_cc.h"
|
#include "gfx_cc.h"
|
||||||
|
|
||||||
void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_floats, const CCFeatures& cc_features, bool include_root_signature, bool three_point_filtering);
|
void gfx_direct3d_common_build_shader(char buf[4096], size_t& len, size_t& num_floats, struct ColorCombiner& cc, const CCFeatures& cc_features, bool include_root_signature, bool three_point_filtering);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -212,13 +212,18 @@ static void update_screen_settings(void) {
|
||||||
if (configWindow.fullscreen != dxgi.is_full_screen)
|
if (configWindow.fullscreen != dxgi.is_full_screen)
|
||||||
toggle_borderless_window_full_screen(configWindow.fullscreen);
|
toggle_borderless_window_full_screen(configWindow.fullscreen);
|
||||||
if (!dxgi.is_full_screen) {
|
if (!dxgi.is_full_screen) {
|
||||||
|
/*
|
||||||
|
// this code is buggy, and I just simply don't care enough about direct x to fix it
|
||||||
|
// when this is enabled, the window will be placed in the wrong spot... often off screen
|
||||||
const int screen_width = GetSystemMetrics(SM_CXSCREEN);
|
const int screen_width = GetSystemMetrics(SM_CXSCREEN);
|
||||||
const int screen_height = GetSystemMetrics(SM_CYSCREEN);
|
const int screen_height = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
|
||||||
const int xpos = (configWindow.x == WAPI_WIN_CENTERPOS) ? (screen_width - configWindow.w) * 0.5 : configWindow.x;
|
const int xpos = (configWindow.x == WAPI_WIN_CENTERPOS) ? (screen_width - configWindow.w) * 0.5 : configWindow.x;
|
||||||
const int ypos = (configWindow.y == WAPI_WIN_CENTERPOS) ? (screen_height - configWindow.h) * 0.5 : configWindow.y;
|
const int ypos = (configWindow.y == WAPI_WIN_CENTERPOS) ? (screen_height - configWindow.h) * 0.5 : configWindow.y;
|
||||||
RECT wr = { xpos, ypos, xpos + (int)configWindow.w, ypos + (int)configWindow.h };
|
RECT wr = { xpos, ypos, xpos + (int)configWindow.w, ypos + (int)configWindow.h };
|
||||||
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
|
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
|
||||||
SetWindowPos(dxgi.h_wnd, NULL, wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top, SWP_NOACTIVATE | SWP_NOZORDER);
|
SetWindowPos(dxgi.h_wnd, NULL, wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top, SWP_NOACTIVATE | SWP_NOZORDER);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,13 +147,13 @@ static const char *shader_item_to_str(uint32_t item, bool with_alpha, bool only_
|
||||||
case SHADER_INPUT_4:
|
case SHADER_INPUT_4:
|
||||||
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput4.rgb";
|
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput4.rgb";
|
||||||
case SHADER_INPUT_5:
|
case SHADER_INPUT_5:
|
||||||
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput5.rgb";
|
return with_alpha || !inputs_have_alpha ? "vInput5" : "vInput5.rgb";
|
||||||
case SHADER_INPUT_6:
|
case SHADER_INPUT_6:
|
||||||
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput6.rgb";
|
return with_alpha || !inputs_have_alpha ? "vInput6" : "vInput6.rgb";
|
||||||
case SHADER_INPUT_7:
|
case SHADER_INPUT_7:
|
||||||
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput7.rgb";
|
return with_alpha || !inputs_have_alpha ? "vInput7" : "vInput7.rgb";
|
||||||
case SHADER_INPUT_8:
|
case SHADER_INPUT_8:
|
||||||
return with_alpha || !inputs_have_alpha ? "vInput4" : "vInput8.rgb";
|
return with_alpha || !inputs_have_alpha ? "vInput8" : "vInput8.rgb";
|
||||||
case SHADER_TEXEL0:
|
case SHADER_TEXEL0:
|
||||||
return with_alpha ? "texVal0" : "texVal0.rgb";
|
return with_alpha ? "texVal0" : "texVal0.rgb";
|
||||||
case SHADER_TEXEL0A:
|
case SHADER_TEXEL0A:
|
||||||
|
|
|
@ -273,7 +273,7 @@ static struct ShaderProgram *gfx_lookup_or_create_shader_program(struct ColorCom
|
||||||
|
|
||||||
static void gfx_generate_cc(struct ColorCombiner *cc) {
|
static void gfx_generate_cc(struct ColorCombiner *cc) {
|
||||||
u8 next_input_number = 0;
|
u8 next_input_number = 0;
|
||||||
u8 input_number[CC_MAX] = { 0 };
|
u8 input_number[CC_ENUM_MAX] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < SHADER_CMD_LENGTH; i++) {
|
for (int i = 0; i < SHADER_CMD_LENGTH; i++) {
|
||||||
u8 cm_cmd = cc->cm.all_values[i];
|
u8 cm_cmd = cc->cm.all_values[i];
|
||||||
|
|
Loading…
Reference in a new issue