- convert texturefactor to uniform

This commit is contained in:
Magnus Norddahl 2019-08-16 14:01:27 +02:00
parent 3968206199
commit 0542bd25ec
8 changed files with 65 additions and 51 deletions

View file

@ -172,11 +172,6 @@ namespace CodeImp.DoomBuilder.Rendering
RenderDevice_SetMultisampleAntialias(Handle, value);
}
public void SetTextureFactor(int factor)
{
// To do: is this even applied to fragment shaders? if not, delete - if it is, convert to uniform
}
public void SetZEnable(bool value)
{
RenderDevice_SetZEnable(Handle, value);
@ -351,7 +346,7 @@ namespace CodeImp.DoomBuilder.Rendering
SetFogEnable(false);
SetMultisampleAntialias((General.Settings.AntiAliasingSamples > 0));
SetSourceBlend(Blend.SourceAlpha);
SetTextureFactor(-1);
SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
SetZEnable(false);
SetZWriteEnable(false);
@ -577,7 +572,8 @@ namespace CodeImp.DoomBuilder.Rendering
lightColor,
ignoreNormals,
spotLight,
campos
campos,
texturefactor
}
public enum VertexFormat : int { Flat, World }

View file

@ -202,13 +202,13 @@ namespace CodeImp.DoomBuilder.Rendering
case BlendingMode.None:
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
break;
case BlendingMode.Mask:
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(true);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
break;
case BlendingMode.Alpha:
@ -216,7 +216,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaTestEnable(false);
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetTextureFactor((new Color4(1f, 1f, 1f, layer.alpha)).ToArgb());
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, layer.alpha));
break;
case BlendingMode.Additive:
@ -224,7 +224,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaTestEnable(false);
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.One);
graphics.SetTextureFactor((new Color4(1f, 1f, 1f, layer.alpha)).ToArgb());
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, layer.alpha));
break;
}
@ -1229,7 +1229,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetAlphaTestEnable(false);
graphics.SetFogEnable(false);
graphics.SetTextureFactor(alphacolor.ToArgb());
graphics.SetUniform(UniformName.texturefactor, alphacolor);
graphics.SetVertexBuffer(thingsvertices);
// Set things texture
@ -1487,7 +1487,7 @@ namespace CodeImp.DoomBuilder.Rendering
{
// Set renderstates for rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFillMode(FillMode.Wireframe);
graphics.SetShader(ShaderName.things2d_fill);
@ -1583,7 +1583,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(true);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1641,7 +1641,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(0, t);
@ -1663,7 +1663,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(true);
@ -1691,7 +1691,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(true);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(0, label.Texture);
@ -1722,7 +1722,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(true);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
@ -1789,7 +1789,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
@ -1824,7 +1824,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
@ -1856,7 +1856,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
@ -1955,7 +1955,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
@ -2007,7 +2007,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZEnable(false);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);

View file

@ -316,7 +316,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetFogColor(General.Colors.Background.ToInt());
graphics.SetFogStart(General.Settings.ViewDistance * FOG_RANGE);
graphics.SetFogEnd(General.Settings.ViewDistance);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetUniform(UniformName.highlightcolor, new Color4()); //mxd
// Texture addressing
@ -384,10 +384,10 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetZWriteEnable(true);
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
//mxd. SKY PASS
if(skygeo.Count > 0)
if (skygeo.Count > 0)
{
world = Matrix.Identity;
ApplyMatrices3D();
@ -611,7 +611,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Done
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
}
//mxd
@ -651,7 +651,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Done
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
}
//mxd
@ -729,7 +729,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Draw(PrimitiveType.LineList, 0, pointscount / 2);
// Done
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
vb.Dispose();
}
@ -2013,7 +2013,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaTestEnable(false);
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetTextureFactor(-1);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
worldmatrix = Matrix.Identity;
ApplyMatrices2D();

View file

@ -469,7 +469,8 @@ static const int uniformLocations[(int)UniformName::NumUniforms] = {
104, // lightColor
109, // ignoreNormals
110, // spotLight
76, // campos
76, // campos,
112, // texturefactor
};
void RenderDevice::SetUniform(UniformName name, const void* values, int count)
@ -504,6 +505,8 @@ void RenderDevice::ApplyUniforms()
glUniform1fv(locations[(int)UniformName::ignoreNormals], 1, &mUniforms[109].valuef);
glUniform1fv(locations[(int)UniformName::spotLight], 1, &mUniforms[110].valuef);
glUniform4fv(locations[(int)UniformName::texturefactor], 1, &mUniforms[112].valuef);
for (int i = 0; i < Shader::MaxSamplers; i++)
glUniform1i(shader->SamplerLocations[i], i);
}

View file

@ -67,6 +67,7 @@ enum class UniformName : int
ignoreNormals,
spotLight,
campos,
texturefactor,
NumUniforms
};
@ -158,7 +159,7 @@ public:
int32_t valuei;
};
UniformEntry mUniforms[4 * 16 + 12 * 4];
UniformEntry mUniforms[4 * 16 + 13 * 4];
GLuint mStreamVertexBuffer = 0;
GLuint mStreamVAO = 0;

View file

@ -84,7 +84,8 @@ bool Shader::Compile(const std::string& vertexShader, const std::string& fragmen
"lightColor",
"ignoreNormals",
"spotLight",
"campos"
"campos",
"texturefactor"
};
for (int i = 0; i < (int)UniformName::NumUniforms; i++)

View file

@ -33,6 +33,7 @@ static const char* display2D_ps_fsaa = R"(
uniform float desaturation;
uniform sampler2D texture1;
uniform vec4 texturefactor;
// This blends the max of 2 pixels
vec4 addcolor(vec4 c1, vec4 c2)
@ -71,6 +72,8 @@ static const char* display2D_ps_fsaa = R"(
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
}
FragColor *= texturefactor;
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
@ -92,6 +95,7 @@ const char* display2D_ps_normal = R"(
uniform float desaturation;
uniform sampler2D texture1;
uniform vec4 texturefactor;
vec3 desaturate(vec3 texel)
{
@ -103,6 +107,7 @@ const char* display2D_ps_normal = R"(
{
vec4 c = texture(texture1, UV);
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
FragColor *= texturefactor;
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
@ -124,11 +129,13 @@ const char* display2D_ps_fullbright = R"(
uniform vec4 rendersettings;
uniform sampler2D texture1;
uniform vec4 texturefactor;
void main()
{
vec4 c = texture(texture1, UV);
FragColor = vec4(c.rgb, c.a * rendersettings.w);
FragColor *= texturefactor;
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;

View file

@ -30,6 +30,7 @@ static const char* things2D_ps_sprite = R"(
uniform float desaturation;
uniform sampler2D texture1;
uniform vec4 texturefactor;
vec3 desaturate(vec3 texel)
{
@ -54,6 +55,8 @@ static const char* things2D_ps_sprite = R"(
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w);
}
FragColor *= texturefactor;
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
@ -72,6 +75,7 @@ static const char* things2D_ps_thing = R"(
uniform float desaturation;
uniform sampler2D texture1;
uniform vec4 texturefactor;
vec3 desaturate(vec3 texel)
{
@ -84,6 +88,8 @@ static const char* things2D_ps_thing = R"(
vec4 c = texture(texture1, UV);
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
FragColor *= texturefactor;
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif