mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 20:49:12 +12:00
Merge branch 'master' into shader-decomp
This commit is contained in:
commit
69accdec54
8 changed files with 34 additions and 26 deletions
|
@ -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);";
|
||||
|
@ -726,4 +723,4 @@ void main() {
|
|||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,11 @@ void RendererGL::initGraphicsContextInternal() {
|
|||
gl.useProgram(displayProgram);
|
||||
glUniform1i(OpenGL::uniformLocation(displayProgram, "u_texture"), 0); // Init sampler object
|
||||
|
||||
// Allocate memory for the shadergen fragment uniform UBO
|
||||
glGenBuffers(1, &shadergenFragmentUBO);
|
||||
gl.bindUBO(shadergenFragmentUBO);
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(PICA::FragmentUniforms), nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
vbo.createFixedSize(sizeof(Vertex) * vertexBufferSize, GL_STREAM_DRAW);
|
||||
gl.bindVBO(vbo);
|
||||
vao.create();
|
||||
|
@ -812,17 +817,12 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
|||
glUniform1i(OpenGL::uniformLocation(program, "u_tex2"), 2);
|
||||
glUniform1i(OpenGL::uniformLocation(program, "u_tex_luts"), 3);
|
||||
|
||||
// Allocate memory for the program UBO
|
||||
glGenBuffers(1, &programEntry.uboBinding);
|
||||
gl.bindUBO(programEntry.uboBinding);
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(PICA::FragmentUniforms), nullptr, GL_DYNAMIC_DRAW);
|
||||
|
||||
// Set up the binding for our UBO. Sadly we can't specify it in the shader like normal people,
|
||||
// As it's an OpenGL 4.2 feature that MacOS doesn't support...
|
||||
uint uboIndex = glGetUniformBlockIndex(program.handle(), "FragmentUniforms");
|
||||
glUniformBlockBinding(program.handle(), uboIndex, uboBlockBinding);
|
||||
}
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, uboBlockBinding, programEntry.uboBinding);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, uboBlockBinding, shadergenFragmentUBO);
|
||||
|
||||
// Upload uniform data to our shader's UBO
|
||||
PICA::FragmentUniforms uniforms;
|
||||
|
@ -862,6 +862,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];
|
||||
|
@ -904,7 +906,7 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
|||
}
|
||||
}
|
||||
|
||||
gl.bindUBO(programEntry.uboBinding);
|
||||
gl.bindUBO(shadergenFragmentUBO);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(PICA::FragmentUniforms), &uniforms);
|
||||
|
||||
return program;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue