mirror of
https://github.com/hyprwm/Hyprland.git
synced 2026-02-04 17:15:39 +00:00
renderer: shader code refactor (#12926)
* shader: begin the shader refactor
make SShader a class and rename it to CShader, move createprogram,
compileshader, logshadererror to CShader.
* shader: move uniform creation to CShader
move uniform creation to CShader, reduces tons of duplicated effort,
however forcing uniform names to be same in all shaders.
* shader: move to array based frag handling
use an array with an enum so it gets easier dealing with multiple
shaders, move creating program to a for loop and array, reduces line of
code a lot.
* shader: use shared ptr for frags
with smart pointers we can now rename useProgram to useShader and return
the shader directly, means only place we have to decide the shader frag
is when calling useShader. easier for future shader splitting to reduce
branching.
* shader: move unneded public members to private
move structs and uniforms to private add a get/set for initialtime
and add a getUniformLocation to make the code tell what its doing,
instead of direct array getting when all we wanted to get was its value,
also limits the setting of uniformLocations to the createProgram as it should
be.
* shader: fix style nits
set first enum member to 0 , remove extra {}
* shader: dont show a failed notif on success
the logic got inverted in the refactor here.
* shader: split CM shader to rgba/rgbx variants
split shader to rgba/rgbx variants, use bool, and reduce branching.
* shader: split up blurprepare CM and non CM
split up blurprepare, remove skipcm, move gain to gain.glsl.
remove ternary operator and reduce branching by using step() and mix()
use vec3 for gain, make brightness a cheap mulitplication with max.
* shader: split up border to CM/noncm variants
splitup border shader to CM/noncm variant, move common used things to
border.glsl , there is room for optimisations here but its a complex
shader im putting it for future PR.
* shader: touchup blurfinish
make brightness a cheap multiplication instead of branching.
mod is redundant, fract in hash already returns a value in [0.0, 1.0]
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -81,23 +81,43 @@ enum eMonitorExtraRenderFBs : uint8_t {
|
||||
FB_MONITOR_RENDER_EXTRA_BLUR,
|
||||
};
|
||||
|
||||
enum ePreparedFragmentShader : uint8_t {
|
||||
SH_FRAG_QUAD = 0,
|
||||
SH_FRAG_RGBA,
|
||||
SH_FRAG_PASSTHRURGBA,
|
||||
SH_FRAG_MATTE,
|
||||
SH_FRAG_RGBX,
|
||||
SH_FRAG_EXT,
|
||||
SH_FRAG_BLUR1,
|
||||
SH_FRAG_BLUR2,
|
||||
SH_FRAG_CM_BLURPREPARE,
|
||||
SH_FRAG_BLURPREPARE,
|
||||
SH_FRAG_BLURFINISH,
|
||||
SH_FRAG_SHADOW,
|
||||
SH_FRAG_CM_BORDER1,
|
||||
SH_FRAG_BORDER1,
|
||||
SH_FRAG_GLITCH,
|
||||
SH_FRAG_CM_RGBA,
|
||||
SH_FRAG_CM_RGBX,
|
||||
|
||||
SH_FRAG_LAST,
|
||||
};
|
||||
|
||||
struct SFragShaderDesc {
|
||||
ePreparedFragmentShader id;
|
||||
const char* file;
|
||||
};
|
||||
|
||||
struct SPreparedShaders {
|
||||
std::string TEXVERTSRC;
|
||||
std::string TEXVERTSRC320;
|
||||
SShader m_shQUAD;
|
||||
SShader m_shRGBA;
|
||||
SShader m_shPASSTHRURGBA;
|
||||
SShader m_shMATTE;
|
||||
SShader m_shRGBX;
|
||||
SShader m_shEXT;
|
||||
SShader m_shBLUR1;
|
||||
SShader m_shBLUR2;
|
||||
SShader m_shBLURPREPARE;
|
||||
SShader m_shBLURFINISH;
|
||||
SShader m_shSHADOW;
|
||||
SShader m_shBORDER1;
|
||||
SShader m_shGLITCH;
|
||||
SShader m_shCM;
|
||||
SPreparedShaders() {
|
||||
for (auto& f : frag) {
|
||||
f = makeShared<CShader>();
|
||||
}
|
||||
}
|
||||
|
||||
std::string TEXVERTSRC;
|
||||
std::string TEXVERTSRC320;
|
||||
std::array<SP<CShader>, SH_FRAG_LAST> frag;
|
||||
};
|
||||
|
||||
struct SMonitorRenderData {
|
||||
@ -274,9 +294,7 @@ class CHyprOpenGLImpl {
|
||||
|
||||
bool initShaders();
|
||||
|
||||
GLuint createProgram(const std::string&, const std::string&, bool dynamic = false, bool silent = false);
|
||||
GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false);
|
||||
void useProgram(GLuint prog);
|
||||
WP<CShader> useShader(WP<CShader> prog);
|
||||
|
||||
void ensureLockTexturesRendered(bool load);
|
||||
|
||||
@ -375,13 +393,12 @@ class CHyprOpenGLImpl {
|
||||
SP<CTexture> m_lockDeadTexture;
|
||||
SP<CTexture> m_lockDead2Texture;
|
||||
SP<CTexture> m_lockTtyTextTexture;
|
||||
SShader m_finalScreenShader;
|
||||
SP<CShader> m_finalScreenShader;
|
||||
CTimer m_globalTimer;
|
||||
GLuint m_currentProgram;
|
||||
ASP<Hyprgraphics::CImageResource> m_backgroundResource;
|
||||
bool m_backgroundResourceFailed = false;
|
||||
|
||||
void logShaderError(const GLuint&, bool program = false, bool silent = false);
|
||||
void createBGTextureForMonitor(PHLMONITOR);
|
||||
void initDRMFormats();
|
||||
void initEGL(bool gbm);
|
||||
@ -403,9 +420,9 @@ class CHyprOpenGLImpl {
|
||||
CFramebuffer* blurMainFramebufferWithDamage(float a, CRegion* damage);
|
||||
CFramebuffer* blurFramebufferWithDamage(float a, CRegion* damage, CFramebuffer& source);
|
||||
|
||||
void passCMUniforms(SShader&, const NColorManagement::PImageDescription imageDescription, const NColorManagement::PImageDescription targetImageDescription,
|
||||
void passCMUniforms(WP<CShader>, const NColorManagement::PImageDescription imageDescription, const NColorManagement::PImageDescription targetImageDescription,
|
||||
bool modifySDR = false, float sdrMinLuminance = -1.0f, int sdrMaxLuminance = -1);
|
||||
void passCMUniforms(SShader&, const NColorManagement::PImageDescription imageDescription);
|
||||
void passCMUniforms(WP<CShader>, const NColorManagement::PImageDescription imageDescription);
|
||||
void renderTexturePrimitive(SP<CTexture> tex, const CBox& box);
|
||||
void renderSplash(cairo_t* const, cairo_surface_t* const, double offset, const Vector2D& size);
|
||||
void renderRectInternal(const CBox&, const CHyprColor&, const SRectRenderData& data);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "Shader.hpp"
|
||||
#include "../config/ConfigManager.hpp"
|
||||
#include "render/OpenGL.hpp"
|
||||
|
||||
#define EPSILON(x, y) (std::abs((x) - (y)) < 1e-5f)
|
||||
@ -14,51 +15,235 @@ static bool compareFloat(auto a, auto b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SShader::SShader() {
|
||||
uniformLocations.fill(-1);
|
||||
CShader::CShader() {
|
||||
m_uniformLocations.fill(-1);
|
||||
}
|
||||
|
||||
SShader::~SShader() {
|
||||
CShader::~CShader() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
void SShader::createVao() {
|
||||
void CShader::logShaderError(const GLuint& shader, bool program, bool silent) {
|
||||
GLint maxLength = 0;
|
||||
if (program)
|
||||
glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
else
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
std::vector<GLchar> errorLog(maxLength);
|
||||
if (program)
|
||||
glGetProgramInfoLog(shader, maxLength, &maxLength, errorLog.data());
|
||||
else
|
||||
glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog.data());
|
||||
std::string errorStr(errorLog.begin(), errorLog.end());
|
||||
|
||||
const auto FULLERROR = (program ? "Screen shader parser: Error linking program:" : "Screen shader parser: Error compiling shader: ") + errorStr;
|
||||
|
||||
Log::logger->log(Log::ERR, "Failed to link shader: {}", FULLERROR);
|
||||
|
||||
if (!silent)
|
||||
g_pConfigManager->addParseError(FULLERROR);
|
||||
}
|
||||
|
||||
GLuint CShader::compileShader(const GLuint& type, std::string src, bool dynamic, bool silent) {
|
||||
auto shader = glCreateShader(type);
|
||||
|
||||
auto shaderSource = src.c_str();
|
||||
|
||||
glShaderSource(shader, 1, &shaderSource, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint ok;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
|
||||
|
||||
if (dynamic) {
|
||||
if (ok == GL_FALSE) {
|
||||
logShaderError(shader, false, silent);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (ok != GL_TRUE)
|
||||
logShaderError(shader, false);
|
||||
RASSERT(ok != GL_FALSE, "compileShader() failed! GL_COMPILE_STATUS not OK!");
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
bool CShader::createProgram(const std::string& vert, const std::string& frag, bool dynamic, bool silent) {
|
||||
auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert, dynamic, silent);
|
||||
if (dynamic) {
|
||||
if (vertCompiled == 0)
|
||||
return false;
|
||||
} else
|
||||
RASSERT(vertCompiled, "Compiling shader failed. VERTEX nullptr! Shader source:\n\n{}", vert);
|
||||
|
||||
auto fragCompiled = compileShader(GL_FRAGMENT_SHADER, frag, dynamic, silent);
|
||||
if (dynamic) {
|
||||
if (fragCompiled == 0)
|
||||
return false;
|
||||
} else
|
||||
RASSERT(fragCompiled, "Compiling shader failed. FRAGMENT nullptr! Shader source:\n\n{}", frag);
|
||||
|
||||
auto prog = glCreateProgram();
|
||||
glAttachShader(prog, vertCompiled);
|
||||
glAttachShader(prog, fragCompiled);
|
||||
glLinkProgram(prog);
|
||||
|
||||
glDetachShader(prog, vertCompiled);
|
||||
glDetachShader(prog, fragCompiled);
|
||||
glDeleteShader(vertCompiled);
|
||||
glDeleteShader(fragCompiled);
|
||||
|
||||
GLint ok;
|
||||
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
|
||||
if (dynamic) {
|
||||
if (ok == GL_FALSE) {
|
||||
logShaderError(prog, true, silent);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ok != GL_TRUE)
|
||||
logShaderError(prog, true);
|
||||
RASSERT(ok != GL_FALSE, "createProgram() failed! GL_LINK_STATUS not OK!");
|
||||
}
|
||||
|
||||
m_program = prog;
|
||||
|
||||
getUniformLocations();
|
||||
createVao();
|
||||
return true;
|
||||
}
|
||||
|
||||
// its fine to call glGet on shaders that dont have the uniform
|
||||
// this however hardcodes the name now. #TODO maybe dont
|
||||
void CShader::getUniformLocations() {
|
||||
auto getUniform = [this](const GLchar* name) { return glGetUniformLocation(m_program, name); };
|
||||
auto getAttrib = [this](const GLchar* name) { return glGetAttribLocation(m_program, name); };
|
||||
|
||||
m_uniformLocations[SHADER_PROJ] = getUniform("proj");
|
||||
m_uniformLocations[SHADER_COLOR] = getUniform("color");
|
||||
m_uniformLocations[SHADER_ALPHA_MATTE] = getUniform("texMatte");
|
||||
m_uniformLocations[SHADER_TEX_TYPE] = getUniform("texType");
|
||||
|
||||
// shader has #include "CM.glsl"
|
||||
m_uniformLocations[SHADER_SKIP_CM] = getUniform("skipCM");
|
||||
m_uniformLocations[SHADER_SOURCE_TF] = getUniform("sourceTF");
|
||||
m_uniformLocations[SHADER_TARGET_TF] = getUniform("targetTF");
|
||||
m_uniformLocations[SHADER_SRC_TF_RANGE] = getUniform("srcTFRange");
|
||||
m_uniformLocations[SHADER_DST_TF_RANGE] = getUniform("dstTFRange");
|
||||
m_uniformLocations[SHADER_TARGET_PRIMARIES] = getUniform("targetPrimaries");
|
||||
m_uniformLocations[SHADER_MAX_LUMINANCE] = getUniform("maxLuminance");
|
||||
m_uniformLocations[SHADER_SRC_REF_LUMINANCE] = getUniform("srcRefLuminance");
|
||||
m_uniformLocations[SHADER_DST_MAX_LUMINANCE] = getUniform("dstMaxLuminance");
|
||||
m_uniformLocations[SHADER_DST_REF_LUMINANCE] = getUniform("dstRefLuminance");
|
||||
m_uniformLocations[SHADER_SDR_SATURATION] = getUniform("sdrSaturation");
|
||||
m_uniformLocations[SHADER_SDR_BRIGHTNESS] = getUniform("sdrBrightnessMultiplier");
|
||||
m_uniformLocations[SHADER_CONVERT_MATRIX] = getUniform("convertMatrix");
|
||||
//
|
||||
m_uniformLocations[SHADER_TEX] = getUniform("tex");
|
||||
m_uniformLocations[SHADER_ALPHA] = getUniform("alpha");
|
||||
m_uniformLocations[SHADER_POS_ATTRIB] = getAttrib("pos");
|
||||
m_uniformLocations[SHADER_TEX_ATTRIB] = getAttrib("texcoord");
|
||||
m_uniformLocations[SHADER_MATTE_TEX_ATTRIB] = getAttrib("texcoordMatte");
|
||||
m_uniformLocations[SHADER_DISCARD_OPAQUE] = getUniform("discardOpaque");
|
||||
m_uniformLocations[SHADER_DISCARD_ALPHA] = getUniform("discardAlpha");
|
||||
m_uniformLocations[SHADER_DISCARD_ALPHA_VALUE] = getUniform("discardAlphaValue");
|
||||
/* set in createVao
|
||||
m_uniformLocations[SHADER_SHADER_VAO]
|
||||
m_uniformLocations[SHADER_SHADER_VBO_POS]
|
||||
m_uniformLocations[SHADER_SHADER_VBO_UV]
|
||||
*/
|
||||
m_uniformLocations[SHADER_TOP_LEFT] = getUniform("topLeft");
|
||||
m_uniformLocations[SHADER_BOTTOM_RIGHT] = getUniform("bottomRight");
|
||||
|
||||
// compat for screenshaders
|
||||
auto fullSize = getUniform("fullSize");
|
||||
if (fullSize == -1)
|
||||
fullSize = getUniform("screen_size");
|
||||
if (fullSize == -1)
|
||||
fullSize = getUniform("screenSize");
|
||||
m_uniformLocations[SHADER_FULL_SIZE] = fullSize;
|
||||
|
||||
m_uniformLocations[SHADER_FULL_SIZE_UNTRANSFORMED] = getUniform("fullSizeUntransformed");
|
||||
m_uniformLocations[SHADER_RADIUS] = getUniform("radius");
|
||||
m_uniformLocations[SHADER_RADIUS_OUTER] = getUniform("radiusOuter");
|
||||
m_uniformLocations[SHADER_ROUNDING_POWER] = getUniform("roundingPower");
|
||||
m_uniformLocations[SHADER_THICK] = getUniform("thick");
|
||||
m_uniformLocations[SHADER_HALFPIXEL] = getUniform("halfpixel");
|
||||
m_uniformLocations[SHADER_RANGE] = getUniform("range");
|
||||
m_uniformLocations[SHADER_SHADOW_POWER] = getUniform("shadowPower");
|
||||
m_uniformLocations[SHADER_USE_ALPHA_MATTE] = getUniform("useAlphaMatte");
|
||||
m_uniformLocations[SHADER_APPLY_TINT] = getUniform("applyTint");
|
||||
m_uniformLocations[SHADER_TINT] = getUniform("tint");
|
||||
m_uniformLocations[SHADER_GRADIENT] = getUniform("gradient");
|
||||
m_uniformLocations[SHADER_GRADIENT_LENGTH] = getUniform("gradientLength");
|
||||
m_uniformLocations[SHADER_GRADIENT2] = getUniform("gradient2");
|
||||
m_uniformLocations[SHADER_GRADIENT2_LENGTH] = getUniform("gradient2Length");
|
||||
m_uniformLocations[SHADER_ANGLE] = getUniform("angle");
|
||||
m_uniformLocations[SHADER_ANGLE2] = getUniform("angle2");
|
||||
m_uniformLocations[SHADER_GRADIENT_LERP] = getUniform("gradientLerp");
|
||||
m_uniformLocations[SHADER_TIME] = getUniform("time");
|
||||
m_uniformLocations[SHADER_DISTORT] = getUniform("distort");
|
||||
m_uniformLocations[SHADER_WL_OUTPUT] = getUniform("wl_output");
|
||||
m_uniformLocations[SHADER_CONTRAST] = getUniform("contrast");
|
||||
m_uniformLocations[SHADER_PASSES] = getUniform("passes");
|
||||
m_uniformLocations[SHADER_VIBRANCY] = getUniform("vibrancy");
|
||||
m_uniformLocations[SHADER_VIBRANCY_DARKNESS] = getUniform("vibrancy_darkness");
|
||||
m_uniformLocations[SHADER_BRIGHTNESS] = getUniform("brightness");
|
||||
m_uniformLocations[SHADER_NOISE] = getUniform("noise");
|
||||
m_uniformLocations[SHADER_POINTER] = getUniform("pointer_position");
|
||||
m_uniformLocations[SHADER_POINTER_SHAPE] = getUniform("pointer_shape");
|
||||
m_uniformLocations[SHADER_POINTER_SWITCH_TIME] = getUniform("pointer_switch_time");
|
||||
m_uniformLocations[SHADER_POINTER_SHAPE_PREVIOUS] = getUniform("pointer_shape_previous");
|
||||
m_uniformLocations[SHADER_POINTER_PRESSED_POSITIONS] = getUniform("pointer_pressed_positions");
|
||||
m_uniformLocations[SHADER_POINTER_HIDDEN] = getUniform("pointer_hidden");
|
||||
m_uniformLocations[SHADER_POINTER_KILLING] = getUniform("pointer_killing");
|
||||
m_uniformLocations[SHADER_POINTER_PRESSED_TIMES] = getUniform("pointer_pressed_times");
|
||||
m_uniformLocations[SHADER_POINTER_PRESSED_KILLED] = getUniform("pointer_pressed_killed");
|
||||
m_uniformLocations[SHADER_POINTER_PRESSED_TOUCHED] = getUniform("pointer_pressed_touched");
|
||||
m_uniformLocations[SHADER_POINTER_INACTIVE_TIMEOUT] = getUniform("pointer_inactive_timeout");
|
||||
m_uniformLocations[SHADER_POINTER_LAST_ACTIVE] = getUniform("pointer_last_active");
|
||||
m_uniformLocations[SHADER_POINTER_SIZE] = getUniform("pointer_size");
|
||||
}
|
||||
|
||||
void CShader::createVao() {
|
||||
GLuint shaderVao = 0, shaderVbo = 0, shaderVboUv = 0;
|
||||
|
||||
glGenVertexArrays(1, &shaderVao);
|
||||
glBindVertexArray(shaderVao);
|
||||
|
||||
if (uniformLocations[SHADER_POS_ATTRIB] != -1) {
|
||||
if (m_uniformLocations[SHADER_POS_ATTRIB] != -1) {
|
||||
glGenBuffers(1, &shaderVbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, shaderVbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(fullVerts), fullVerts, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(uniformLocations[SHADER_POS_ATTRIB]);
|
||||
glVertexAttribPointer(uniformLocations[SHADER_POS_ATTRIB], 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glEnableVertexAttribArray(m_uniformLocations[SHADER_POS_ATTRIB]);
|
||||
glVertexAttribPointer(m_uniformLocations[SHADER_POS_ATTRIB], 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
}
|
||||
|
||||
// UV VBO (dynamic, may be updated per frame)
|
||||
if (uniformLocations[SHADER_TEX_ATTRIB] != -1) {
|
||||
if (m_uniformLocations[SHADER_TEX_ATTRIB] != -1) {
|
||||
glGenBuffers(1, &shaderVboUv);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, shaderVboUv);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(fullVerts), fullVerts, GL_DYNAMIC_DRAW); // Initial dummy UVs
|
||||
glEnableVertexAttribArray(uniformLocations[SHADER_TEX_ATTRIB]);
|
||||
glVertexAttribPointer(uniformLocations[SHADER_TEX_ATTRIB], 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glEnableVertexAttribArray(m_uniformLocations[SHADER_TEX_ATTRIB]);
|
||||
glVertexAttribPointer(m_uniformLocations[SHADER_TEX_ATTRIB], 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
uniformLocations[SHADER_SHADER_VAO] = shaderVao;
|
||||
uniformLocations[SHADER_SHADER_VBO_POS] = shaderVbo;
|
||||
uniformLocations[SHADER_SHADER_VBO_UV] = shaderVboUv;
|
||||
m_uniformLocations[SHADER_SHADER_VAO] = shaderVao;
|
||||
m_uniformLocations[SHADER_SHADER_VBO_POS] = shaderVbo;
|
||||
m_uniformLocations[SHADER_SHADER_VBO_UV] = shaderVboUv;
|
||||
|
||||
RASSERT(uniformLocations[SHADER_SHADER_VAO] >= 0, "SHADER_SHADER_VAO could not be created");
|
||||
RASSERT(uniformLocations[SHADER_SHADER_VBO_POS] >= 0, "SHADER_SHADER_VBO_POS could not be created");
|
||||
RASSERT(uniformLocations[SHADER_SHADER_VBO_UV] >= 0, "SHADER_SHADER_VBO_UV could not be created");
|
||||
RASSERT(m_uniformLocations[SHADER_SHADER_VAO] >= 0, "SHADER_SHADER_VAO could not be created");
|
||||
RASSERT(m_uniformLocations[SHADER_SHADER_VBO_POS] >= 0, "SHADER_SHADER_VBO_POS could not be created");
|
||||
RASSERT(m_uniformLocations[SHADER_SHADER_VBO_UV] >= 0, "SHADER_SHADER_VBO_UV could not be created");
|
||||
}
|
||||
|
||||
void SShader::setUniformInt(eShaderUniform location, GLint v0) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformInt(eShaderUniform location, GLint v0) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -67,11 +252,11 @@ void SShader::setUniformInt(eShaderUniform location, GLint v0) {
|
||||
return;
|
||||
|
||||
cached = v0;
|
||||
glUniform1i(uniformLocations[location], v0);
|
||||
glUniform1i(m_uniformLocations[location], v0);
|
||||
}
|
||||
|
||||
void SShader::setUniformFloat(eShaderUniform location, GLfloat v0) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformFloat(eShaderUniform location, GLfloat v0) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -83,11 +268,11 @@ void SShader::setUniformFloat(eShaderUniform location, GLfloat v0) {
|
||||
}
|
||||
|
||||
cached = v0;
|
||||
glUniform1f(uniformLocations[location], v0);
|
||||
glUniform1f(m_uniformLocations[location], v0);
|
||||
}
|
||||
|
||||
void SShader::setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -99,11 +284,11 @@ void SShader::setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1)
|
||||
}
|
||||
|
||||
cached = std::array<GLfloat, 2>{v0, v1};
|
||||
glUniform2f(uniformLocations[location], v0, v1);
|
||||
glUniform2f(m_uniformLocations[location], v0, v1);
|
||||
}
|
||||
|
||||
void SShader::setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -115,11 +300,11 @@ void SShader::setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1,
|
||||
}
|
||||
|
||||
cached = std::array<GLfloat, 3>{v0, v1, v2};
|
||||
glUniform3f(uniformLocations[location], v0, v1, v2);
|
||||
glUniform3f(m_uniformLocations[location], v0, v1, v2);
|
||||
}
|
||||
|
||||
void SShader::setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -131,11 +316,11 @@ void SShader::setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1,
|
||||
}
|
||||
|
||||
cached = std::array<GLfloat, 4>{v0, v1, v2, v3};
|
||||
glUniform4f(uniformLocations[location], v0, v1, v2, v3);
|
||||
glUniform4f(m_uniformLocations[location], v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
void SShader::setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 9> value) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 9> value) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -147,11 +332,11 @@ void SShader::setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLbool
|
||||
}
|
||||
|
||||
cached = SUniformMatrix3Data{.count = count, .transpose = transpose, .value = value};
|
||||
glUniformMatrix3fv(uniformLocations[location], count, transpose, value.data());
|
||||
glUniformMatrix3fv(m_uniformLocations[location], count, transpose, value.data());
|
||||
}
|
||||
|
||||
void SShader::setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 8> value) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 8> value) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -163,11 +348,11 @@ void SShader::setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLbo
|
||||
}
|
||||
|
||||
cached = SUniformMatrix4Data{.count = count, .transpose = transpose, .value = value};
|
||||
glUniformMatrix4x2fv(uniformLocations[location], count, transpose, value.data());
|
||||
glUniformMatrix4x2fv(m_uniformLocations[location], count, transpose, value.data());
|
||||
}
|
||||
|
||||
void SShader::setUniformfv(eShaderUniform location, GLsizei count, const std::vector<float>& value, GLsizei vec_size) {
|
||||
if (uniformLocations.at(location) == -1)
|
||||
void CShader::setUniformfv(eShaderUniform location, GLsizei count, const std::vector<float>& value, GLsizei vec_size) {
|
||||
if (m_uniformLocations.at(location) == -1)
|
||||
return;
|
||||
|
||||
auto& cached = uniformStatus.at(location);
|
||||
@ -180,36 +365,36 @@ void SShader::setUniformfv(eShaderUniform location, GLsizei count, const std::ve
|
||||
|
||||
cached = SUniformVData{.count = count, .value = value};
|
||||
switch (vec_size) {
|
||||
case 1: glUniform1fv(uniformLocations[location], count, value.data()); break;
|
||||
case 2: glUniform2fv(uniformLocations[location], count, value.data()); break;
|
||||
case 4: glUniform4fv(uniformLocations[location], count, value.data()); break;
|
||||
case 1: glUniform1fv(m_uniformLocations[location], count, value.data()); break;
|
||||
case 2: glUniform2fv(m_uniformLocations[location], count, value.data()); break;
|
||||
case 4: glUniform4fv(m_uniformLocations[location], count, value.data()); break;
|
||||
default: UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void SShader::setUniform1fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
void CShader::setUniform1fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
setUniformfv(location, count, value, 1);
|
||||
}
|
||||
|
||||
void SShader::setUniform2fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
void CShader::setUniform2fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
setUniformfv(location, count, value, 2);
|
||||
}
|
||||
|
||||
void SShader::setUniform4fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
void CShader::setUniform4fv(eShaderUniform location, GLsizei count, const std::vector<float>& value) {
|
||||
setUniformfv(location, count, value, 4);
|
||||
}
|
||||
|
||||
void SShader::destroy() {
|
||||
void CShader::destroy() {
|
||||
uniformStatus.fill(std::monostate());
|
||||
|
||||
if (program == 0)
|
||||
if (m_program == 0)
|
||||
return;
|
||||
|
||||
GLuint shaderVao, shaderVbo, shaderVboUv;
|
||||
|
||||
shaderVao = uniformLocations[SHADER_SHADER_VAO] == -1 ? 0 : uniformLocations[SHADER_SHADER_VAO];
|
||||
shaderVbo = uniformLocations[SHADER_SHADER_VBO_POS] == -1 ? 0 : uniformLocations[SHADER_SHADER_VBO_POS];
|
||||
shaderVboUv = uniformLocations[SHADER_SHADER_VBO_UV] == -1 ? 0 : uniformLocations[SHADER_SHADER_VBO_UV];
|
||||
shaderVao = m_uniformLocations[SHADER_SHADER_VAO] == -1 ? 0 : m_uniformLocations[SHADER_SHADER_VAO];
|
||||
shaderVbo = m_uniformLocations[SHADER_SHADER_VBO_POS] == -1 ? 0 : m_uniformLocations[SHADER_SHADER_VBO_POS];
|
||||
shaderVboUv = m_uniformLocations[SHADER_SHADER_VBO_UV] == -1 ? 0 : m_uniformLocations[SHADER_SHADER_VBO_UV];
|
||||
|
||||
if (shaderVao)
|
||||
glDeleteVertexArrays(1, &shaderVao);
|
||||
@ -220,6 +405,22 @@ void SShader::destroy() {
|
||||
if (shaderVboUv)
|
||||
glDeleteBuffers(1, &shaderVboUv);
|
||||
|
||||
glDeleteProgram(program);
|
||||
program = 0;
|
||||
glDeleteProgram(m_program);
|
||||
m_program = 0;
|
||||
}
|
||||
|
||||
GLint CShader::getUniformLocation(eShaderUniform location) const {
|
||||
return m_uniformLocations[location];
|
||||
}
|
||||
|
||||
GLuint CShader::program() const {
|
||||
return m_program;
|
||||
}
|
||||
|
||||
int CShader::getInitialTime() const {
|
||||
return m_initialTime;
|
||||
}
|
||||
|
||||
void CShader::setInitialTime(int time) {
|
||||
m_initialTime = time;
|
||||
}
|
||||
|
||||
@ -80,15 +80,32 @@ enum eShaderUniform : uint8_t {
|
||||
SHADER_LAST,
|
||||
};
|
||||
|
||||
struct SShader {
|
||||
SShader();
|
||||
~SShader();
|
||||
class CShader {
|
||||
public:
|
||||
CShader();
|
||||
~CShader();
|
||||
|
||||
GLuint program = 0;
|
||||
bool createProgram(const std::string& vert, const std::string& frag, bool dynamic = false, bool silent = false);
|
||||
void setUniformInt(eShaderUniform location, GLint v0);
|
||||
void setUniformFloat(eShaderUniform location, GLfloat v0);
|
||||
void setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1);
|
||||
void setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2);
|
||||
void setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
||||
void setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 9> value);
|
||||
void setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 8> value);
|
||||
void setUniform1fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void setUniform2fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void setUniform4fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void destroy();
|
||||
GLuint program() const;
|
||||
GLint getUniformLocation(eShaderUniform location) const;
|
||||
int getInitialTime() const;
|
||||
void setInitialTime(int time);
|
||||
|
||||
std::array<GLint, SHADER_LAST> uniformLocations;
|
||||
|
||||
float initialTime = 0;
|
||||
private:
|
||||
GLuint m_program = 0;
|
||||
float m_initialTime = 0;
|
||||
std::array<GLint, SHADER_LAST> m_uniformLocations;
|
||||
|
||||
struct SUniformMatrix3Data {
|
||||
GLsizei count = 0;
|
||||
@ -114,19 +131,9 @@ struct SShader {
|
||||
uniformStatus;
|
||||
//
|
||||
|
||||
void createVao();
|
||||
void setUniformInt(eShaderUniform location, GLint v0);
|
||||
void setUniformFloat(eShaderUniform location, GLfloat v0);
|
||||
void setUniformFloat2(eShaderUniform location, GLfloat v0, GLfloat v1);
|
||||
void setUniformFloat3(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2);
|
||||
void setUniformFloat4(eShaderUniform location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
||||
void setUniformMatrix3fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 9> value);
|
||||
void setUniformMatrix4x2fv(eShaderUniform location, GLsizei count, GLboolean transpose, std::array<GLfloat, 8> value);
|
||||
void setUniform1fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void setUniform2fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void setUniform4fv(eShaderUniform location, GLsizei count, const std::vector<float>& value);
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
void setUniformfv(eShaderUniform location, GLsizei count, const std::vector<float>& value, GLsizei vec_size);
|
||||
void logShaderError(const GLuint&, bool program = false, bool silent = false);
|
||||
GLuint compileShader(const GLuint&, std::string, bool dynamic = false, bool silent = false);
|
||||
void getUniformLocations();
|
||||
void createVao();
|
||||
void setUniformfv(eShaderUniform location, GLsizei count, const std::vector<float>& value, GLsizei vec_size);
|
||||
};
|
||||
|
||||
36
src/render/shaders/glsl/CMblurprepare.frag
Normal file
36
src/render/shaders/glsl/CMblurprepare.frag
Normal file
@ -0,0 +1,36 @@
|
||||
#version 300 es
|
||||
#extension GL_ARB_shading_language_include : enable
|
||||
|
||||
precision highp float;
|
||||
in vec2 v_texcoord; // is in 0-1
|
||||
uniform sampler2D tex;
|
||||
|
||||
uniform float contrast;
|
||||
uniform float brightness;
|
||||
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
|
||||
#include "CM.glsl"
|
||||
#include "gain.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
vec4 pixColor = texture(tex, v_texcoord);
|
||||
|
||||
if (sourceTF == CM_TRANSFER_FUNCTION_ST2084_PQ) {
|
||||
pixColor.rgb /= sdrBrightnessMultiplier;
|
||||
}
|
||||
pixColor.rgb = convertMatrix * toLinearRGB(pixColor.rgb, sourceTF);
|
||||
pixColor = toNit(pixColor, vec2(srcTFRange[0], srcRefLuminance));
|
||||
pixColor = fromLinearNit(pixColor, targetTF, dstTFRange);
|
||||
|
||||
// contrast
|
||||
if (contrast != 1.0)
|
||||
pixColor.rgb = gain(pixColor.rgb, contrast);
|
||||
|
||||
// brightness
|
||||
pixColor.rgb *= max(1.0, brightness);
|
||||
|
||||
fragColor = pixColor;
|
||||
}
|
||||
98
src/render/shaders/glsl/CMborder.frag
Normal file
98
src/render/shaders/glsl/CMborder.frag
Normal file
@ -0,0 +1,98 @@
|
||||
#version 300 es
|
||||
#extension GL_ARB_shading_language_include : enable
|
||||
|
||||
precision highp float;
|
||||
in vec2 v_texcoord;
|
||||
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
uniform mat4x2 targetPrimaries;
|
||||
|
||||
uniform vec2 fullSizeUntransformed;
|
||||
uniform float radiusOuter;
|
||||
uniform float thick;
|
||||
|
||||
// Gradients are in OkLabA!!!! {l, a, b, alpha}
|
||||
uniform vec4 gradient[10];
|
||||
uniform vec4 gradient2[10];
|
||||
uniform int gradientLength;
|
||||
uniform int gradient2Length;
|
||||
uniform float angle;
|
||||
uniform float angle2;
|
||||
uniform float gradientLerp;
|
||||
uniform float alpha;
|
||||
|
||||
#include "rounding.glsl"
|
||||
#include "CM.glsl"
|
||||
#include "border.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
highp vec2 pixCoord = vec2(gl_FragCoord);
|
||||
highp vec2 pixCoordOuter = pixCoord;
|
||||
highp vec2 originalPixCoord = v_texcoord;
|
||||
originalPixCoord *= fullSizeUntransformed;
|
||||
float additionalAlpha = 1.0;
|
||||
|
||||
vec4 pixColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
bool done = false;
|
||||
|
||||
pixCoord -= topLeft + fullSize * 0.5;
|
||||
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
|
||||
pixCoordOuter = pixCoord;
|
||||
pixCoord -= fullSize * 0.5 - radius;
|
||||
pixCoordOuter -= fullSize * 0.5 - radiusOuter;
|
||||
|
||||
// center the pixes don't make it top-left
|
||||
pixCoord += vec2(1.0, 1.0) / fullSize;
|
||||
pixCoordOuter += vec2(1.0, 1.0) / fullSize;
|
||||
|
||||
if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) {
|
||||
float dist = pow(pow(pixCoord.x,roundingPower)+pow(pixCoord.y,roundingPower),1.0/roundingPower);
|
||||
float distOuter = pow(pow(pixCoordOuter.x,roundingPower)+pow(pixCoordOuter.y,roundingPower),1.0/roundingPower);
|
||||
float h = (thick / 2.0);
|
||||
|
||||
if (dist < radius - h) {
|
||||
// lower
|
||||
float normalized = smoothstep(0.0, 1.0, (dist - radius + thick + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0));
|
||||
additionalAlpha *= normalized;
|
||||
done = true;
|
||||
} else if (min(pixCoordOuter.x, pixCoordOuter.y) > 0.0) {
|
||||
// higher
|
||||
float normalized = 1.0 - smoothstep(0.0, 1.0, (distOuter - radiusOuter + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0));
|
||||
additionalAlpha *= normalized;
|
||||
done = true;
|
||||
} else if (distOuter < radiusOuter - h) {
|
||||
additionalAlpha = 1.0;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
// now check for other shit
|
||||
if (!done) {
|
||||
// distance to all straight bb borders
|
||||
float distanceT = originalPixCoord[1];
|
||||
float distanceB = fullSizeUntransformed[1] - originalPixCoord[1];
|
||||
float distanceL = originalPixCoord[0];
|
||||
float distanceR = fullSizeUntransformed[0] - originalPixCoord[0];
|
||||
|
||||
// get the smallest
|
||||
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
|
||||
|
||||
if (smallest > thick)
|
||||
discard;
|
||||
}
|
||||
|
||||
if (additionalAlpha == 0.0)
|
||||
discard;
|
||||
|
||||
pixColor = getColorForCoord(v_texcoord);
|
||||
pixColor.rgb *= pixColor[3];
|
||||
|
||||
pixColor = doColorManagement(pixColor, sourceTF, targetTF, targetPrimaries);
|
||||
|
||||
pixColor *= alpha * additionalAlpha;
|
||||
|
||||
fragColor = pixColor;
|
||||
}
|
||||
@ -5,19 +5,17 @@ precision highp float;
|
||||
in vec2 v_texcoord;
|
||||
uniform sampler2D tex;
|
||||
|
||||
uniform int texType; // eTextureType: 0 - rgba, 1 - rgbx, 2 - ext
|
||||
// uniform int skipCM;
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
uniform mat4x2 targetPrimaries;
|
||||
|
||||
uniform float alpha;
|
||||
|
||||
uniform int discardOpaque;
|
||||
uniform int discardAlpha;
|
||||
uniform bool discardOpaque;
|
||||
uniform bool discardAlpha;
|
||||
uniform float discardAlphaValue;
|
||||
|
||||
uniform int applyTint;
|
||||
uniform bool applyTint;
|
||||
uniform vec3 tint;
|
||||
|
||||
#include "rounding.glsl"
|
||||
@ -25,28 +23,22 @@ uniform vec3 tint;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
vec4 pixColor;
|
||||
if (texType == 1)
|
||||
pixColor = vec4(texture(tex, v_texcoord).rgb, 1.0);
|
||||
//else if (texType == 2)
|
||||
// discard; // this shouldnt happen.
|
||||
else // assume rgba
|
||||
pixColor = texture(tex, v_texcoord);
|
||||
vec4 pixColor = texture(tex, v_texcoord);
|
||||
|
||||
if (discardOpaque == 1 && pixColor[3] * alpha == 1.0)
|
||||
if (discardOpaque && pixColor.a * alpha == 1.0)
|
||||
discard;
|
||||
|
||||
if (discardAlpha == 1 && pixColor[3] <= discardAlphaValue)
|
||||
if (discardAlpha && pixColor.a <= discardAlphaValue)
|
||||
discard;
|
||||
|
||||
// this shader shouldn't be used when skipCM == 1
|
||||
pixColor = doColorManagement(pixColor, sourceTF, targetTF, targetPrimaries);
|
||||
|
||||
if (applyTint == 1)
|
||||
pixColor = vec4(pixColor.rgb * tint.rgb, pixColor[3]);
|
||||
if (applyTint)
|
||||
pixColor.rgb *= tint;
|
||||
|
||||
if (radius > 0.0)
|
||||
pixColor = rounding(pixColor);
|
||||
|
||||
|
||||
fragColor = pixColor * alpha;
|
||||
}
|
||||
44
src/render/shaders/glsl/CMrgbx.frag
Normal file
44
src/render/shaders/glsl/CMrgbx.frag
Normal file
@ -0,0 +1,44 @@
|
||||
#version 300 es
|
||||
#extension GL_ARB_shading_language_include : enable
|
||||
|
||||
precision highp float;
|
||||
in vec2 v_texcoord;
|
||||
uniform sampler2D tex;
|
||||
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
uniform mat4x2 targetPrimaries;
|
||||
|
||||
uniform float alpha;
|
||||
|
||||
uniform bool discardOpaque;
|
||||
uniform bool discardAlpha;
|
||||
uniform float discardAlphaValue;
|
||||
|
||||
uniform bool applyTint;
|
||||
uniform vec3 tint;
|
||||
|
||||
#include "rounding.glsl"
|
||||
#include "CM.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
vec4 pixColor = vec4(texture(tex, v_texcoord).rgb, 1.0);
|
||||
|
||||
if (discardOpaque && pixColor.a * alpha == 1.0)
|
||||
discard;
|
||||
|
||||
if (discardAlpha && pixColor.a <= discardAlphaValue)
|
||||
discard;
|
||||
|
||||
// this shader shouldn't be used when skipCM == 1
|
||||
pixColor = doColorManagement(pixColor, sourceTF, targetTF, targetPrimaries);
|
||||
|
||||
if (applyTint)
|
||||
pixColor.rgb *= tint;
|
||||
|
||||
if (radius > 0.0)
|
||||
pixColor = rounding(pixColor);
|
||||
|
||||
fragColor = pixColor * alpha;
|
||||
}
|
||||
@ -20,13 +20,11 @@ void main() {
|
||||
|
||||
// noise
|
||||
float noiseHash = hash(v_texcoord);
|
||||
float noiseAmount = (mod(noiseHash, 1.0) - 0.5);
|
||||
float noiseAmount = noiseHash - 0.5;
|
||||
pixColor.rgb += noiseAmount * noise;
|
||||
|
||||
// brightness
|
||||
if (brightness < 1.0) {
|
||||
pixColor.rgb *= brightness;
|
||||
}
|
||||
pixColor.rgb *= min(1.0, brightness);
|
||||
|
||||
fragColor = pixColor;
|
||||
}
|
||||
|
||||
@ -8,41 +8,19 @@ uniform sampler2D tex;
|
||||
uniform float contrast;
|
||||
uniform float brightness;
|
||||
|
||||
uniform int skipCM;
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
|
||||
#include "CM.glsl"
|
||||
|
||||
float gain(float x, float k) {
|
||||
float a = 0.5 * pow(2.0 * ((x < 0.5) ? x : 1.0 - x), k);
|
||||
return (x < 0.5) ? a : 1.0 - a;
|
||||
}
|
||||
#include "gain.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
vec4 pixColor = texture(tex, v_texcoord);
|
||||
|
||||
if (skipCM == 0) {
|
||||
if (sourceTF == CM_TRANSFER_FUNCTION_ST2084_PQ) {
|
||||
pixColor.rgb /= sdrBrightnessMultiplier;
|
||||
}
|
||||
pixColor.rgb = convertMatrix * toLinearRGB(pixColor.rgb, sourceTF);
|
||||
pixColor = toNit(pixColor, vec2(srcTFRange[0], srcRefLuminance));
|
||||
pixColor = fromLinearNit(pixColor, targetTF, dstTFRange);
|
||||
}
|
||||
|
||||
// contrast
|
||||
if (contrast != 1.0) {
|
||||
pixColor.r = gain(pixColor.r, contrast);
|
||||
pixColor.g = gain(pixColor.g, contrast);
|
||||
pixColor.b = gain(pixColor.b, contrast);
|
||||
}
|
||||
if (contrast != 1.0)
|
||||
pixColor.rgb = gain(pixColor.rgb, contrast);
|
||||
|
||||
// brightness
|
||||
if (brightness > 1.0) {
|
||||
pixColor.rgb *= brightness;
|
||||
}
|
||||
pixColor.rgb *= max(1.0, brightness);
|
||||
|
||||
fragColor = pixColor;
|
||||
}
|
||||
|
||||
@ -4,11 +4,6 @@
|
||||
precision highp float;
|
||||
in vec2 v_texcoord;
|
||||
|
||||
uniform int skipCM;
|
||||
uniform int sourceTF; // eTransferFunction
|
||||
uniform int targetTF; // eTransferFunction
|
||||
uniform mat4x2 targetPrimaries;
|
||||
|
||||
uniform vec2 fullSizeUntransformed;
|
||||
uniform float radiusOuter;
|
||||
uniform float thick;
|
||||
@ -25,89 +20,7 @@ uniform float alpha;
|
||||
|
||||
#include "rounding.glsl"
|
||||
#include "CM.glsl"
|
||||
|
||||
vec4 okLabAToSrgb(vec4 lab) {
|
||||
float l = pow(lab[0] + lab[1] * 0.3963377774 + lab[2] * 0.2158037573, 3.0);
|
||||
float m = pow(lab[0] + lab[1] * (-0.1055613458) + lab[2] * (-0.0638541728), 3.0);
|
||||
float s = pow(lab[0] + lab[1] * (-0.0894841775) + lab[2] * (-1.2914855480), 3.0);
|
||||
|
||||
return vec4(fromLinearRGB(
|
||||
vec3(
|
||||
l * 4.0767416621 + m * -3.3077115913 + s * 0.2309699292,
|
||||
l * (-1.2684380046) + m * 2.6097574011 + s * (-0.3413193965),
|
||||
l * (-0.0041960863) + m * (-0.7034186147) + s * 1.7076147010
|
||||
), CM_TRANSFER_FUNCTION_GAMMA22
|
||||
), lab[3]);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray1(vec2 normalizedCoord) {
|
||||
if (gradientLength < 2)
|
||||
return gradient[0];
|
||||
|
||||
float finalAng = 0.0;
|
||||
|
||||
if (angle > 4.71 /* 270 deg */) {
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = 6.28 - angle;
|
||||
} else if (angle > 3.14 /* 180 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = angle - 3.14;
|
||||
} else if (angle > 1.57 /* 90 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
finalAng = 3.14 - angle;
|
||||
} else {
|
||||
finalAng = angle;
|
||||
}
|
||||
|
||||
float sine = sin(finalAng);
|
||||
|
||||
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradientLength - 1);
|
||||
int bottom = int(floor(progress));
|
||||
int top = bottom + 1;
|
||||
|
||||
return gradient[top] * (progress - float(bottom)) + gradient[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray2(vec2 normalizedCoord) {
|
||||
if (gradient2Length < 2)
|
||||
return gradient2[0];
|
||||
|
||||
float finalAng = 0.0;
|
||||
|
||||
if (angle2 > 4.71 /* 270 deg */) {
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = 6.28 - angle;
|
||||
} else if (angle2 > 3.14 /* 180 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = angle - 3.14;
|
||||
} else if (angle2 > 1.57 /* 90 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
finalAng = 3.14 - angle2;
|
||||
} else {
|
||||
finalAng = angle2;
|
||||
}
|
||||
|
||||
float sine = sin(finalAng);
|
||||
|
||||
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradient2Length - 1);
|
||||
int bottom = int(floor(progress));
|
||||
int top = bottom + 1;
|
||||
|
||||
return gradient2[top] * (progress - float(bottom)) + gradient2[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getColorForCoord(vec2 normalizedCoord) {
|
||||
vec4 result1 = getOkColorForCoordArray1(normalizedCoord);
|
||||
|
||||
if (gradient2Length <= 0)
|
||||
return okLabAToSrgb(result1);
|
||||
|
||||
vec4 result2 = getOkColorForCoordArray2(normalizedCoord);
|
||||
|
||||
return okLabAToSrgb(mix(result1, result2, gradientLerp));
|
||||
}
|
||||
#include "border.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
void main() {
|
||||
@ -173,9 +86,6 @@ void main() {
|
||||
pixColor = getColorForCoord(v_texcoord);
|
||||
pixColor.rgb *= pixColor[3];
|
||||
|
||||
if (skipCM == 0)
|
||||
pixColor = doColorManagement(pixColor, sourceTF, targetTF, targetPrimaries);
|
||||
|
||||
pixColor *= alpha * additionalAlpha;
|
||||
|
||||
fragColor = pixColor;
|
||||
|
||||
82
src/render/shaders/glsl/border.glsl
Normal file
82
src/render/shaders/glsl/border.glsl
Normal file
@ -0,0 +1,82 @@
|
||||
vec4 okLabAToSrgb(vec4 lab) {
|
||||
float l = pow(lab[0] + lab[1] * 0.3963377774 + lab[2] * 0.2158037573, 3.0);
|
||||
float m = pow(lab[0] + lab[1] * (-0.1055613458) + lab[2] * (-0.0638541728), 3.0);
|
||||
float s = pow(lab[0] + lab[1] * (-0.0894841775) + lab[2] * (-1.2914855480), 3.0);
|
||||
|
||||
return vec4(fromLinearRGB(
|
||||
vec3(
|
||||
l * 4.0767416621 + m * -3.3077115913 + s * 0.2309699292,
|
||||
l * (-1.2684380046) + m * 2.6097574011 + s * (-0.3413193965),
|
||||
l * (-0.0041960863) + m * (-0.7034186147) + s * 1.7076147010
|
||||
), CM_TRANSFER_FUNCTION_GAMMA22
|
||||
), lab[3]);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray1(vec2 normalizedCoord) {
|
||||
if (gradientLength < 2)
|
||||
return gradient[0];
|
||||
|
||||
float finalAng = 0.0;
|
||||
|
||||
if (angle > 4.71 /* 270 deg */) {
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = 6.28 - angle;
|
||||
} else if (angle > 3.14 /* 180 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = angle - 3.14;
|
||||
} else if (angle > 1.57 /* 90 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
finalAng = 3.14 - angle;
|
||||
} else {
|
||||
finalAng = angle;
|
||||
}
|
||||
|
||||
float sine = sin(finalAng);
|
||||
|
||||
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradientLength - 1);
|
||||
int bottom = int(floor(progress));
|
||||
int top = bottom + 1;
|
||||
|
||||
return gradient[top] * (progress - float(bottom)) + gradient[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getOkColorForCoordArray2(vec2 normalizedCoord) {
|
||||
if (gradient2Length < 2)
|
||||
return gradient2[0];
|
||||
|
||||
float finalAng = 0.0;
|
||||
|
||||
if (angle2 > 4.71 /* 270 deg */) {
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = 6.28 - angle;
|
||||
} else if (angle2 > 3.14 /* 180 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
normalizedCoord[1] = 1.0 - normalizedCoord[1];
|
||||
finalAng = angle - 3.14;
|
||||
} else if (angle2 > 1.57 /* 90 deg */) {
|
||||
normalizedCoord[0] = 1.0 - normalizedCoord[0];
|
||||
finalAng = 3.14 - angle2;
|
||||
} else {
|
||||
finalAng = angle2;
|
||||
}
|
||||
|
||||
float sine = sin(finalAng);
|
||||
|
||||
float progress = (normalizedCoord[1] * sine + normalizedCoord[0] * (1.0 - sine)) * float(gradient2Length - 1);
|
||||
int bottom = int(floor(progress));
|
||||
int top = bottom + 1;
|
||||
|
||||
return gradient2[top] * (progress - float(bottom)) + gradient2[bottom] * (float(top) - progress);
|
||||
}
|
||||
|
||||
vec4 getColorForCoord(vec2 normalizedCoord) {
|
||||
vec4 result1 = getOkColorForCoordArray1(normalizedCoord);
|
||||
|
||||
if (gradient2Length <= 0)
|
||||
return okLabAToSrgb(result1);
|
||||
|
||||
vec4 result2 = getOkColorForCoordArray2(normalizedCoord);
|
||||
|
||||
return okLabAToSrgb(mix(result1, result2, gradientLerp));
|
||||
}
|
||||
6
src/render/shaders/glsl/gain.glsl
Normal file
6
src/render/shaders/glsl/gain.glsl
Normal file
@ -0,0 +1,6 @@
|
||||
vec3 gain(vec3 x, float k) {
|
||||
vec3 t = step(0.5, x);
|
||||
vec3 y = mix(x, 1.0 - x, t);
|
||||
vec3 a = 0.5 * pow(2.0 * y, vec3(k));
|
||||
return mix(a, 1.0 - a, t);
|
||||
}
|
||||
@ -5,7 +5,7 @@ in vec2 v_texcoord;
|
||||
uniform sampler2D tex;
|
||||
uniform float time; // quirk: time is set to 0 at the beginning, should be around 10 when crash.
|
||||
uniform float distort;
|
||||
uniform vec2 screenSize;
|
||||
uniform vec2 fullSize;
|
||||
|
||||
float rand(float co) {
|
||||
return fract(sin(dot(vec2(co, co), vec2(12.9898, 78.233))) * 43758.5453);
|
||||
@ -31,7 +31,7 @@ void main() {
|
||||
float ABERR_OFFSET = 4.0 * (distort / 5.5) * time;
|
||||
float TEAR_AMOUNT = 9000.0 * (1.0 - (distort / 5.5));
|
||||
float TEAR_BANDS = 108.0 / 2.0 * (distort / 5.5) * 2.0;
|
||||
float MELT_AMOUNT = (distort * 8.0) / screenSize.y;
|
||||
float MELT_AMOUNT = (distort * 8.0) / fullSize.y;
|
||||
|
||||
float NOISE = abs(mod(noise(v_texcoord) * distort * time * 2.771, 1.0)) * time / 10.0;
|
||||
if (time < 2.0)
|
||||
@ -44,7 +44,7 @@ void main() {
|
||||
if (time < 3.0)
|
||||
blockOffset = vec2(0,0);
|
||||
|
||||
float meltSeed = abs(mod(rand(floor(v_texcoord.x * screenSize.x * 17.719)) * 281.882, 1.0));
|
||||
float meltSeed = abs(mod(rand(floor(v_texcoord.x * fullSize.x * 17.719)) * 281.882, 1.0));
|
||||
if (meltSeed < 0.8) {
|
||||
meltSeed = 0.0;
|
||||
} else {
|
||||
@ -52,11 +52,11 @@ void main() {
|
||||
}
|
||||
float meltAmount = MELT_AMOUNT * meltSeed;
|
||||
|
||||
vec2 pixCoord = vec2(v_texcoord.x + offset + NOISE * 3.0 / screenSize.x + blockOffset.x, v_texcoord.y - meltAmount + 0.02 * NOISE / screenSize.x + NOISE * 3.0 / screenSize.y + blockOffset.y);
|
||||
vec2 pixCoord = vec2(v_texcoord.x + offset + NOISE * 3.0 / fullSize.x + blockOffset.x, v_texcoord.y - meltAmount + 0.02 * NOISE / fullSize.x + NOISE * 3.0 / fullSize.y + blockOffset.y);
|
||||
|
||||
vec4 pixColor = texture(tex, pixCoord);
|
||||
vec4 pixColorLeft = texture(tex, pixCoord + vec2(ABERR_OFFSET / screenSize.x, 0));
|
||||
vec4 pixColorRight = texture(tex, pixCoord + vec2(-ABERR_OFFSET / screenSize.x, 0));
|
||||
vec4 pixColorLeft = texture(tex, pixCoord + vec2(ABERR_OFFSET / fullSize.x, 0));
|
||||
vec4 pixColorRight = texture(tex, pixCoord + vec2(-ABERR_OFFSET / fullSize.x, 0));
|
||||
|
||||
pixColor[0] = pixColorLeft[0];
|
||||
pixColor[2] = pixColorRight[2];
|
||||
|
||||
Reference in New Issue
Block a user