mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-30 11:02:39 -06:00
gl_rasterizer: change shadow_texture_bias from shader config var to shader uniform
Games can frequently change this register. Using it as shader config var would generates a lot of shaders
This commit is contained in:
parent
bad2e084e3
commit
b5f2318ae7
5 changed files with 21 additions and 6 deletions
|
@ -203,6 +203,7 @@ void RasterizerOpenGL::SyncEntireState() {
|
||||||
SyncProcTexNoise();
|
SyncProcTexNoise();
|
||||||
SyncProcTexBias();
|
SyncProcTexBias();
|
||||||
SyncShadowBias();
|
SyncShadowBias();
|
||||||
|
SyncShadowTextureBias();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -903,6 +904,11 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
|
||||||
SyncBlendColor();
|
SyncBlendColor();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Shadow texture
|
||||||
|
case PICA_REG_INDEX(texturing.shadow):
|
||||||
|
SyncShadowTextureBias();
|
||||||
|
break;
|
||||||
|
|
||||||
// Fog state
|
// Fog state
|
||||||
case PICA_REG_INDEX(texturing.fog_color):
|
case PICA_REG_INDEX(texturing.fog_color):
|
||||||
SyncFogColor();
|
SyncFogColor();
|
||||||
|
@ -1906,6 +1912,14 @@ void RasterizerOpenGL::SyncShadowBias() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RasterizerOpenGL::SyncShadowTextureBias() {
|
||||||
|
GLint bias = Pica::g_state.regs.texturing.shadow.bias << 1;
|
||||||
|
if (bias != uniform_block_data.data.shadow_texture_bias) {
|
||||||
|
uniform_block_data.data.shadow_texture_bias = bias;
|
||||||
|
uniform_block_data.dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncAndUploadLUTs() {
|
void RasterizerOpenGL::SyncAndUploadLUTs() {
|
||||||
constexpr std::size_t max_size = sizeof(GLvec2) * 256 * Pica::LightingRegs::NumLightingSampler +
|
constexpr std::size_t max_size = sizeof(GLvec2) * 256 * Pica::LightingRegs::NumLightingSampler +
|
||||||
sizeof(GLvec2) * 128 + // fog
|
sizeof(GLvec2) * 128 + // fog
|
||||||
|
|
|
@ -214,6 +214,9 @@ private:
|
||||||
/// Syncs the shadow rendering bias to match the PICA register
|
/// Syncs the shadow rendering bias to match the PICA register
|
||||||
void SyncShadowBias();
|
void SyncShadowBias();
|
||||||
|
|
||||||
|
/// Syncs the shadow texture bias to match the PICA register
|
||||||
|
void SyncShadowTextureBias();
|
||||||
|
|
||||||
/// Syncs and uploads the lighting, fog and proctex LUTs
|
/// Syncs and uploads the lighting, fog and proctex LUTs
|
||||||
void SyncAndUploadLUTs();
|
void SyncAndUploadLUTs();
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ layout (std140) uniform shader_data {
|
||||||
int proctex_lut_offset;
|
int proctex_lut_offset;
|
||||||
int proctex_diff_lut_offset;
|
int proctex_diff_lut_offset;
|
||||||
float proctex_bias;
|
float proctex_bias;
|
||||||
|
int shadow_texture_bias;
|
||||||
ivec4 lighting_lut_offset[NUM_LIGHTING_SAMPLERS / 4];
|
ivec4 lighting_lut_offset[NUM_LIGHTING_SAMPLERS / 4];
|
||||||
vec3 fog_color;
|
vec3 fog_color;
|
||||||
vec2 proctex_noise_f;
|
vec2 proctex_noise_f;
|
||||||
|
@ -240,7 +241,6 @@ PicaFSConfig PicaFSConfig::BuildFromRegs(const Pica::Regs& regs) {
|
||||||
FramebufferRegs::FragmentOperationMode::Shadow;
|
FramebufferRegs::FragmentOperationMode::Shadow;
|
||||||
|
|
||||||
state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0;
|
state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0;
|
||||||
state.shadow_texture_bias = regs.texturing.shadow.bias << 1;
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1358,8 +1358,7 @@ vec4 shadowTexture(vec2 uv, float w) {
|
||||||
if (!config.state.shadow_texture_orthographic) {
|
if (!config.state.shadow_texture_orthographic) {
|
||||||
out += "uv /= w;";
|
out += "uv /= w;";
|
||||||
}
|
}
|
||||||
out += "uint z = uint(max(0, int(min(abs(w), 1.0) * 0xFFFFFF) - " +
|
out += "uint z = uint(max(0, int(min(abs(w), 1.0) * 0xFFFFFF) - shadow_texture_bias));";
|
||||||
std::to_string(state.shadow_texture_bias) + "));";
|
|
||||||
out += R"(
|
out += R"(
|
||||||
vec2 coord = vec2(imageSize(shadow_texture_px)) * uv - vec2(0.5);
|
vec2 coord = vec2(imageSize(shadow_texture_px)) * uv - vec2(0.5);
|
||||||
vec2 coord_floor = floor(coord);
|
vec2 coord_floor = floor(coord);
|
||||||
|
@ -1391,8 +1390,7 @@ vec4 shadowTextureCube(vec2 uv, float w) {
|
||||||
if (c.z > 0.0) uv.x = -uv.x;
|
if (c.z > 0.0) uv.x = -uv.x;
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
out += "uint z = uint(max(0, int(min(w, 1.0) * 0xFFFFFF) - " +
|
out += "uint z = uint(max(0, int(min(w, 1.0) * 0xFFFFFF) - shadow_texture_bias));";
|
||||||
std::to_string(state.shadow_texture_bias) + "));";
|
|
||||||
out += R"(
|
out += R"(
|
||||||
vec2 coord = vec2(size) * (uv / w * vec2(0.5) + vec2(0.5)) - vec2(0.5);
|
vec2 coord = vec2(size) * (uv / w * vec2(0.5) + vec2(0.5)) - vec2(0.5);
|
||||||
vec2 coord_floor = floor(coord);
|
vec2 coord_floor = floor(coord);
|
||||||
|
|
|
@ -118,7 +118,6 @@ struct PicaFSConfigState {
|
||||||
|
|
||||||
bool shadow_rendering;
|
bool shadow_rendering;
|
||||||
bool shadow_texture_orthographic;
|
bool shadow_texture_orthographic;
|
||||||
u32 shadow_texture_bias;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,6 +49,7 @@ struct UniformData {
|
||||||
GLint proctex_lut_offset;
|
GLint proctex_lut_offset;
|
||||||
GLint proctex_diff_lut_offset;
|
GLint proctex_diff_lut_offset;
|
||||||
GLfloat proctex_bias;
|
GLfloat proctex_bias;
|
||||||
|
GLint shadow_texture_bias;
|
||||||
alignas(16) GLivec4 lighting_lut_offset[Pica::LightingRegs::NumLightingSampler / 4];
|
alignas(16) GLivec4 lighting_lut_offset[Pica::LightingRegs::NumLightingSampler / 4];
|
||||||
alignas(16) GLvec3 fog_color;
|
alignas(16) GLvec3 fog_color;
|
||||||
alignas(8) GLvec2 proctex_noise_f;
|
alignas(8) GLvec2 proctex_noise_f;
|
||||||
|
|
Loading…
Reference in a new issue