mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00: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(); | ||||
|     SyncProcTexBias(); | ||||
|     SyncShadowBias(); | ||||
|     SyncShadowTextureBias(); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -903,6 +904,11 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
|         SyncBlendColor(); | ||||
|         break; | ||||
| 
 | ||||
|     // Shadow texture
 | ||||
|     case PICA_REG_INDEX(texturing.shadow): | ||||
|         SyncShadowTextureBias(); | ||||
|         break; | ||||
| 
 | ||||
|     // Fog state
 | ||||
|     case PICA_REG_INDEX(texturing.fog_color): | ||||
|         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() { | ||||
|     constexpr std::size_t max_size = sizeof(GLvec2) * 256 * Pica::LightingRegs::NumLightingSampler + | ||||
|                                      sizeof(GLvec2) * 128 +     // fog
 | ||||
|  |  | |||
|  | @ -214,6 +214,9 @@ private: | |||
|     /// Syncs the shadow rendering bias to match the PICA register
 | ||||
|     void SyncShadowBias(); | ||||
| 
 | ||||
|     /// Syncs the shadow texture bias to match the PICA register
 | ||||
|     void SyncShadowTextureBias(); | ||||
| 
 | ||||
|     /// Syncs and uploads the lighting, fog and proctex LUTs
 | ||||
|     void SyncAndUploadLUTs(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -63,6 +63,7 @@ layout (std140) uniform shader_data { | |||
|     int proctex_lut_offset; | ||||
|     int proctex_diff_lut_offset; | ||||
|     float proctex_bias; | ||||
|     int shadow_texture_bias; | ||||
|     ivec4 lighting_lut_offset[NUM_LIGHTING_SAMPLERS / 4]; | ||||
|     vec3 fog_color; | ||||
|     vec2 proctex_noise_f; | ||||
|  | @ -240,7 +241,6 @@ PicaFSConfig PicaFSConfig::BuildFromRegs(const Pica::Regs& regs) { | |||
|                              FramebufferRegs::FragmentOperationMode::Shadow; | ||||
| 
 | ||||
|     state.shadow_texture_orthographic = regs.texturing.shadow.orthographic != 0; | ||||
|     state.shadow_texture_bias = regs.texturing.shadow.bias << 1; | ||||
| 
 | ||||
|     return res; | ||||
| } | ||||
|  | @ -1358,8 +1358,7 @@ vec4 shadowTexture(vec2 uv, float w) { | |||
|     if (!config.state.shadow_texture_orthographic) { | ||||
|         out += "uv /= w;"; | ||||
|     } | ||||
|     out += "uint z = uint(max(0, int(min(abs(w), 1.0) * 0xFFFFFF) - " + | ||||
|            std::to_string(state.shadow_texture_bias) + "));"; | ||||
|     out += "uint z = uint(max(0, int(min(abs(w), 1.0) * 0xFFFFFF) - shadow_texture_bias));"; | ||||
|     out += R"( | ||||
|     vec2 coord = vec2(imageSize(shadow_texture_px)) * uv - vec2(0.5); | ||||
|     vec2 coord_floor = floor(coord); | ||||
|  | @ -1391,8 +1390,7 @@ vec4 shadowTextureCube(vec2 uv, float w) { | |||
|         if (c.z > 0.0) uv.x = -uv.x; | ||||
|     } | ||||
| )"; | ||||
|     out += "uint z = uint(max(0, int(min(w, 1.0) * 0xFFFFFF) - " + | ||||
|            std::to_string(state.shadow_texture_bias) + "));"; | ||||
|     out += "uint z = uint(max(0, int(min(w, 1.0) * 0xFFFFFF) - shadow_texture_bias));"; | ||||
|     out += R"( | ||||
|     vec2 coord = vec2(size) * (uv / w * vec2(0.5) + vec2(0.5)) - vec2(0.5); | ||||
|     vec2 coord_floor = floor(coord); | ||||
|  |  | |||
|  | @ -118,7 +118,6 @@ struct PicaFSConfigState { | |||
| 
 | ||||
|     bool shadow_rendering; | ||||
|     bool shadow_texture_orthographic; | ||||
|     u32 shadow_texture_bias; | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|  |  | |||
|  | @ -49,6 +49,7 @@ struct UniformData { | |||
|     GLint proctex_lut_offset; | ||||
|     GLint proctex_diff_lut_offset; | ||||
|     GLfloat proctex_bias; | ||||
|     GLint shadow_texture_bias; | ||||
|     alignas(16) GLivec4 lighting_lut_offset[Pica::LightingRegs::NumLightingSampler / 4]; | ||||
|     alignas(16) GLvec3 fog_color; | ||||
|     alignas(8) GLvec2 proctex_noise_f; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue