diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 600119321..d4a99f79f 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -144,12 +144,40 @@ static bool IsPassThroughTevStage(const TevStageConfig& stage) { | |||
| 144 | stage.GetColorMultiplier() == 1 && stage.GetAlphaMultiplier() == 1); | 144 | stage.GetColorMultiplier() == 1 && stage.GetAlphaMultiplier() == 1); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | static std::string TexCoord(const PicaShaderConfig& config, int texture_unit) { | 147 | static std::string SampleTexture(const PicaShaderConfig& config, unsigned texture_unit) { |
| 148 | if (texture_unit == 2 && config.state.texture2_use_coord1) { | 148 | const auto& state = config.state; |
| 149 | return "texcoord[1]"; | 149 | switch (texture_unit) { |
| 150 | case 0: | ||
| 151 | // Only unit 0 respects the texturing type | ||
| 152 | switch (state.texture0_type) { | ||
| 153 | case TexturingRegs::TextureConfig::Texture2D: | ||
| 154 | return "texture(tex[0], texcoord[0])"; | ||
| 155 | case TexturingRegs::TextureConfig::Projection2D: | ||
| 156 | return "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))"; | ||
| 157 | default: | ||
| 158 | LOG_CRITICAL(HW_GPU, "Unhandled texture type %x", | ||
| 159 | static_cast<int>(state.texture0_type)); | ||
| 160 | UNIMPLEMENTED(); | ||
| 161 | return "texture(tex[0], texcoord[0])"; | ||
| 162 | } | ||
| 163 | case 1: | ||
| 164 | return "texture(tex[1], texcoord[1])"; | ||
| 165 | case 2: | ||
| 166 | if (state.texture2_use_coord1) | ||
| 167 | return "texture(tex[2], texcoord[1])"; | ||
| 168 | else | ||
| 169 | return "texture(tex[2], texcoord[2])"; | ||
| 170 | case 3: | ||
| 171 | if (state.proctex.enable) { | ||
| 172 | return "ProcTex()"; | ||
| 173 | } else { | ||
| 174 | LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); | ||
| 175 | return "vec4(0.0)"; | ||
| 176 | } | ||
| 177 | default: | ||
| 178 | UNREACHABLE(); | ||
| 179 | return ""; | ||
| 150 | } | 180 | } |
| 151 | |||
| 152 | return "texcoord[" + std::to_string(texture_unit) + "]"; | ||
| 153 | } | 181 | } |
| 154 | 182 | ||
| 155 | /// Writes the specified TEV stage source component(s) | 183 | /// Writes the specified TEV stage source component(s) |
| @@ -168,35 +196,16 @@ static void AppendSource(std::string& out, const PicaShaderConfig& config, | |||
| 168 | out += "secondary_fragment_color"; | 196 | out += "secondary_fragment_color"; |
| 169 | break; | 197 | break; |
| 170 | case Source::Texture0: | 198 | case Source::Texture0: |
| 171 | // Only unit 0 respects the texturing type (according to 3DBrew) | 199 | out += SampleTexture(config, 0); |
| 172 | switch (state.texture0_type) { | ||
| 173 | case TexturingRegs::TextureConfig::Texture2D: | ||
| 174 | out += "texture(tex[0], texcoord[0])"; | ||
| 175 | break; | ||
| 176 | case TexturingRegs::TextureConfig::Projection2D: | ||
| 177 | out += "textureProj(tex[0], vec3(texcoord[0], texcoord0_w))"; | ||
| 178 | break; | ||
| 179 | default: | ||
| 180 | out += "texture(tex[0], texcoord[0])"; | ||
| 181 | LOG_CRITICAL(HW_GPU, "Unhandled texture type %x", | ||
| 182 | static_cast<int>(state.texture0_type)); | ||
| 183 | UNIMPLEMENTED(); | ||
| 184 | break; | ||
| 185 | } | ||
| 186 | break; | 200 | break; |
| 187 | case Source::Texture1: | 201 | case Source::Texture1: |
| 188 | out += "texture(tex[1], texcoord[1])"; | 202 | out += SampleTexture(config, 1); |
| 189 | break; | 203 | break; |
| 190 | case Source::Texture2: | 204 | case Source::Texture2: |
| 191 | out += "texture(tex[2], " + TexCoord(config, 2) + ")"; | 205 | out += SampleTexture(config, 2); |
| 192 | break; | 206 | break; |
| 193 | case Source::Texture3: | 207 | case Source::Texture3: |
| 194 | if (config.state.proctex.enable) { | 208 | out += SampleTexture(config, 3); |
| 195 | out += "ProcTex()"; | ||
| 196 | } else { | ||
| 197 | LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); | ||
| 198 | out += "vec4(0.0)"; | ||
| 199 | } | ||
| 200 | break; | 209 | break; |
| 201 | case Source::PreviousBuffer: | 210 | case Source::PreviousBuffer: |
| 202 | out += "combiner_buffer"; | 211 | out += "combiner_buffer"; |
| @@ -506,18 +515,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 506 | if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { | 515 | if (lighting.bump_mode == LightingRegs::LightingBumpMode::NormalMap) { |
| 507 | // Bump mapping is enabled using a normal map, read perturbation vector from the selected | 516 | // Bump mapping is enabled using a normal map, read perturbation vector from the selected |
| 508 | // texture | 517 | // texture |
| 509 | if (lighting.bump_selector == 3) { | 518 | out += "vec3 surface_normal = 2.0 * (" + SampleTexture(config, lighting.bump_selector) + |
| 510 | if (config.state.proctex.enable) { | 519 | ").rgb - 1.0;\n"; |
| 511 | out += "vec3 surface_normal = 2.0 * ProcTex().rgb - 1.0;\n"; | ||
| 512 | } else { | ||
| 513 | LOG_ERROR(Render_OpenGL, "Using Texture3 without enabling it"); | ||
| 514 | out += "vec3 surface_normal = vec3(-1.0);\n"; | ||
| 515 | } | ||
| 516 | } else { | ||
| 517 | std::string bump_selector = std::to_string(lighting.bump_selector); | ||
| 518 | out += "vec3 surface_normal = 2.0 * texture(tex[" + bump_selector + "], " + | ||
| 519 | TexCoord(config, lighting.bump_selector) + ").rgb - 1.0;\n"; | ||
| 520 | } | ||
| 521 | 520 | ||
| 522 | // Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher | 521 | // Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher |
| 523 | // precision result | 522 | // precision result |