- implement the fixed function fog

This commit is contained in:
Magnus Norddahl 2019-08-22 18:43:54 +02:00
parent 808d644c0b
commit 64cc7d2bc2
12 changed files with 151 additions and 122 deletions

View file

@ -3471,7 +3471,9 @@ namespace CodeImp.DoomBuilder.Data
for(int i = 0; i < 6; i++)
{
Matrix faceview = GetCubeMapViewMatrix((CubeMapFace)i);
General.Map.Graphics.SetUniform(UniformName.worldviewproj, mworld * faceview * mprojection);
General.Map.Graphics.SetUniform(UniformName.world, mworld);
General.Map.Graphics.SetUniform(UniformName.view, faceview);
General.Map.Graphics.SetUniform(UniformName.projection, mprojection);
// Render the skysphere meshes
for(int j = 0; j < meshes.Meshes.Count; j++)

View file

@ -49,7 +49,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.StartRendering(clear, new Color4(0), this.Texture, false);
graphics.SetShader(ShaderName.plotter);
graphics.SetUniform(UniformName.transformsettings, projmat);
graphics.SetUniform(UniformName.projection, projmat);
graphics.SetAlphaBlendEnable(true);
graphics.SetBlendOperation(BlendOperation.Add);
graphics.SetSourceBlend(Blend.SourceAlpha);

View file

@ -147,26 +147,6 @@ namespace CodeImp.DoomBuilder.Rendering
RenderDevice_SetFillMode(Handle, mode);
}
public void SetFogEnable(bool value)
{
// To do: move to shaders as an uniform
}
public void SetFogColor(int value)
{
// To do: move to shaders as an uniform
}
public void SetFogStart(float value)
{
// To do: move to shaders as an uniform
}
public void SetFogEnd(float value)
{
// To do: move to shaders as an uniform
}
public void SetMultisampleAntialias(bool value)
{
RenderDevice_SetMultisampleAntialias(Handle, value);
@ -329,7 +309,6 @@ namespace CodeImp.DoomBuilder.Rendering
SetCullMode(Cull.None);
SetDestinationBlend(Blend.InverseSourceAlpha);
SetFillMode(FillMode.Solid);
SetFogEnable(false);
SetMultisampleAntialias((General.Settings.AntiAliasingSamples > 0));
SetSourceBlend(Blend.SourceAlpha);
SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
@ -526,10 +505,10 @@ namespace CodeImp.DoomBuilder.Rendering
public enum UniformName : int
{
rendersettings,
transformsettings,
projection,
desaturation,
highlightcolor,
worldviewproj,
view,
world,
modelnormal,
FillColor,
@ -542,7 +521,9 @@ namespace CodeImp.DoomBuilder.Rendering
ignoreNormals,
spotLight,
campos,
texturefactor
texturefactor,
fogsettings,
fogcolor
}
public enum VertexFormat : int { Flat, World }

View file

@ -180,7 +180,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Renderstates that count for this whole sequence
graphics.SetCullMode(Cull.None);
graphics.SetZEnable(false);
graphics.SetFogEnable(false);
graphics.SetVertexBuffer(screenverts);
worldmatrix = Matrix.Identity;
@ -474,9 +473,9 @@ namespace CodeImp.DoomBuilder.Rendering
Vector4 values = new Vector4(texelx, texely, fsaafactor, alpha);
graphics.SetUniform(UniformName.rendersettings, values);
if (flipY)
graphics.SetUniform(UniformName.transformsettings, worldmatrix * viewmatrix * Matrix.Scaling(1f, -1f, 1f));
graphics.SetUniform(UniformName.projection, worldmatrix * viewmatrix * Matrix.Scaling(1f, -1f, 1f));
else
graphics.SetUniform(UniformName.transformsettings, worldmatrix * viewmatrix);
graphics.SetUniform(UniformName.projection, worldmatrix * viewmatrix);
graphics.SetSamplerFilter(bilinear ? TextureFilter.Linear : TextureFilter.Point);
}
@ -484,13 +483,13 @@ namespace CodeImp.DoomBuilder.Rendering
{
Vector4 values = new Vector4(0.0f, 0.0f, 1.0f, alpha);
graphics.SetUniform(UniformName.rendersettings, values);
graphics.SetUniform(UniformName.transformsettings, worldmatrix * viewmatrix);
graphics.SetUniform(UniformName.projection, worldmatrix * viewmatrix);
}
//mxd. Used to render models
private void SetThings2DTransformSettings(Matrix world)
{
graphics.SetUniform(UniformName.transformsettings, world * viewmatrix);
graphics.SetUniform(UniformName.projection, world * viewmatrix);
}
/// <summary>
@ -1198,8 +1197,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetAlphaTestEnable(false);
graphics.SetFogEnable(false);
graphics.SetUniform(UniformName.texturefactor, alphacolor);
graphics.SetUniform(UniformName.texturefactor, alphacolor);
graphics.SetVertexBuffer(thingsvertices);
// Set things texture
@ -1558,8 +1556,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(true);
SetWorldTransformation(true);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
// Prepare for rendering
@ -1616,7 +1613,6 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(t);
SetWorldTransformation(transformcoords);
@ -1638,9 +1634,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(true);
SetWorldTransformation(true);
graphics.SetUniform(UniformName.FillColor, new Color4(color));
SetThings2DSettings(1.0f);
@ -1666,7 +1661,6 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(true);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(label.Texture);
SetWorldTransformation(false);
@ -1697,8 +1691,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(true);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
SetDisplay2DSettings(1f, 1f, 0f, 1f, false);
@ -1764,8 +1757,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(General.Map.Data.WhiteTexture.Texture);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1799,8 +1791,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(General.Map.Data.WhiteTexture.Texture);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1831,8 +1822,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(texture.Texture);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1930,8 +1920,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(General.Map.Data.WhiteTexture.Texture);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);
@ -1982,8 +1971,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaBlendEnable(false);
graphics.SetAlphaTestEnable(false);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetFogEnable(false);
SetWorldTransformation(false);
SetWorldTransformation(false);
graphics.SetShader(ShaderName.display2d_normal);
graphics.SetTexture(General.Map.Data.WhiteTexture.Texture);
SetDisplay2DSettings(1f, 1f, 0f, 1f, General.Settings.ClassicBilinear);

View file

@ -45,7 +45,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Matrices
private Matrix projection;
private Matrix view3d;
private Matrix viewproj; //mxd
private Matrix billboard;
private Matrix view2d;
private Matrix world;
@ -53,10 +52,6 @@ namespace CodeImp.DoomBuilder.Rendering
private Vector3D cameravector;
private ShaderName shaderpass;
// Spaghetti
Matrix viewmatrix = Matrix.Identity;
Matrix worldmatrix = Matrix.Identity;
// Window size
private Size windowsize;
@ -248,7 +243,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Make the projection matrix
projection = Matrix.PerspectiveFov(fovy, aspect, PROJ_NEAR_PLANE, General.Settings.ViewDistance);
viewproj = view3d * projection; //mxd
}
// This creates matrices for a camera view
@ -267,7 +261,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Make the view matrix
view3d = Matrix.LookAt(RenderDevice.V3(pos), RenderDevice.V3(lookat), new Vector3(0f, 0f, 1f));
viewproj = view3d * projection; //mxd
// Make the billboard matrix
billboard = Matrix.RotationZ(anglexy + Angle2D.PI);
@ -285,14 +278,9 @@ namespace CodeImp.DoomBuilder.Rendering
// This applies the matrices
private void ApplyMatrices3D()
{
graphics.SetUniform(UniformName.worldviewproj, world * viewproj); //mxd. Multiplication is ~2x faster than "world * view3d * projection";
}
// This sets the appropriate view matrix
public void ApplyMatrices2D()
{
worldmatrix = world;
viewmatrix = view2d;
graphics.SetUniform(UniformName.projection, projection);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.view, view3d);
}
#endregion
@ -312,10 +300,8 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaTestEnable(false);
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetFogEnable(false);
graphics.SetFogColor(General.Colors.Background.ToInt());
graphics.SetFogStart(General.Settings.ViewDistance * FOG_RANGE);
graphics.SetFogEnd(General.Settings.ViewDistance);
graphics.SetUniform(UniformName.fogsettings, new Vector4(-1.0f));
graphics.SetUniform(UniformName.fogcolor, General.Colors.Background.ToColorValue());
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetUniform(UniformName.highlightcolor, new Color4()); //mxd
@ -810,7 +796,6 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Set variables for fog rendering?
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
}
}
@ -915,7 +900,6 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Set variables for fog rendering?
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, t.FogFactor));
}
@ -1083,7 +1067,6 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Set variables for fog rendering?
if (wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
}
}
@ -1221,7 +1204,6 @@ namespace CodeImp.DoomBuilder.Rendering
//mxd. Set variables for fog rendering?
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
if (t.FogFactor != fogfactor)
{
@ -1456,7 +1438,6 @@ namespace CodeImp.DoomBuilder.Rendering
{
if (geometrytolit.Count == 0) return;
graphics.SetUniform(UniformName.world, Matrix.Identity);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetShader(ShaderName.world3d_lightpass);
graphics.SetAlphaBlendEnable(true);
@ -1480,7 +1461,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Anything to do?
if (geometrytolit.Count == 0) return;
graphics.SetUniform(UniformName.world, Matrix.Identity);
graphics.SetUniform(UniformName.modelnormal, Matrix.Identity);
graphics.SetShader(ShaderName.world3d_lightpass);
graphics.SetAlphaBlendEnable(true);
@ -1602,7 +1582,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Set variables for fog rendering
if(wantedshaderpass > ShaderName.world3d_p7)
{
graphics.SetUniform(UniformName.world, world);
// this is not right...
graphics.SetUniform(UniformName.modelnormal, General.Map.Data.ModeldefEntries[t.Thing.Type].TransformRotation * modelrotation);
if (t.Thing.Sector != null) graphics.SetUniform(UniformName.lightColor, t.Thing.Sector.FogColor);
@ -1756,7 +1735,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Set render settings
graphics.SetShader(ShaderName.world3d_skybox);
graphics.SetTexture(General.Map.Data.SkyBox);
graphics.SetUniform(UniformName.world, world);
graphics.SetUniform(UniformName.campos, new Vector4(cameraposition.x, cameraposition.y, cameraposition.z, 0f));
foreach(VisualGeometry g in geo)
@ -2013,14 +1991,14 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.SetAlphaTestEnable(false);
graphics.SetSourceBlend(Blend.SourceAlpha);
graphics.SetDestinationBlend(Blend.InverseSourceAlpha);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
worldmatrix = Matrix.Identity;
ApplyMatrices2D();
graphics.SetShader(ShaderName.display2d_normal);
// Texture
if(crosshairbusy)
graphics.SetUniform(UniformName.projection, world * view2d);
graphics.SetUniform(UniformName.texturefactor, new Color4(1f, 1f, 1f, 1f));
graphics.SetUniform(UniformName.rendersettings, new Vector4(1.0f, 1.0f, 0.0f, 1.0f));
graphics.SetSamplerFilter(TextureFilter.Linear);
// Texture
if (crosshairbusy)
{
if(General.Map.Data.CrosshairBusy3D.Texture == null) General.Map.Data.CrosshairBusy3D.CreateTexture();
graphics.SetTexture(General.Map.Data.CrosshairBusy3D.Texture);
@ -2032,22 +2010,20 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Draw
SetDisplay2DSettings(1.0f, 1.0f, 0.0f, 1.0f, true);
graphics.Draw(PrimitiveType.TriangleStrip, 0, 2, crosshairverts);
graphics.Draw(PrimitiveType.TriangleStrip, 0, 2, crosshairverts);
}
private void SetDisplay2DSettings(float texelx, float texely, float fsaafactor, float alpha, bool bilinear)
{
Vector4 values = new Vector4(texelx, texely, fsaafactor, alpha);
graphics.SetUniform(UniformName.rendersettings, values);
graphics.SetUniform(UniformName.transformsettings, worldmatrix * viewmatrix);
graphics.SetSamplerFilter(bilinear ? TextureFilter.Linear : TextureFilter.Point);
}
// This switches fog on and off
public void SetFogMode(bool usefog)
{
graphics.SetFogEnable(usefog);
if (usefog)
{
graphics.SetUniform(UniformName.fogsettings, new Vector4(General.Settings.ViewDistance * FOG_RANGE, General.Settings.ViewDistance, 0.0f, 0.0f));
}
else
{
graphics.SetUniform(UniformName.fogsettings, new Vector4(-1.0f));
}
}
// This siwtches crosshair busy icon on and off

View file

@ -426,10 +426,10 @@ void RenderDevice::SetShader(ShaderName name)
static const int uniformLocations[(int)UniformName::NumUniforms] = {
64, // rendersettings
0, // transformsettings
0, // projection
108, // desaturation
80, // highlightcolor
16, // worldviewproj
16, // view
32, // world
48, // modelnormal
68, // FillColor
@ -443,6 +443,8 @@ static const int uniformLocations[(int)UniformName::NumUniforms] = {
110, // spotLight
76, // campos,
112, // texturefactor
116, // fogsettings
120, // fogcolor
};
void RenderDevice::SetUniform(UniformName name, const void* values, int count)
@ -564,8 +566,8 @@ void RenderDevice::ApplyUniforms()
Shader* shader = GetActiveShader();
auto& locations = shader->UniformLocations;
glUniformMatrix4fv(locations[(int)UniformName::transformsettings], 1, GL_FALSE, &mUniforms[0].valuef);
glUniformMatrix4fv(locations[(int)UniformName::worldviewproj], 1, GL_FALSE, &mUniforms[16].valuef);
glUniformMatrix4fv(locations[(int)UniformName::projection], 1, GL_FALSE, &mUniforms[0].valuef);
glUniformMatrix4fv(locations[(int)UniformName::view], 1, GL_FALSE, &mUniforms[16].valuef);
glUniformMatrix4fv(locations[(int)UniformName::world], 1, GL_FALSE, &mUniforms[32].valuef);
glUniformMatrix4fv(locations[(int)UniformName::modelnormal], 1, GL_FALSE, &mUniforms[48].valuef);
@ -586,6 +588,8 @@ void RenderDevice::ApplyUniforms()
glUniform1fv(locations[(int)UniformName::spotLight], 1, &mUniforms[110].valuef);
glUniform4fv(locations[(int)UniformName::texturefactor], 1, &mUniforms[112].valuef);
glUniform4fv(locations[(int)UniformName::fogsettings], 1, &mUniforms[116].valuef);
glUniform4fv(locations[(int)UniformName::fogcolor], 1, &mUniforms[120].valuef);
mUniformsChanged = false;
}

View file

@ -52,10 +52,10 @@ enum class ShaderName
enum class UniformName : int
{
rendersettings,
transformsettings,
projection,
desaturation,
highlightcolor,
worldviewproj,
view,
world,
modelnormal,
FillColor,
@ -69,6 +69,8 @@ enum class UniformName : int
spotLight,
campos,
texturefactor,
fogsettings,
fogcolor,
NumUniforms
};
@ -158,7 +160,7 @@ public:
int32_t valuei;
};
UniformEntry mUniforms[4 * 16 + 13 * 4];
UniformEntry mUniforms[4 * 16 + 15 * 4];
GLuint mStreamVertexBuffer = 0;
GLuint mStreamVAO = 0;

View file

@ -83,10 +83,10 @@ void Shader::CreateProgram()
static const char* names[(int)UniformName::NumUniforms] = {
"rendersettings",
"transformsettings",
"projection",
"desaturation",
"highlightcolor",
"worldviewproj",
"view",
"world",
"modelnormal",
"fillColor",
@ -99,7 +99,9 @@ void Shader::CreateProgram()
"ignoreNormals",
"spotLight",
"campos",
"texturefactor"
"texturefactor",
"fogsettings",
"fogcolor"
};
for (int i = 0; i < (int)UniformName::NumUniforms; i++)

View file

@ -8,11 +8,11 @@ static const char* display2D_vs = R"(
out vec4 Color;
out vec2 UV;
uniform mat4 transformsettings;
uniform mat4 projection;
void main()
{
gl_Position = transformsettings * vec4(AttrPosition, 1.0f);
gl_Position = projection * vec4(AttrPosition, 1.0f);
Color = AttrColor;
UV = AttrUV;
}

View file

@ -8,11 +8,11 @@ static const char* plotter_vs = R"(
out vec4 Color;
out vec2 UV;
uniform mat4 transformsettings;
uniform mat4 projection;
void main()
{
gl_Position = transformsettings * vec4(AttrPosition, 1.0f);
gl_Position = projection * vec4(AttrPosition, 1.0f);
Color = AttrColor;
UV = AttrUV;
}

View file

@ -8,11 +8,11 @@ static const char* things2D_vs = R"(
out vec4 Color;
out vec2 UV;
uniform mat4 transformsettings;
uniform mat4 projection;
void main()
{
gl_Position = transformsettings * vec4(AttrPosition, 1.0f);
gl_Position = projection * vec4(AttrPosition, 1.0f);
Color = AttrColor;
UV = AttrUV;
}

View file

@ -8,12 +8,16 @@ static const char* world3D_vs_main = R"(
out vec4 Color;
out vec2 UV;
out vec4 viewpos;
uniform mat4 worldviewproj;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
viewpos = view * world * vec4(AttrPosition, 1.0);
gl_Position = projection * viewpos;
Color = AttrColor;
UV = AttrUV;
}
@ -27,13 +31,18 @@ static const char* world3D_vs_customvertexcolor = R"(
out vec4 Color;
out vec2 UV;
out vec4 viewpos;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 worldviewproj;
uniform vec4 vertexColor;
void main()
{
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
viewpos = view * world * vec4(AttrPosition, 1.0);
gl_Position = projection * viewpos;
Color = vertexColor;
UV = AttrUV;
}
@ -49,15 +58,19 @@ static const char* world3D_vs_customvertexcolor_fog = R"(
out vec2 UV;
out vec3 PosW;
out vec3 Normal;
out vec4 viewpos;
uniform mat4 worldviewproj;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 modelnormal;
uniform vec4 vertexColor;
void main()
{
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
viewpos = view * world * vec4(AttrPosition, 1.0);
gl_Position = projection * viewpos;
PosW = (world * vec4(AttrPosition, 1.0)).xyz;
Color = vertexColor;
UV = AttrUV;
@ -75,14 +88,17 @@ static const char* world3D_vs_lightpass = R"(
out vec2 UV;
out vec3 PosW;
out vec3 Normal;
out vec4 viewpos;
uniform mat4 worldviewproj;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 modelnormal;
void main()
{
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
viewpos = view * world * vec4(AttrPosition, 1.0);
gl_Position = projection * viewpos;
PosW = (world * vec4(AttrPosition, 1.0)).xyz;
Color = AttrColor;
UV = AttrUV;
@ -95,14 +111,18 @@ static const char* world3D_vs_skybox = R"(
in vec2 AttrUV;
out vec3 Tex;
out vec4 viewpos;
uniform mat4 worldviewproj;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
uniform vec4 campos; //w is set to fade factor (distance, at wich fog color completely overrides pixel color)
void main()
{
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
viewpos = view * world * vec4(AttrPosition, 1.0);
gl_Position = projection * viewpos;
vec3 worldpos = (world * vec4(AttrPosition, 1.0)).xyz;
vec4 skynormal = vec4(0.0, 1.0, 0.0, 0.0);
vec3 normal = normalize((world * skynormal).xyz);
@ -113,12 +133,16 @@ static const char* world3D_vs_skybox = R"(
static const char* world3D_ps_main = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
uniform vec4 stencilColor;
uniform float desaturation;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform sampler2D texture1;
vec4 desaturate(vec4 texel)
@ -136,17 +160,23 @@ static const char* world3D_ps_main = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
static const char* world3D_ps_fullbright = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
uniform vec4 stencilColor;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform sampler2D texture1;
void main()
@ -159,12 +189,15 @@ static const char* world3D_ps_fullbright = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
static const char* world3D_ps_main_highlight = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
@ -172,6 +205,9 @@ static const char* world3D_ps_main_highlight = R"(
uniform vec4 stencilColor;
uniform float desaturation;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform sampler2D texture1;
vec4 desaturate(vec4 texel)
@ -199,12 +235,15 @@ static const char* world3D_ps_main_highlight = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
static const char* world3D_ps_fullbright_highlight = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
@ -213,6 +252,9 @@ static const char* world3D_ps_fullbright_highlight = R"(
uniform sampler2D texture1;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
void main()
{
vec4 tcolor = texture(texture1, UV);
@ -232,6 +274,8 @@ static const char* world3D_ps_fullbright_highlight = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
@ -240,6 +284,7 @@ static const char* world3D_ps_main_fog = R"(
in vec2 UV;
in vec3 PosW;
in vec3 Normal;
in vec4 viewpos;
out vec4 FragColor;
@ -248,6 +293,9 @@ static const char* world3D_ps_main_fog = R"(
uniform float desaturation;
uniform vec4 campos; //w is set to fade factor (distance, at wich fog color completely overrides pixel color)
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform sampler2D texture1;
// This adds fog color to current pixel color
@ -282,6 +330,8 @@ static const char* world3D_ps_main_fog = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
@ -290,6 +340,7 @@ static const char* world3D_ps_main_highlight_fog = R"(
in vec2 UV;
in vec3 PosW;
in vec3 Normal;
in vec4 viewpos;
out vec4 FragColor;
@ -299,6 +350,9 @@ static const char* world3D_ps_main_highlight_fog = R"(
uniform float desaturation;
uniform vec4 campos; //w is set to fade factor (distance, at wich fog color completely overrides pixel color)
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform sampler2D texture1;
// This adds fog color to current pixel color
@ -336,17 +390,23 @@ static const char* world3D_ps_main_highlight_fog = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
static const char* world3D_ps_constant_color = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
uniform vec4 vertexColor;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
void main()
{
FragColor = vertexColor;
@ -354,15 +414,21 @@ static const char* world3D_ps_constant_color = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
static const char* world3D_ps_vertex_color = R"(
in vec4 Color;
in vec2 UV;
in vec4 viewpos;
out vec4 FragColor;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
void main()
{
FragColor = Color;
@ -370,6 +436,8 @@ static const char* world3D_ps_vertex_color = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";
@ -451,11 +519,15 @@ static const char* world3D_ps_lightpass = R"(
static const char* world3D_ps_skybox = R"(
in vec3 Tex;
in vec4 viewpos;
out vec4 FragColor;
uniform vec4 highlightcolor;
uniform vec4 fogsettings;
uniform vec4 fogcolor;
uniform samplerCube texture1;
void main()
@ -466,5 +538,7 @@ static const char* world3D_ps_skybox = R"(
#if defined(ALPHA_TEST)
if (FragColor.a < 0.5) discard;
#endif
if (fogsettings.x >= 0.0f) FragColor = mix(FragColor, fogcolor, clamp((-viewpos.z - fogsettings.x) / (fogsettings.y - fogsettings.x), 0.0, 1.0));
}
)";