Merge pull request #4619 from wwylele/shadow-explosion

gl_rasterizer: change shadow_texture_bias from shader config to shader uniform
This commit is contained in:
Weiyi Wang 2019-02-08 18:38:40 -05:00 committed by GitHub
commit bf1dbb47dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 6 deletions

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -118,7 +118,6 @@ struct PicaFSConfigState {
bool shadow_rendering; bool shadow_rendering;
bool shadow_texture_orthographic; bool shadow_texture_orthographic;
u32 shadow_texture_bias;
}; };
/** /**

View File

@ -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;