2015-10-06 04:33:47 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "video_core/pica.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
|
|
|
|
2015-10-07 00:01:53 +02:00
|
|
|
using Pica::Regs;
|
|
|
|
using TevStageConfig = Regs::TevStageConfig;
|
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
namespace GLShader {
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Detects if a TEV stage is configured to be skipped (to avoid generating unnecessary code)
|
2015-10-07 00:01:53 +02:00
|
|
|
static bool IsPassThroughTevStage(const TevStageConfig& stage) {
|
|
|
|
return (stage.color_op == TevStageConfig::Operation::Replace &&
|
|
|
|
stage.alpha_op == TevStageConfig::Operation::Replace &&
|
|
|
|
stage.color_source1 == TevStageConfig::Source::Previous &&
|
|
|
|
stage.alpha_source1 == TevStageConfig::Source::Previous &&
|
|
|
|
stage.color_modifier1 == TevStageConfig::ColorModifier::SourceColor &&
|
|
|
|
stage.alpha_modifier1 == TevStageConfig::AlphaModifier::SourceAlpha &&
|
|
|
|
stage.GetColorMultiplier() == 1 &&
|
|
|
|
stage.GetAlphaMultiplier() == 1);
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the specified TEV stage source component(s)
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendSource(std::string& out, TevStageConfig::Source source,
|
|
|
|
const std::string& index_name) {
|
|
|
|
using Source = TevStageConfig::Source;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (source) {
|
|
|
|
case Source::PrimaryColor:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "primary_color";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::PrimaryFragmentColor:
|
|
|
|
// HACK: Until we implement fragment lighting, use primary_color
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "primary_color";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::SecondaryFragmentColor:
|
|
|
|
// HACK: Until we implement fragment lighting, use zero
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "vec4(0.0)";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::Texture0:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "texture(tex[0], texcoord[0])";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::Texture1:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "texture(tex[1], texcoord[1])";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
2015-10-13 04:23:26 +02:00
|
|
|
case Source::Texture2:
|
|
|
|
out += "texture(tex[2], texcoord[2])";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::PreviousBuffer:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "combiner_buffer";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::Constant:
|
2015-10-13 04:23:26 +02:00
|
|
|
((out += "const_color[") += index_name) += ']';
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Source::Previous:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "last_tex_env_out";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec4(0.0)";
|
2015-10-06 04:33:47 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown source op %u", source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the color components to use for the specified TEV stage color modifier
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendColorModifier(std::string& out, TevStageConfig::ColorModifier modifier,
|
|
|
|
TevStageConfig::Source source, const std::string& index_name) {
|
|
|
|
using ColorModifier = TevStageConfig::ColorModifier;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (modifier) {
|
|
|
|
case ColorModifier::SourceColor:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".rgb";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::OneMinusSourceColor:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(1.0) - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".rgb";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::SourceAlpha:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".aaa";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::OneMinusSourceAlpha:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(1.0) - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".aaa";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::SourceRed:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".rrr";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::OneMinusSourceRed:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(1.0) - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".rrr";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::SourceGreen:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".ggg";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::OneMinusSourceGreen:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(1.0) - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".ggg";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::SourceBlue:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".bbb";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case ColorModifier::OneMinusSourceBlue:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(1.0) - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".bbb";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(0.0)";
|
2015-10-06 04:33:47 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown color modifier op %u", modifier);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the alpha component to use for the specified TEV stage alpha modifier
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendAlphaModifier(std::string& out, TevStageConfig::AlphaModifier modifier,
|
|
|
|
TevStageConfig::Source source, const std::string& index_name) {
|
|
|
|
using AlphaModifier = TevStageConfig::AlphaModifier;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (modifier) {
|
|
|
|
case AlphaModifier::SourceAlpha:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".a";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::OneMinusSourceAlpha:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "1.0 - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".a";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::SourceRed:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".r";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::OneMinusSourceRed:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "1.0 - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".r";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::SourceGreen:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".g";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::OneMinusSourceGreen:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "1.0 - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".g";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::SourceBlue:
|
2015-10-07 00:01:53 +02:00
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".b";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case AlphaModifier::OneMinusSourceBlue:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "1.0 - ";
|
|
|
|
AppendSource(out, source, index_name);
|
|
|
|
out += ".b";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-08 03:02:50 +02:00
|
|
|
out += "0.0";
|
2015-10-06 04:33:47 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown alpha modifier op %u", modifier);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the combiner function for the color components for the specified TEV stage operation
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendColorCombiner(std::string& out, TevStageConfig::Operation operation,
|
2015-10-06 04:33:47 +02:00
|
|
|
const std::string& variable_name) {
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "clamp(";
|
2015-10-07 00:01:53 +02:00
|
|
|
using Operation = TevStageConfig::Operation;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (operation) {
|
|
|
|
case Operation::Replace:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Modulate:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Add:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] + " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::AddSigned:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] + " + variable_name + "[1] - vec3(0.5)";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Lerp:
|
2015-10-13 04:23:26 +02:00
|
|
|
// TODO(bunnei): Verify if HW actually does this per-component, otherwise we can just use builtin lerp
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[2] + " + variable_name + "[1] * (vec3(1.0) - " + variable_name + "[2])";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Subtract:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] - " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::MultiplyThenAdd:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[1] + " + variable_name + "[2]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::AddThenMultiply:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "min(" + variable_name + "[0] + " + variable_name + "[1], vec3(1.0)) * " + variable_name + "[2]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "vec3(0.0)";
|
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown color combiner operation: %u", operation);
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-10-21 06:04:02 +02:00
|
|
|
out += ", vec3(0.0), vec3(1.0))"; // Clamp result to 0.0, 1.0
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the combiner function for the alpha component for the specified TEV stage operation
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendAlphaCombiner(std::string& out, TevStageConfig::Operation operation,
|
2015-10-06 04:33:47 +02:00
|
|
|
const std::string& variable_name) {
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "clamp(";
|
2015-10-07 00:01:53 +02:00
|
|
|
using Operation = TevStageConfig::Operation;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (operation) {
|
|
|
|
case Operation::Replace:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Modulate:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Add:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] + " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::AddSigned:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] + " + variable_name + "[1] - 0.5";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Lerp:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[2] + " + variable_name + "[1] * (1.0 - " + variable_name + "[2])";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::Subtract:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] - " + variable_name + "[1]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::MultiplyThenAdd:
|
2015-10-13 04:23:26 +02:00
|
|
|
out += variable_name + "[0] * " + variable_name + "[1] + " + variable_name + "[2]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case Operation::AddThenMultiply:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "min(" + variable_name + "[0] + " + variable_name + "[1], 1.0) * " + variable_name + "[2]";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "0.0";
|
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown alpha combiner operation: %u", operation);
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-10-13 04:23:26 +02:00
|
|
|
out += ", 0.0, 1.0)";
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the if-statement condition used to evaluate alpha testing
|
2015-10-07 00:01:53 +02:00
|
|
|
static void AppendAlphaTestCondition(std::string& out, Regs::CompareFunc func) {
|
|
|
|
using CompareFunc = Regs::CompareFunc;
|
2015-10-06 04:33:47 +02:00
|
|
|
switch (func) {
|
|
|
|
case CompareFunc::Never:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "true";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case CompareFunc::Always:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "false";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
|
|
|
case CompareFunc::Equal:
|
|
|
|
case CompareFunc::NotEqual:
|
|
|
|
case CompareFunc::LessThan:
|
|
|
|
case CompareFunc::LessThanOrEqual:
|
|
|
|
case CompareFunc::GreaterThan:
|
|
|
|
case CompareFunc::GreaterThanOrEqual:
|
2015-10-21 06:04:02 +02:00
|
|
|
{
|
|
|
|
static const char* op[] = { "!=", "==", ">=", ">", "<=", "<", };
|
|
|
|
unsigned index = (unsigned)func - (unsigned)CompareFunc::Equal;
|
|
|
|
out += "int(last_tex_env_out.a * 255.0f) " + std::string(op[index]) + " alphatest_ref";
|
2015-10-06 04:33:47 +02:00
|
|
|
break;
|
2015-10-21 06:04:02 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
default:
|
2015-10-07 00:01:53 +02:00
|
|
|
out += "false";
|
2015-10-06 04:33:47 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unknown alpha test condition %u", func);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:21:28 +02:00
|
|
|
/// Writes the code to emulate the specified TEV stage
|
2015-10-10 04:46:47 +02:00
|
|
|
static void WriteTevStage(std::string& out, const PicaShaderConfig& config, unsigned index) {
|
2015-10-07 00:01:53 +02:00
|
|
|
auto& stage = config.tev_stages[index];
|
|
|
|
if (!IsPassThroughTevStage(stage)) {
|
|
|
|
std::string index_name = std::to_string(index);
|
|
|
|
|
|
|
|
out += "vec3 color_results_" + index_name + "[3] = vec3[3](";
|
|
|
|
AppendColorModifier(out, stage.color_modifier1, stage.color_source1, index_name);
|
|
|
|
out += ", ";
|
|
|
|
AppendColorModifier(out, stage.color_modifier2, stage.color_source2, index_name);
|
|
|
|
out += ", ";
|
|
|
|
AppendColorModifier(out, stage.color_modifier3, stage.color_source3, index_name);
|
|
|
|
out += ");\n";
|
|
|
|
|
|
|
|
out += "vec3 color_output_" + index_name + " = ";
|
|
|
|
AppendColorCombiner(out, stage.color_op, "color_results_" + index_name);
|
|
|
|
out += ";\n";
|
|
|
|
|
|
|
|
out += "float alpha_results_" + index_name + "[3] = float[3](";
|
|
|
|
AppendAlphaModifier(out, stage.alpha_modifier1, stage.alpha_source1, index_name);
|
|
|
|
out += ", ";
|
|
|
|
AppendAlphaModifier(out, stage.alpha_modifier2, stage.alpha_source2, index_name);
|
|
|
|
out += ", ";
|
|
|
|
AppendAlphaModifier(out, stage.alpha_modifier3, stage.alpha_source3, index_name);
|
|
|
|
out += ");\n";
|
|
|
|
|
|
|
|
out += "float alpha_output_" + index_name + " = ";
|
|
|
|
AppendAlphaCombiner(out, stage.alpha_op, "alpha_results_" + index_name);
|
|
|
|
out += ";\n";
|
|
|
|
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "last_tex_env_out = vec4("
|
|
|
|
"clamp(color_output_" + index_name + " * " + std::to_string(stage.GetColorMultiplier()) + ".0, vec3(0.0), vec3(1.0)),"
|
2015-10-08 03:01:28 +02:00
|
|
|
"clamp(alpha_output_" + index_name + " * " + std::to_string(stage.GetAlphaMultiplier()) + ".0, 0.0, 1.0));\n";
|
2015-10-07 00:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (config.TevStageUpdatesCombinerBufferColor(index))
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "combiner_buffer.rgb = last_tex_env_out.rgb;\n";
|
2015-10-07 00:01:53 +02:00
|
|
|
|
|
|
|
if (config.TevStageUpdatesCombinerBufferAlpha(index))
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "combiner_buffer.a = last_tex_env_out.a;\n";
|
2015-10-07 00:01:53 +02:00
|
|
|
}
|
|
|
|
|
2015-10-10 04:46:47 +02:00
|
|
|
std::string GenerateFragmentShader(const PicaShaderConfig& config) {
|
2015-10-07 00:01:53 +02:00
|
|
|
std::string out = R"(
|
2015-11-26 04:33:24 +01:00
|
|
|
#version 330 core
|
2015-10-06 04:33:47 +02:00
|
|
|
#define NUM_TEV_STAGES 6
|
|
|
|
|
2015-10-13 04:23:26 +02:00
|
|
|
in vec4 primary_color;
|
|
|
|
in vec2 texcoord[3];
|
|
|
|
|
2015-10-06 04:33:47 +02:00
|
|
|
out vec4 color;
|
2015-11-10 17:58:53 +01:00
|
|
|
|
|
|
|
layout (std140) uniform shader_data {
|
|
|
|
vec4 const_color[NUM_TEV_STAGES];
|
|
|
|
vec4 tev_combiner_buffer_color;
|
|
|
|
int alphatest_ref;
|
|
|
|
};
|
|
|
|
|
2015-10-10 01:32:38 +02:00
|
|
|
)";
|
2015-10-06 04:33:47 +02:00
|
|
|
|
2015-11-25 11:56:11 +01:00
|
|
|
out += "uniform sampler2D tex[3];\n";
|
2015-10-10 01:32:38 +02:00
|
|
|
out += "void main() {\n";
|
|
|
|
out += "vec4 combiner_buffer = tev_combiner_buffer_color;\n";
|
|
|
|
out += "vec4 last_tex_env_out = vec4(0.0);\n";
|
2015-10-06 04:33:47 +02:00
|
|
|
|
|
|
|
// Do not do any sort of processing if it's obvious we're not going to pass the alpha test
|
2015-10-07 00:01:53 +02:00
|
|
|
if (config.alpha_test_func == Regs::CompareFunc::Never) {
|
2015-10-08 03:11:32 +02:00
|
|
|
out += "discard; }";
|
2015-10-07 00:01:53 +02:00
|
|
|
return out;
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 04:23:26 +02:00
|
|
|
for (size_t index = 0; index < config.tev_stages.size(); ++index)
|
2015-10-07 00:01:53 +02:00
|
|
|
WriteTevStage(out, config, (unsigned)index);
|
2015-10-06 04:33:47 +02:00
|
|
|
|
2015-10-07 00:01:53 +02:00
|
|
|
if (config.alpha_test_func != Regs::CompareFunc::Always) {
|
|
|
|
out += "if (";
|
|
|
|
AppendAlphaTestCondition(out, config.alpha_test_func);
|
2015-10-13 04:23:26 +02:00
|
|
|
out += ") discard;\n";
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 04:23:26 +02:00
|
|
|
out += "color = last_tex_env_out;\n}";
|
2015-10-07 00:01:53 +02:00
|
|
|
|
|
|
|
return out;
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GenerateVertexShader() {
|
2015-11-26 04:33:24 +01:00
|
|
|
std::string out = "#version 330 core\n";
|
2015-10-22 03:50:55 +02:00
|
|
|
out += "layout(location = " + std::to_string((int)ATTRIBUTE_POSITION) + ") in vec4 vert_position;\n";
|
|
|
|
out += "layout(location = " + std::to_string((int)ATTRIBUTE_COLOR) + ") in vec4 vert_color;\n";
|
|
|
|
out += "layout(location = " + std::to_string((int)ATTRIBUTE_TEXCOORD0) + ") in vec2 vert_texcoord0;\n";
|
|
|
|
out += "layout(location = " + std::to_string((int)ATTRIBUTE_TEXCOORD1) + ") in vec2 vert_texcoord1;\n";
|
|
|
|
out += "layout(location = " + std::to_string((int)ATTRIBUTE_TEXCOORD2) + ") in vec2 vert_texcoord2;\n";
|
|
|
|
|
|
|
|
out += R"(
|
2015-10-13 04:23:26 +02:00
|
|
|
out vec4 primary_color;
|
|
|
|
out vec2 texcoord[3];
|
2015-10-06 04:33:47 +02:00
|
|
|
|
|
|
|
void main() {
|
2015-10-13 04:23:26 +02:00
|
|
|
primary_color = vert_color;
|
|
|
|
texcoord[0] = vert_texcoord0;
|
|
|
|
texcoord[1] = vert_texcoord1;
|
|
|
|
texcoord[2] = vert_texcoord2;
|
2015-10-06 04:33:47 +02:00
|
|
|
gl_Position = vec4(vert_position.x, -vert_position.y, -vert_position.z, vert_position.w);
|
|
|
|
}
|
|
|
|
)";
|
2015-10-22 03:50:55 +02:00
|
|
|
|
2015-10-07 00:01:53 +02:00
|
|
|
return out;
|
2015-10-06 04:33:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:01:53 +02:00
|
|
|
} // namespace GLShader
|