mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 06:05:40 +12:00
Shadergen: Move fog colour to uniform
This commit is contained in:
parent
33cb3d9c9f
commit
32ddc28789
4 changed files with 7 additions and 12 deletions
|
@ -35,9 +35,6 @@ namespace PICA {
|
|||
|
||||
BitField<0, 3, FogMode> mode;
|
||||
BitField<3, 1, u32> flipDepth;
|
||||
BitField<8, 8, u32> fogColorR;
|
||||
BitField<16, 8, u32> fogColorG;
|
||||
BitField<24, 8, u32> fogColorB;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -238,9 +235,6 @@ namespace PICA {
|
|||
|
||||
if (fogConfig.mode == FogMode::Fog) {
|
||||
fogConfig.flipDepth = Helpers::getBit<16>(regs[InternalRegs::TexEnvUpdateBuffer]);
|
||||
fogConfig.fogColorR = Helpers::getBits<0, 8>(regs[InternalRegs::FogColor]);
|
||||
fogConfig.fogColorG = Helpers::getBits<8, 8>(regs[InternalRegs::FogColor]);
|
||||
fogConfig.fogColorB = Helpers::getBits<16, 8>(regs[InternalRegs::FogColor]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,8 +34,10 @@ namespace PICA {
|
|||
alignas(16) vec4 tevBufferColor;
|
||||
alignas(16) vec4 clipCoords;
|
||||
|
||||
// Note: We upload this as a u32 and decode on GPU
|
||||
// Note: We upload these as a u32 and decode on GPU.
|
||||
// Particularly the fog colour since fog is really uncommon and it doesn't matter if we decode on GPU.
|
||||
u32 globalAmbientLight;
|
||||
u32 fogColor;
|
||||
// NOTE: THIS MUST BE LAST so that if lighting is disabled we can potentially omit uploading it
|
||||
LightUniform lightUniforms[8];
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@ static constexpr const char* uniformDefinition = R"(
|
|||
|
||||
// Note: We upload this as a u32 and decode on GPU
|
||||
uint globalAmbientLight;
|
||||
uint inFogColor;
|
||||
LightSource lightSources[8];
|
||||
};
|
||||
)";
|
||||
|
@ -656,10 +657,6 @@ void FragmentGenerator::compileFog(std::string& shader, const PICA::FragmentConf
|
|||
return;
|
||||
}
|
||||
|
||||
float r = config.fogConfig.fogColorR / 255.0f;
|
||||
float g = config.fogConfig.fogColorG / 255.0f;
|
||||
float b = config.fogConfig.fogColorB / 255.0f;
|
||||
|
||||
if (config.fogConfig.flipDepth) {
|
||||
shader += "float fog_index = (1.0 - depth) * 128.0;\n";
|
||||
} else {
|
||||
|
@ -668,7 +665,7 @@ void FragmentGenerator::compileFog(std::string& shader, const PICA::FragmentConf
|
|||
|
||||
shader += "float clamped_index = clamp(floor(fog_index), 0.0, 127.0);";
|
||||
shader += "float delta = fog_index - clamped_index;";
|
||||
shader += "vec3 fog_color = vec3(" + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b) + ");";
|
||||
shader += "vec3 fog_color = (1.0 / 255.0) * vec3(float(inFogColor & 0xffu), float((inFogColor >> 8u) & 0xffu), float((inFogColor >> 16u) & 0xffu));";
|
||||
shader += "vec2 value = texelFetch(u_tex_luts, ivec2(int(clamped_index), 24), 0).rg;"; // fog LUT is past the light LUTs
|
||||
shader += "float fog_factor = clamp(value.r + value.g * delta, 0.0, 1.0);";
|
||||
shader += "combinerOutput.rgb = mix(fog_color, combinerOutput.rgb, fog_factor);";
|
||||
|
|
|
@ -903,6 +903,8 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
|||
vec[3] = float((color >> 24) & 0xFF) / 255.0f;
|
||||
}
|
||||
|
||||
uniforms.fogColor = regs[PICA::InternalRegs::FogColor];
|
||||
|
||||
// Append lighting uniforms
|
||||
if (fsConfig.lighting.enable) {
|
||||
uniforms.globalAmbientLight = regs[InternalRegs::LightGlobalAmbient];
|
||||
|
|
Loading…
Add table
Reference in a new issue