Merge branch 'master' into nyom

This commit is contained in:
wheremyfoodat 2024-07-22 15:46:27 +03:00
commit a5ea268826
17 changed files with 188 additions and 46 deletions

View file

@ -74,6 +74,9 @@ void GPU::reset() {
lightingLUT.fill(0);
lightingLUTDirty = true;
fogLUT.fill(0);
fogLUTDirty = true;
totalAttribCount = 0;
fixedAttribMask = 0;
fixedAttribIndex = 0;

View file

@ -135,6 +135,21 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
break;
}
case FogLUTData0:
case FogLUTData1:
case FogLUTData2:
case FogLUTData3:
case FogLUTData4:
case FogLUTData5:
case FogLUTData6:
case FogLUTData7: {
const uint32_t index = regs[FogLUTIndex] & 0x7F;
fogLUT[index] = value;
fogLUTDirty = true;
regs[FogLUTIndex] = (index + 1) & 0x7F;
break;
}
case LightingLUTData0:
case LightingLUTData1:
case LightingLUTData2:
@ -314,9 +329,11 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
break;
}
/* TODO: Find out if this actually does anything
case VertexShaderTransferEnd:
if (value != 0) shaderUnit.vs.finalize();
break;
*/
case VertexShaderTransferIndex: shaderUnit.vs.setBufferIndex(value); break;

View file

@ -130,7 +130,7 @@ std::string FragmentGenerator::generate(const FragmentConfig& config) {
uniform sampler2D u_tex0;
uniform sampler2D u_tex1;
uniform sampler2D u_tex2;
uniform sampler2D u_tex_lighting_lut;
uniform sampler2D u_tex_luts;
)";
ret += uniformDefinition;
@ -144,7 +144,7 @@ std::string FragmentGenerator::generate(const FragmentConfig& config) {
}
float lutLookup(uint lut, int index) {
return texelFetch(u_tex_lighting_lut, ivec2(index, int(lut)), 0).r;
return texelFetch(u_tex_luts, ivec2(index, int(lut)), 0).r;
}
vec3 regToColor(uint reg) {
@ -194,6 +194,8 @@ std::string FragmentGenerator::generate(const FragmentConfig& config) {
compileTEV(ret, i, config);
}
compileFog(ret, config);
applyAlphaTest(ret, config);
ret += "fragColor = combinerOutput;\n}"; // End of main function
@ -652,4 +654,27 @@ void FragmentGenerator::compileLUTLookup(std::string& shader, const PICA::Fragme
shader += "lut_lookup_result *= " + std::to_string(scales[scale]) + ";\n";
}
}
}
void FragmentGenerator::compileFog(std::string& shader, const PICA::FragmentConfig& config) {
if (config.fogConfig.mode != FogMode::Fog) {
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 {
shader += "float fog_index = depth * 128.0;\n";
}
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 += "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);";
}

View file

@ -9,7 +9,6 @@ void ShaderUnit::reset() {
void PICAShader::reset() {
loadedShader.fill(0);
bufferedShader.fill(0);
operandDescriptors.fill(0);
boolUniform = 0;