diff options
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 8 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 72 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/pica_to_gl.h | 2 |
3 files changed, 45 insertions, 37 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index bfdc0c8a4..3e6850302 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -192,18 +192,18 @@ union PicaShaderConfig { bool enable; unsigned src_num; - Pica::Regs::LightingBumpMode bump_mode; + Pica::LightingRegs::LightingBumpMode bump_mode; unsigned bump_selector; bool bump_renorm; bool clamp_highlights; - Pica::Regs::LightingConfig config; - Pica::Regs::LightingFresnelSelector fresnel_selector; + Pica::LightingRegs::LightingConfig config; + Pica::LightingRegs::LightingFresnelSelector fresnel_selector; struct { bool enable; bool abs_input; - Pica::Regs::LightingLutInput type; + Pica::LightingRegs::LightingLutInput type; float scale; } lut_d0, lut_d1, lut_fr, lut_rr, lut_rg, lut_rb; } lighting; diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 9c7687f62..0467cccfd 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -14,6 +14,7 @@ using Pica::Regs; using Pica::RasterizerRegs; +using Pica::LightingRegs; using TevStageConfig = Pica::TexturingRegs::TevStageConfig; namespace GLShader { @@ -365,7 +366,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { "vec3 refl_value = vec3(0.0);\n"; // Compute fragment normals - if (lighting.bump_mode == Pica::Regs::LightingBumpMode::NormalMap) { + if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { // Bump mapping is enabled using a normal map, read perturbation vector from the selected // texture std::string bump_selector = std::to_string(lighting.bump_selector); @@ -379,7 +380,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { "(1.0 - (surface_normal.x*surface_normal.x + surface_normal.y*surface_normal.y))"; out += "surface_normal.z = sqrt(max(" + val + ", 0.0));\n"; } - } else if (lighting.bump_mode == Pica::Regs::LightingBumpMode::TangentMap) { + } else if (lighting.bump_mode == LightingRegs::LightingBumpMode::TangentMap) { // Bump mapping is enabled using a tangent map LOG_CRITICAL(HW_GPU, "unimplemented bump mapping mode (tangent mapping)"); UNIMPLEMENTED(); @@ -393,23 +394,24 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { out += "vec3 normal = normalize(quaternion_rotate(normquat, surface_normal));\n"; // Gets the index into the specified lookup table for specular lighting - auto GetLutIndex = [&lighting](unsigned light_num, Regs::LightingLutInput input, bool abs) { + auto GetLutIndex = [&lighting](unsigned light_num, LightingRegs::LightingLutInput input, + bool abs) { const std::string half_angle = "normalize(normalize(view) + light_vector)"; std::string index; switch (input) { - case Regs::LightingLutInput::NH: + case LightingRegs::LightingLutInput::NH: index = "dot(normal, " + half_angle + ")"; break; - case Regs::LightingLutInput::VH: + case LightingRegs::LightingLutInput::VH: index = std::string("dot(normalize(view), " + half_angle + ")"); break; - case Regs::LightingLutInput::NV: + case LightingRegs::LightingLutInput::NV: index = std::string("dot(normal, normalize(view))"); break; - case Regs::LightingLutInput::LN: + case LightingRegs::LightingLutInput::LN: index = std::string("dot(light_vector, normal)"); break; @@ -433,7 +435,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { }; // Gets the lighting lookup table value given the specified sampler and index - auto GetLutValue = [](Regs::LightingSampler sampler, std::string lut_index) { + auto GetLutValue = [](LightingRegs::LightingSampler sampler, std::string lut_index) { return std::string("texture(lut[" + std::to_string((unsigned)sampler / 4) + "], " + lut_index + ")[" + std::to_string((unsigned)sampler & 3) + "]"); }; @@ -462,8 +464,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { light_src + ".position) + " + light_src + ".dist_atten_bias)"; index = "(OFFSET_256 + SCALE_256 * clamp(" + index + ", 0.0, 1.0))"; const unsigned lut_num = - ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); - dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index); + ((unsigned)LightingRegs::LightingSampler::DistanceAttenuation + light_config.num); + dist_atten = GetLutValue((LightingRegs::LightingSampler)lut_num, index); } // If enabled, clamp specular component if lighting result is negative @@ -473,24 +475,24 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { // Specular 0 component std::string d0_lut_value = "1.0"; if (lighting.lut_d0.enable && - Pica::Regs::IsLightingSamplerSupported(lighting.config, - Pica::Regs::LightingSampler::Distribution0)) { + LightingRegs::IsLightingSamplerSupported( + lighting.config, LightingRegs::LightingSampler::Distribution0)) { // Lookup specular "distribution 0" LUT value std::string index = GetLutIndex(light_config.num, lighting.lut_d0.type, lighting.lut_d0.abs_input); d0_lut_value = "(" + std::to_string(lighting.lut_d0.scale) + " * " + - GetLutValue(Regs::LightingSampler::Distribution0, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::Distribution0, index) + ")"; } std::string specular_0 = "(" + d0_lut_value + " * " + light_src + ".specular_0)"; // If enabled, lookup ReflectRed value, otherwise, 1.0 is used if (lighting.lut_rr.enable && - Pica::Regs::IsLightingSamplerSupported(lighting.config, - Pica::Regs::LightingSampler::ReflectRed)) { + LightingRegs::IsLightingSamplerSupported(lighting.config, + LightingRegs::LightingSampler::ReflectRed)) { std::string index = GetLutIndex(light_config.num, lighting.lut_rr.type, lighting.lut_rr.abs_input); std::string value = "(" + std::to_string(lighting.lut_rr.scale) + " * " + - GetLutValue(Regs::LightingSampler::ReflectRed, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::ReflectRed, index) + ")"; out += "refl_value.r = " + value + ";\n"; } else { out += "refl_value.r = 1.0;\n"; @@ -498,12 +500,13 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { // If enabled, lookup ReflectGreen value, otherwise, ReflectRed value is used if (lighting.lut_rg.enable && - Pica::Regs::IsLightingSamplerSupported(lighting.config, - Pica::Regs::LightingSampler::ReflectGreen)) { + LightingRegs::IsLightingSamplerSupported(lighting.config, + LightingRegs::LightingSampler::ReflectGreen)) { std::string index = GetLutIndex(light_config.num, lighting.lut_rg.type, lighting.lut_rg.abs_input); std::string value = "(" + std::to_string(lighting.lut_rg.scale) + " * " + - GetLutValue(Regs::LightingSampler::ReflectGreen, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::ReflectGreen, index) + + ")"; out += "refl_value.g = " + value + ";\n"; } else { out += "refl_value.g = refl_value.r;\n"; @@ -511,12 +514,13 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { // If enabled, lookup ReflectBlue value, otherwise, ReflectRed value is used if (lighting.lut_rb.enable && - Pica::Regs::IsLightingSamplerSupported(lighting.config, - Pica::Regs::LightingSampler::ReflectBlue)) { + LightingRegs::IsLightingSamplerSupported(lighting.config, + LightingRegs::LightingSampler::ReflectBlue)) { std::string index = GetLutIndex(light_config.num, lighting.lut_rb.type, lighting.lut_rb.abs_input); std::string value = "(" + std::to_string(lighting.lut_rb.scale) + " * " + - GetLutValue(Regs::LightingSampler::ReflectBlue, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::ReflectBlue, index) + + ")"; out += "refl_value.b = " + value + ";\n"; } else { out += "refl_value.b = refl_value.r;\n"; @@ -525,35 +529,39 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { // Specular 1 component std::string d1_lut_value = "1.0"; if (lighting.lut_d1.enable && - Pica::Regs::IsLightingSamplerSupported(lighting.config, - Pica::Regs::LightingSampler::Distribution1)) { + LightingRegs::IsLightingSamplerSupported( + lighting.config, LightingRegs::LightingSampler::Distribution1)) { // Lookup specular "distribution 1" LUT value std::string index = GetLutIndex(light_config.num, lighting.lut_d1.type, lighting.lut_d1.abs_input); d1_lut_value = "(" + std::to_string(lighting.lut_d1.scale) + " * " + - GetLutValue(Regs::LightingSampler::Distribution1, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::Distribution1, index) + ")"; } std::string specular_1 = "(" + d1_lut_value + " * refl_value * " + light_src + ".specular_1)"; // Fresnel - if (lighting.lut_fr.enable && Pica::Regs::IsLightingSamplerSupported( - lighting.config, Pica::Regs::LightingSampler::Fresnel)) { + if (lighting.lut_fr.enable && + LightingRegs::IsLightingSamplerSupported(lighting.config, + LightingRegs::LightingSampler::Fresnel)) { // Lookup fresnel LUT value std::string index = GetLutIndex(light_config.num, lighting.lut_fr.type, lighting.lut_fr.abs_input); std::string value = "(" + std::to_string(lighting.lut_fr.scale) + " * " + - GetLutValue(Regs::LightingSampler::Fresnel, index) + ")"; + GetLutValue(LightingRegs::LightingSampler::Fresnel, index) + ")"; // Enabled for difffuse lighting alpha component - if (lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::PrimaryAlpha || - lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::Both) + if (lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha || + lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { out += "diffuse_sum.a *= " + value + ";\n"; + } // Enabled for the specular lighting alpha component - if (lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::SecondaryAlpha || - lighting.fresnel_selector == Pica::Regs::LightingFresnelSelector::Both) + if (lighting.fresnel_selector == + LightingRegs::LightingFresnelSelector::SecondaryAlpha || + lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) { out += "specular_sum.a *= " + value + ";\n"; + } } // Compute primary fragment color (diffuse lighting) function diff --git a/src/video_core/renderer_opengl/pica_to_gl.h b/src/video_core/renderer_opengl/pica_to_gl.h index c1bf3dc24..97c044918 100644 --- a/src/video_core/renderer_opengl/pica_to_gl.h +++ b/src/video_core/renderer_opengl/pica_to_gl.h @@ -210,7 +210,7 @@ inline GLvec4 ColorRGBA8(const u32 color) { }}; } -inline std::array<GLfloat, 3> LightColor(const Pica::Regs::LightColor& color) { +inline std::array<GLfloat, 3> LightColor(const Pica::LightingRegs::LightColor& color) { return {{ color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, }}; |