mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Optimize blender shaders. Thanks to Logan McNaughton aka loganmc10 and standard-two-simplex for the new code.
This commit is contained in:
parent
a2a96f3d92
commit
231463e368
|
@ -464,77 +464,38 @@ public:
|
||||||
class ShaderBlender1 : public ShaderPart
|
class ShaderBlender1 : public ShaderPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderBlender1(const opengl::GLInfo & _glinfo)
|
ShaderBlender1()
|
||||||
{
|
{
|
||||||
if (_glinfo.isGLESX) {
|
#if 1
|
||||||
m_part =
|
m_part =
|
||||||
" muxPM[0] = clampedColor; \n"
|
" muxPM[0] = clampedColor; \n"
|
||||||
" if (uForceBlendCycle1 != 0) { \n"
|
" lowp vec4 vprobe = vec4(0.0, 1.0, 2.0, 3.0); \n"
|
||||||
" muxA[0] = clampedColor.a; \n"
|
" if (uForceBlendCycle1 != 0) { \n"
|
||||||
" lowp float muxa; \n"
|
" muxA[0] = clampedColor.a; \n"
|
||||||
" if (uBlendMux1[1] == 0) \n"
|
" lowp float muxa = dot(muxA, vec4(equal(vec4(uBlendMux1[1]), vprobe))); \n"
|
||||||
" muxa = muxA[0]; \n"
|
" muxB[0] = 1.0 - muxa; \n"
|
||||||
" else if (uBlendMux1[1] == 1) \n"
|
" lowp vec4 muxpm0 = muxPM * vec4(equal(vec4(uBlendMux1[0]), vprobe)); \n"
|
||||||
" muxa = muxA[1]; \n"
|
" lowp vec4 muxpm2 = muxPM * vec4(equal(vec4(uBlendMux1[2]), vprobe)); \n"
|
||||||
" else if (uBlendMux1[1] == 2) \n"
|
" lowp float muxb = dot(muxB, vec4(equal(vec4(uBlendMux1[3]), vprobe))); \n"
|
||||||
" muxa = muxA[2]; \n"
|
" lowp vec4 blend1 = (muxpm0 * muxa) + (muxpm2 * muxb); \n"
|
||||||
" else if (uBlendMux1[1] == 3) \n"
|
" clampedColor.rgb = clamp(blend1.rgb, 0.0, 1.0); \n"
|
||||||
" muxa = muxA[3]; \n"
|
" } else { \n"
|
||||||
" muxB[0] = 1.0 - muxa; \n"
|
" lowp vec4 muxpm0 = muxPM * vec4(equal(vec4(uBlendMux1[0]), vprobe)); \n"
|
||||||
" lowp vec4 muxpm0; \n"
|
" clampedColor.rgb = muxpm0.rgb; \n"
|
||||||
" if (uBlendMux1[0] == 0) \n"
|
" } \n"
|
||||||
" muxpm0 = muxPM[0]; \n"
|
;
|
||||||
" else if (uBlendMux1[0] == 1) \n"
|
#else
|
||||||
" muxpm0 = muxPM[1]; \n"
|
// Keep old code for reference
|
||||||
" else if (uBlendMux1[0] == 2) \n"
|
m_part =
|
||||||
" muxpm0 = muxPM[2]; \n"
|
" muxPM[0] = clampedColor; \n"
|
||||||
" else if (uBlendMux1[0] == 3) \n"
|
" if (uForceBlendCycle1 != 0) { \n"
|
||||||
" muxpm0 = muxPM[3]; \n"
|
" muxA[0] = clampedColor.a; \n"
|
||||||
" lowp vec4 muxpm2; \n"
|
" muxB[0] = 1.0 - muxA[uBlendMux1[1]]; \n"
|
||||||
" if (uBlendMux1[2] == 0) \n"
|
" lowp vec4 blend1 = (muxPM[uBlendMux1[0]] * muxA[uBlendMux1[1]]) + (muxPM[uBlendMux1[2]] * muxB[uBlendMux1[3]]); \n"
|
||||||
" muxpm2 = muxPM[0]; \n"
|
" clampedColor.rgb = clamp(blend1.rgb, 0.0, 1.0); \n"
|
||||||
" else if (uBlendMux1[2] == 1) \n"
|
" } else clampedColor.rgb = muxPM[uBlendMux1[0]].rgb; \n"
|
||||||
" muxpm2 = muxPM[1]; \n"
|
;
|
||||||
" else if (uBlendMux1[2] == 2) \n"
|
#endif
|
||||||
" muxpm2 = muxPM[2]; \n"
|
|
||||||
" else if (uBlendMux1[2] == 3) \n"
|
|
||||||
" muxpm2 = muxPM[3]; \n"
|
|
||||||
" lowp float muxb; \n"
|
|
||||||
" if (uBlendMux1[3] == 0) \n"
|
|
||||||
" muxb = muxB[0]; \n"
|
|
||||||
" else if (uBlendMux1[3] == 1) \n"
|
|
||||||
" muxb = muxB[1]; \n"
|
|
||||||
" else if (uBlendMux1[3] == 2) \n"
|
|
||||||
" muxb = muxB[2]; \n"
|
|
||||||
" else if (uBlendMux1[3] == 3) \n"
|
|
||||||
" muxb = muxB[3]; \n"
|
|
||||||
" lowp vec4 blend1 = (muxpm0 * muxa) + (muxpm2 * muxb); \n"
|
|
||||||
" clampedColor.rgb = clamp(blend1.rgb, 0.0, 1.0); \n"
|
|
||||||
" } else { \n"
|
|
||||||
" lowp vec4 muxpm0; \n"
|
|
||||||
" if (uBlendMux1[0] == 0) \n"
|
|
||||||
" muxpm0 = muxPM[0]; \n"
|
|
||||||
" else if (uBlendMux1[0] == 1) \n"
|
|
||||||
" muxpm0 = muxPM[1]; \n"
|
|
||||||
" else if (uBlendMux1[0] == 2) \n"
|
|
||||||
" muxpm0 = muxPM[2]; \n"
|
|
||||||
" else if (uBlendMux1[0] == 3) \n"
|
|
||||||
" muxpm0 = muxPM[3]; \n"
|
|
||||||
" clampedColor.rgb = muxpm0.rgb; \n"
|
|
||||||
" } \n"
|
|
||||||
;
|
|
||||||
} else {
|
|
||||||
m_part =
|
|
||||||
" muxPM[0] = clampedColor; \n"
|
|
||||||
" if (uForceBlendCycle1 != 0) { \n"
|
|
||||||
" muxA[0] = clampedColor.a; \n"
|
|
||||||
" muxB[0] = 1.0 - muxA[uBlendMux1[1]]; \n"
|
|
||||||
" lowp vec4 blend1 = (muxPM[uBlendMux1[0]] * muxA[uBlendMux1[1]]) + (muxPM[uBlendMux1[2]] * muxB[uBlendMux1[3]]); \n"
|
|
||||||
" clampedColor.rgb = clamp(blend1.rgb, 0.0, 1.0); \n"
|
|
||||||
" } else clampedColor.rgb = muxPM[uBlendMux1[0]].rgb; \n"
|
|
||||||
;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(std::stringstream & shader) const override
|
void write(std::stringstream & shader) const override
|
||||||
|
@ -549,79 +510,39 @@ public:
|
||||||
class ShaderBlender2 : public ShaderPart
|
class ShaderBlender2 : public ShaderPart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderBlender2(const opengl::GLInfo & _glinfo)
|
ShaderBlender2()
|
||||||
{
|
{
|
||||||
if (_glinfo.isGLESX) {
|
#if 1
|
||||||
m_part =
|
m_part =
|
||||||
" muxPM[0] = clampedColor; \n"
|
" muxPM[0] = clampedColor; \n"
|
||||||
" muxPM[1] = vec4(0.0); \n"
|
" muxPM[1] = vec4(0.0); \n"
|
||||||
" if (uForceBlendCycle2 != 0) { \n"
|
" if (uForceBlendCycle2 != 0) { \n"
|
||||||
" muxA[0] = clampedColor.a; \n"
|
" muxA[0] = clampedColor.a; \n"
|
||||||
" lowp float muxa; \n"
|
" lowp float muxa = dot(muxA,vec4(equal(vec4(uBlendMux2[1]), vprobe))); \n"
|
||||||
" if (uBlendMux2[1] == 0) \n"
|
" muxB[0] = 1.0 - muxa; \n"
|
||||||
" muxa = muxA[0]; \n"
|
" lowp vec4 muxpm0 = muxPM*vec4(equal(vec4(uBlendMux2[0]), vprobe)); \n"
|
||||||
" else if (uBlendMux2[1] == 1) \n"
|
" lowp vec4 muxpm2 = muxPM*vec4(equal(vec4(uBlendMux2[2]), vprobe)); \n"
|
||||||
" muxa = muxA[1]; \n"
|
" lowp float muxb = dot(muxB,vec4(equal(vec4(uBlendMux2[3]), vprobe))); \n"
|
||||||
" else if (uBlendMux2[1] == 2) \n"
|
" lowp vec4 blend2 = muxpm0 * muxa + muxpm2 * muxb; \n"
|
||||||
" muxa = muxA[2]; \n"
|
" clampedColor.rgb = clamp(blend2.rgb, 0.0, 1.0); \n"
|
||||||
" else if (uBlendMux2[1] == 3) \n"
|
" } else { \n"
|
||||||
" muxa = muxA[3]; \n"
|
" lowp vec4 muxpm0 = muxPM * vec4(equal(vec4(uBlendMux2[0]), vprobe)); \n"
|
||||||
" muxB[0] = 1.0 - muxa; \n"
|
" clampedColor.rgb = muxpm0.rgb; \n"
|
||||||
" lowp vec4 muxpm0; \n"
|
" } \n"
|
||||||
" if (uBlendMux2[0] == 0) \n"
|
;
|
||||||
" muxpm0 = muxPM[0]; \n"
|
#else
|
||||||
" else if (uBlendMux2[0] == 1) \n"
|
// Keep old code for reference
|
||||||
" muxpm0 = muxPM[1]; \n"
|
m_part =
|
||||||
" else if (uBlendMux2[0] == 2) \n"
|
" muxPM[0] = clampedColor; \n"
|
||||||
" muxpm0 = muxPM[2]; \n"
|
" muxPM[1] = vec4(0.0); \n"
|
||||||
" else if (uBlendMux2[0] == 3) \n"
|
" if (uForceBlendCycle2 != 0) { \n"
|
||||||
" muxpm0 = muxPM[3]; \n"
|
" muxA[0] = clampedColor.a; \n"
|
||||||
" lowp vec4 muxpm2; \n"
|
" muxB[0] = 1.0 - muxA[uBlendMux2[1]]; \n"
|
||||||
" if (uBlendMux2[2] == 0) \n"
|
" lowp vec4 blend2 = muxPM[uBlendMux2[0]] * muxA[uBlendMux2[1]] + muxPM[uBlendMux2[2]] * muxB[uBlendMux2[3]]; \n"
|
||||||
" muxpm2 = muxPM[0]; \n"
|
" clampedColor.rgb = clamp(blend2.rgb, 0.0, 1.0); \n"
|
||||||
" else if (uBlendMux2[2] == 1) \n"
|
" } else clampedColor.rgb = muxPM[uBlendMux2[0]].rgb; \n"
|
||||||
" muxpm2 = muxPM[1]; \n"
|
;
|
||||||
" else if (uBlendMux2[2] == 2) \n"
|
#endif
|
||||||
" muxpm2 = muxPM[2]; \n"
|
|
||||||
" else if (uBlendMux2[2] == 3) \n"
|
|
||||||
" muxpm2 = muxPM[3]; \n"
|
|
||||||
" lowp float muxb; \n"
|
|
||||||
" if (uBlendMux2[3] == 0) \n"
|
|
||||||
" muxb = muxB[0]; \n"
|
|
||||||
" else if (uBlendMux2[3] == 1) \n"
|
|
||||||
" muxb = muxB[1]; \n"
|
|
||||||
" else if (uBlendMux2[3] == 2) \n"
|
|
||||||
" muxb = muxB[2]; \n"
|
|
||||||
" else if (uBlendMux2[3] == 3) \n"
|
|
||||||
" muxb = muxB[3]; \n"
|
|
||||||
" lowp vec4 blend2 = muxpm0 * muxa + muxpm2 * muxb; \n"
|
|
||||||
" clampedColor.rgb = clamp(blend2.rgb, 0.0, 1.0); \n"
|
|
||||||
" } else { \n"
|
|
||||||
" lowp vec4 muxpm0; \n"
|
|
||||||
" if (uBlendMux2[0] == 0) \n"
|
|
||||||
" muxpm0 = muxPM[0]; \n"
|
|
||||||
" else if (uBlendMux2[0] == 1) \n"
|
|
||||||
" muxpm0 = muxPM[1]; \n"
|
|
||||||
" else if (uBlendMux2[0] == 2) \n"
|
|
||||||
" muxpm0 = muxPM[2]; \n"
|
|
||||||
" else if (uBlendMux2[0] == 3) \n"
|
|
||||||
" muxpm0 = muxPM[3]; \n"
|
|
||||||
" clampedColor.rgb = muxpm0.rgb; \n"
|
|
||||||
" } \n"
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_part =
|
|
||||||
" muxPM[0] = clampedColor; \n"
|
|
||||||
" muxPM[1] = vec4(0.0); \n"
|
|
||||||
" if (uForceBlendCycle2 != 0) { \n"
|
|
||||||
" muxA[0] = clampedColor.a; \n"
|
|
||||||
" muxB[0] = 1.0 - muxA[uBlendMux2[1]]; \n"
|
|
||||||
" lowp vec4 blend2 = muxPM[uBlendMux2[0]] * muxA[uBlendMux2[1]] + muxPM[uBlendMux2[2]] * muxB[uBlendMux2[3]]; \n"
|
|
||||||
" clampedColor.rgb = clamp(blend2.rgb, 0.0, 1.0); \n"
|
|
||||||
" } else clampedColor.rgb = muxPM[uBlendMux2[0]].rgb; \n"
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2020,8 +1941,8 @@ GLuint _createVertexShader(ShaderPart * _header, ShaderPart * _body)
|
||||||
}
|
}
|
||||||
|
|
||||||
CombinerProgramBuilder::CombinerProgramBuilder(const opengl::GLInfo & _glinfo, opengl::CachedUseProgram * _useProgram)
|
CombinerProgramBuilder::CombinerProgramBuilder(const opengl::GLInfo & _glinfo, opengl::CachedUseProgram * _useProgram)
|
||||||
: m_blender1(new ShaderBlender1(_glinfo))
|
: m_blender1(new ShaderBlender1)
|
||||||
, m_blender2(new ShaderBlender2(_glinfo))
|
, m_blender2(new ShaderBlender2)
|
||||||
, m_legacyBlender(new ShaderLegacyBlender)
|
, m_legacyBlender(new ShaderLegacyBlender)
|
||||||
, m_clamp(new ShaderClamp)
|
, m_clamp(new ShaderClamp)
|
||||||
, m_signExtendColorC(new ShaderSignExtendColorC)
|
, m_signExtendColorC(new ShaderSignExtendColorC)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user