mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-26 05:41:45 +00:00
- port all the direct3d shaders to glsl
This commit is contained in:
parent
14fd3c96e1
commit
3c44f77b60
13 changed files with 892 additions and 72 deletions
|
@ -411,24 +411,24 @@ namespace CodeImp.DoomBuilder.Rendering
|
|||
things2d_thing,
|
||||
things2d_sprite,
|
||||
things2d_fill,
|
||||
world3d_main, // 0
|
||||
world3d_fullbright, // 1
|
||||
world3d_main_highlight, // 2
|
||||
world3d_fullbright_highlight, // 3
|
||||
world3d_main_vertexcolor, // 4
|
||||
world3d_skybox, // 5
|
||||
world3d_main_highlight_vertexcolor, // 6
|
||||
world3d_main,
|
||||
world3d_fullbright,
|
||||
world3d_main_highlight,
|
||||
world3d_fullbright_highlight,
|
||||
world3d_main_vertexcolor,
|
||||
world3d_skybox,
|
||||
world3d_main_highlight_vertexcolor,
|
||||
world3d_p7,
|
||||
world3d_main_fog, // 8
|
||||
world3d_main_fog,
|
||||
world3d_p9,
|
||||
world3d_main_highlight_fog, // 10
|
||||
world3d_main_highlight_fog,
|
||||
world3d_p11,
|
||||
world3d_main_fog_vertexcolor, // 12
|
||||
world3d_main_fog_vertexcolor,
|
||||
world3d_p13,
|
||||
world3d_main_highlight_fog_vertexcolor, // 14
|
||||
world3d_vertex_color, // 15
|
||||
world3d_constant_color, // 16
|
||||
world3d_lightpass // 17 // AlphaBlendEnable = true
|
||||
world3d_main_highlight_fog_vertexcolor,
|
||||
world3d_vertex_color,
|
||||
world3d_constant_color,
|
||||
world3d_lightpass // AlphaBlendEnable = true
|
||||
}
|
||||
|
||||
public enum Uniform : int
|
||||
|
|
|
@ -208,6 +208,7 @@
|
|||
</ClCompile>
|
||||
<ClCompile Include="RenderDevice.cpp" />
|
||||
<ClCompile Include="Shader.cpp" />
|
||||
<ClCompile Include="ShaderManager.cpp" />
|
||||
<ClCompile Include="Texture.cpp" />
|
||||
<ClCompile Include="VertexBuffer.cpp" />
|
||||
<ClCompile Include="VertexDeclaration.cpp" />
|
||||
|
@ -220,6 +221,11 @@
|
|||
<ClInclude Include="Precomp.h" />
|
||||
<ClInclude Include="RenderDevice.h" />
|
||||
<ClInclude Include="Shader.h" />
|
||||
<ClInclude Include="ShaderDefault.h" />
|
||||
<ClInclude Include="ShaderDisplay2D.h" />
|
||||
<ClInclude Include="ShaderManager.h" />
|
||||
<ClInclude Include="ShaderThings2D.h" />
|
||||
<ClInclude Include="ShaderWorld3D.h" />
|
||||
<ClInclude Include="Texture.h" />
|
||||
<ClInclude Include="VertexBuffer.h" />
|
||||
<ClInclude Include="VertexDeclaration.h" />
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<ClCompile Include="OpenGLContext.cpp" />
|
||||
<ClCompile Include="Precomp.cpp" />
|
||||
<ClCompile Include="Shader.cpp" />
|
||||
<ClCompile Include="ShaderManager.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="IndexBuffer.h" />
|
||||
|
@ -28,6 +29,11 @@
|
|||
<ClInclude Include="OpenGLContext.h" />
|
||||
<ClInclude Include="Precomp.h" />
|
||||
<ClInclude Include="Shader.h" />
|
||||
<ClInclude Include="ShaderThings2D.h" />
|
||||
<ClInclude Include="ShaderWorld3D.h" />
|
||||
<ClInclude Include="ShaderDefault.h" />
|
||||
<ClInclude Include="ShaderManager.h" />
|
||||
<ClInclude Include="ShaderDisplay2D.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="exports.def" />
|
||||
|
|
|
@ -5,65 +5,27 @@
|
|||
#include "IndexBuffer.h"
|
||||
#include "VertexDeclaration.h"
|
||||
#include "Texture.h"
|
||||
#include "Shader.h"
|
||||
#include "ShaderManager.h"
|
||||
#include <stdexcept>
|
||||
|
||||
const char* mainVertexShader = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 World;
|
||||
uniform mat4 View;
|
||||
uniform mat4 Projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
Normal = AttrNormal;
|
||||
gl_Position = Projection * View * World * AttrPosition;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* mainFragmentShader = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(UV, 1.0, 1.0);
|
||||
}
|
||||
)";
|
||||
|
||||
RenderDevice::RenderDevice(HWND hwnd) : Context(hwnd)
|
||||
{
|
||||
if (Context)
|
||||
{
|
||||
Context.Begin();
|
||||
mShader = std::make_unique<Shader>();
|
||||
if (!mShader->Compile(mainVertexShader, mainFragmentShader))
|
||||
{
|
||||
throw std::runtime_error(mShader->GetErrors());
|
||||
}
|
||||
mShaderManager = std::make_unique<ShaderManager>();
|
||||
Context.End();
|
||||
}
|
||||
}
|
||||
|
||||
RenderDevice::~RenderDevice()
|
||||
{
|
||||
if (Context)
|
||||
{
|
||||
Context.Begin();
|
||||
mShaderManager->ReleaseResources();
|
||||
Context.End();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderDevice::SetVertexBuffer(int index, VertexBuffer* buffer, long offset, long stride)
|
||||
|
@ -250,7 +212,7 @@ void RenderDevice::ApplyChanges()
|
|||
|
||||
void RenderDevice::ApplyShader()
|
||||
{
|
||||
glUseProgram(mShader->GetProgram());
|
||||
//glUseProgram(mShader->GetProgram());
|
||||
}
|
||||
|
||||
void RenderDevice::ApplyRasterizerState()
|
||||
|
@ -363,7 +325,7 @@ void RenderDevice::ApplyMatrices()
|
|||
for (size_t i = 0; i < (size_t)TransformState::NumTransforms; i++)
|
||||
{
|
||||
auto& binding = mTransforms[i];
|
||||
glUniformMatrix4fv(mShader->TransformLocations[i], 1, GL_FALSE, binding.Values);
|
||||
//glUniformMatrix4fv(mShader->TransformLocations[i], 1, GL_FALSE, binding.Values);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class VertexBuffer;
|
|||
class IndexBuffer;
|
||||
class VertexDeclaration;
|
||||
class Texture;
|
||||
class Shader;
|
||||
class ShaderManager;
|
||||
enum class CubeMapFace;
|
||||
|
||||
enum class Cull : int { None, Counterclockwise };
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
|
||||
IndexBuffer* mIndexBuffer = nullptr;
|
||||
|
||||
std::unique_ptr<Shader> mShader;
|
||||
std::unique_ptr<ShaderManager> mShaderManager;
|
||||
|
||||
Cull mCullMode = Cull::None;
|
||||
FillMode mFillMode = FillMode::Solid;
|
||||
|
|
|
@ -5,13 +5,17 @@
|
|||
#include "RenderDevice.h"
|
||||
#include <stdexcept>
|
||||
|
||||
Shader::Shader()
|
||||
void Shader::ReleaseResources()
|
||||
{
|
||||
}
|
||||
|
||||
Shader::~Shader()
|
||||
{
|
||||
// To do: move to delete list
|
||||
if (mProgram)
|
||||
glDeleteProgram(mProgram);
|
||||
if (mVertexShader)
|
||||
glDeleteShader(mVertexShader);
|
||||
if (mFragmentShader)
|
||||
glDeleteShader(mFragmentShader);
|
||||
mProgram = 0;
|
||||
mVertexShader = 0;
|
||||
mFragmentShader = 0;
|
||||
}
|
||||
|
||||
bool Shader::Compile(const std::string& vertexShader, const std::string& fragmentShader)
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
class Shader
|
||||
{
|
||||
public:
|
||||
Shader();
|
||||
~Shader();
|
||||
Shader() = default;
|
||||
void ReleaseResources();
|
||||
|
||||
bool Compile(const std::string& vertexShader, const std::string& fragmentShader);
|
||||
const char* GetErrors() const { return mErrors.c_str(); }
|
||||
|
|
41
Source/Native/ShaderDefault.h
Normal file
41
Source/Native/ShaderDefault.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
static const char* default_vs = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 World;
|
||||
uniform mat4 View;
|
||||
uniform mat4 Projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
Normal = AttrNormal;
|
||||
gl_Position = Projection * View * World * AttrPosition;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* default_ps = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(UV, 1.0, 1.0);
|
||||
}
|
||||
)";
|
133
Source/Native/ShaderDisplay2D.h
Normal file
133
Source/Native/ShaderDisplay2D.h
Normal file
|
@ -0,0 +1,133 @@
|
|||
#pragma once
|
||||
|
||||
static const char* display2D_vs = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPos;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
|
||||
uniform mat4 transformsettings;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformsettings * vec4(AttrPos, 1.0f);
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* display2D_ps_fsaa = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Render settings
|
||||
// x = texel width
|
||||
// y = texel height
|
||||
// z = FSAA blend factor
|
||||
// w = transparency
|
||||
uniform vec4 rendersettings;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
// This blends the max of 2 pixels
|
||||
vec4 addcolor(vec4 c1, vec4 c2)
|
||||
{
|
||||
return vec4(
|
||||
max(c1.r, c2.r),
|
||||
max(c1.g, c2.g),
|
||||
max(c1.b, c2.b),
|
||||
clamp(c1.a + c2.a * 0.5, 0.0, 1.0));
|
||||
}
|
||||
|
||||
vec3 desaturate(vec3 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return mix(texel, vec3(gray), desaturation);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(texture1, UV);
|
||||
|
||||
// If this pixel is not drawn on...
|
||||
if(c.a < 0.1f)
|
||||
{
|
||||
// Mix the colors of nearby pixels
|
||||
vec4 n = vec4(0.0);
|
||||
n = addcolor(n, texture(texture1, vec2(UV.x + rendersettings.x, UV.y)));
|
||||
n = addcolor(n, texture(texture1, vec2(UV.x - rendersettings.x, UV.y)));
|
||||
n = addcolor(n, texture(texture1, vec2(UV.x, UV.y + rendersettings.y)));
|
||||
n = addcolor(n, texture(texture1, vec2(UV.x, UV.y - rendersettings.y)));
|
||||
|
||||
FragColor = vec4(desaturate(n.rgb), n.a * rendersettings.z * rendersettings.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
const char* display2D_ps_normal = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Render settings
|
||||
// x = texel width
|
||||
// y = texel height
|
||||
// z = FSAA blend factor
|
||||
// w = transparency
|
||||
uniform vec4 rendersettings;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec3 desaturate(vec3 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return mix(texel, vec3(gray), desaturation);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(texture1, UV);
|
||||
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* display2D_ps_fullbright = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Render settings
|
||||
// x = texel width
|
||||
// y = texel height
|
||||
// z = FSAA blend factor
|
||||
// w = transparency
|
||||
uniform vec4 rendersettings;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(texture1, UV);
|
||||
FragColor = vec4(c.rgb, c.a * rendersettings.w);
|
||||
}
|
||||
)";
|
57
Source/Native/ShaderManager.cpp
Normal file
57
Source/Native/ShaderManager.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
|
||||
#include "Precomp.h"
|
||||
#include "ShaderManager.h"
|
||||
#include "ShaderDefault.h"
|
||||
#include "ShaderDisplay2D.h"
|
||||
#include "ShaderThings2D.h"
|
||||
#include "ShaderWorld3D.h"
|
||||
#include <stdexcept>
|
||||
|
||||
struct ShaderPair { const char* vs; const char* ps; };
|
||||
|
||||
static const ShaderPair ShaderSources[(int)ShaderName::count] = {
|
||||
{ default_vs, default_ps },
|
||||
{ display2D_vs, display2D_ps_fsaa },
|
||||
{ display2D_vs, display2D_ps_normal },
|
||||
{ display2D_vs, display2D_ps_fullbright },
|
||||
{ things2D_vs, things2D_ps_thing },
|
||||
{ things2D_vs, things2D_ps_sprite },
|
||||
{ things2D_vs, things2D_ps_fill },
|
||||
{ world3D_vs_main, world3D_ps_main },
|
||||
{ world3D_vs_main, world3D_ps_fullbright },
|
||||
{ world3D_vs_main, world3D_ps_main_highlight },
|
||||
{ world3D_vs_main, world3D_ps_fullbright_highlight },
|
||||
{ world3D_vs_customvertexcolor, world3D_ps_main },
|
||||
{ world3D_vs_skybox, world3D_ps_skybox },
|
||||
{ world3D_vs_customvertexcolor, world3D_ps_main_highlight },
|
||||
{ nullptr, nullptr },
|
||||
{ world3D_vs_lightpass, world3D_ps_main_fog },
|
||||
{ nullptr, nullptr },
|
||||
{ world3D_vs_lightpass, world3D_ps_main_highlight_fog },
|
||||
{ nullptr, nullptr },
|
||||
{ world3D_vs_customvertexcolor_fog, world3D_ps_main_fog },
|
||||
{ nullptr, nullptr },
|
||||
{ world3D_vs_customvertexcolor_fog, world3D_ps_main_highlight_fog },
|
||||
{ world3D_vs_main, world3D_ps_vertex_color },
|
||||
{ world3D_vs_customvertexcolor, world3D_ps_constant_color },
|
||||
{ world3D_vs_lightpass, world3D_ps_lightpass }
|
||||
};
|
||||
|
||||
ShaderManager::ShaderManager()
|
||||
{
|
||||
for (int i = 0; i < (int)ShaderName::count; i++)
|
||||
{
|
||||
if (ShaderSources[i].vs && ShaderSources[i].ps)
|
||||
{
|
||||
if (!mShaders[i].Compile(ShaderSources[i].vs, ShaderSources[i].ps))
|
||||
{
|
||||
CompileErrors += "Could not compile " + std::to_string(i) + "\r\n";
|
||||
CompileErrors += mShaders[i].GetErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderManager::ReleaseResources()
|
||||
{
|
||||
}
|
46
Source/Native/ShaderManager.h
Normal file
46
Source/Native/ShaderManager.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "Shader.h"
|
||||
|
||||
enum class ShaderName
|
||||
{
|
||||
basic,
|
||||
display2d_fsaa,
|
||||
display2d_normal,
|
||||
display2d_fullbright,
|
||||
things2d_thing,
|
||||
things2d_sprite,
|
||||
things2d_fill,
|
||||
world3d_main,
|
||||
world3d_fullbright,
|
||||
world3d_main_highlight,
|
||||
world3d_fullbright_highlight,
|
||||
world3d_main_vertexcolor,
|
||||
world3d_skybox,
|
||||
world3d_main_highlight_vertexcolor,
|
||||
world3d_p7,
|
||||
world3d_main_fog,
|
||||
world3d_p9,
|
||||
world3d_main_highlight_fog,
|
||||
world3d_p11,
|
||||
world3d_main_fog_vertexcolor,
|
||||
world3d_p13,
|
||||
world3d_main_highlight_fog_vertexcolor,
|
||||
world3d_vertex_color,
|
||||
world3d_constant_color,
|
||||
world3d_lightpass, // AlphaBlendEnable = true
|
||||
count
|
||||
};
|
||||
|
||||
class ShaderManager
|
||||
{
|
||||
public:
|
||||
ShaderManager();
|
||||
|
||||
void ReleaseResources();
|
||||
|
||||
std::string CompileErrors;
|
||||
|
||||
private:
|
||||
Shader mShaders[(int)ShaderName::count];
|
||||
};
|
105
Source/Native/ShaderThings2D.h
Normal file
105
Source/Native/ShaderThings2D.h
Normal file
|
@ -0,0 +1,105 @@
|
|||
#pragma once
|
||||
|
||||
static const char* things2D_vs = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
|
||||
uniform mat4 transformsettings;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformsettings * vec4(AttrPosition, 1.0f);
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* things2D_ps_sprite = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Render settings
|
||||
// w = transparency
|
||||
uniform vec4 rendersettings;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec3 desaturate(vec3 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return mix(texel, vec3(gray), desaturation);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Take this pixel's color
|
||||
vec4 c = texture(texture1, UV);
|
||||
|
||||
// Modulate it by selection color
|
||||
if (Color.a > 0.0)
|
||||
{
|
||||
vec3 cr = desaturate(c.rgb);
|
||||
FragColor = vec4((cr.r + Color.r) / 2.0f, (cr.g + Color.g) / 2.0f, (cr.b + Color.b) / 2.0f, c.a * rendersettings.w * Color.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Or leave it as it is
|
||||
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w);
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* things2D_ps_thing = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
// Render settings
|
||||
// w = transparency
|
||||
uniform vec4 rendersettings;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec3 desaturate(vec3 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return mix(texel, vec3(gray), desaturation);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 c = texture(texture1, UV);
|
||||
FragColor = vec4(desaturate(c.rgb), c.a * rendersettings.w) * Color;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* things2D_ps_fill = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 fillColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = fillColor;
|
||||
}
|
||||
)";
|
460
Source/Native/ShaderWorld3D.h
Normal file
460
Source/Native/ShaderWorld3D.h
Normal file
|
@ -0,0 +1,460 @@
|
|||
#pragma once
|
||||
|
||||
static const char* world3D_vs_main = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
|
||||
uniform mat4 worldviewproj;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_vs_customvertexcolor = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
|
||||
uniform mat4 worldviewproj;
|
||||
uniform vec4 vertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
|
||||
Color = vertexColor;
|
||||
UV = AttrUV;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_vs_customvertexcolor_fog = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
out vec3 PosW;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 worldviewproj;
|
||||
uniform mat4 world;
|
||||
uniform mat4 modelnormal;
|
||||
uniform vec4 vertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
|
||||
PosW = (world * vec4(AttrPosition, 1.0)).xyz;
|
||||
Color = vertexColor;
|
||||
UV = AttrUV;
|
||||
Normal = normalize((modelnormal * vec4(AttrNormal, 1.0)).xyz);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_vs_lightpass = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec4 AttrColor;
|
||||
in vec2 AttrUV;
|
||||
in vec3 AttrNormal;
|
||||
|
||||
out vec4 Color;
|
||||
out vec2 UV;
|
||||
out vec3 PosW;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 worldviewproj;
|
||||
uniform mat4 world;
|
||||
uniform mat4 modelnormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = worldviewproj * vec4(AttrPosition, 1.0);
|
||||
PosW = (world * vec4(AttrPosition, 1.0)).xyz;
|
||||
Color = AttrColor;
|
||||
UV = AttrUV;
|
||||
Normal = normalize((modelnormal * vec4(AttrNormal, 1.0)).xyz);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_vs_skybox = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 AttrPosition;
|
||||
in vec2 AttrUV;
|
||||
|
||||
out vec3 Tex;
|
||||
|
||||
uniform mat4 worldviewproj;
|
||||
uniform mat4 world;
|
||||
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);
|
||||
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);
|
||||
Tex = reflect(worldpos - campos.xyz, normal);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_main = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 stencilColor;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec4 desaturate(vec4 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return vec4(mix(texel.rgb, vec3(gray), desaturation), texel.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
FragColor = desaturate(tcolor * Color);
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_fullbright = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 stencilColor;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
tcolor.a *= Color.a;
|
||||
FragColor = tcolor;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_main_highlight = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 highlightcolor;
|
||||
uniform vec4 stencilColor;
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec4 desaturate(vec4 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return vec4(mix(texel.rgb, vec3(gray), desaturation), texel.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
if (tcolor.a == 0.0)
|
||||
{
|
||||
FragColor = tcolor;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blend texture color and vertex color
|
||||
vec4 ncolor = desaturate(tcolor * Color);
|
||||
|
||||
FragColor = vec4(highlightcolor.rgb * highlightcolor.a + (ncolor.rgb - 0.4 * highlightcolor.a), max(Color.a + 0.25, 0.5));
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_fullbright_highlight = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 highlightcolor;
|
||||
uniform vec4 stencilColor;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
if(tcolor.a == 0.0)
|
||||
{
|
||||
FragColor = tcolor;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blend texture color and vertex color
|
||||
vec4 ncolor = tcolor * Color;
|
||||
|
||||
FragColor = vec4(highlightcolor.rgb * highlightcolor.a + (tcolor.rgb - 0.4 * highlightcolor.a), max(Color.a + 0.25, 0.5));
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_main_fog = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
in vec3 PosW;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 stencilColor;
|
||||
uniform vec4 lightColor;
|
||||
uniform float desaturation;
|
||||
uniform vec4 campos; //w is set to fade factor (distance, at wich fog color completely overrides pixel color)
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
// This adds fog color to current pixel color
|
||||
vec4 getFogColor(vec4 color)
|
||||
{
|
||||
float fogdist = max(16.0, distance(PosW, campos.xyz));
|
||||
float fogfactor = exp2(campos.w * fogdist);
|
||||
|
||||
color.rgb = mix(lightColor.rgb, color.rgb, fogfactor);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 desaturate(vec4 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return vec4(mix(texel.rgb, vec3(gray), desaturation), texel.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
if (tcolor.a == 0.0)
|
||||
{
|
||||
FragColor = tcolor;
|
||||
}
|
||||
else
|
||||
{
|
||||
FragColor = desaturate(getFogColor(tcolor * Color));
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_main_highlight_fog = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
in vec3 PosW;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 highlightcolor;
|
||||
uniform vec4 stencilColor;
|
||||
uniform vec4 lightColor;
|
||||
uniform float desaturation;
|
||||
uniform vec4 campos; //w is set to fade factor (distance, at wich fog color completely overrides pixel color)
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
// This adds fog color to current pixel color
|
||||
vec4 getFogColor(vec4 color)
|
||||
{
|
||||
float fogdist = max(16.0, distance(PosW, campos.xyz));
|
||||
float fogfactor = exp2(campos.w * fogdist);
|
||||
|
||||
color.rgb = mix(lightColor.rgb, color.rgb, fogfactor);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 desaturate(vec4 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return vec4(mix(texel.rgb, vec3(gray), desaturation), texel.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
if (tcolor.a == 0.0)
|
||||
{
|
||||
FragColor = tcolor;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blend texture color and vertex color
|
||||
vec4 ncolor = desaturate(getFogColor(tcolor * Color));
|
||||
|
||||
FragColor = vec4(highlightcolor.rgb * highlightcolor.a + (ncolor.rgb - 0.4 * highlightcolor.a), max(ncolor.a + 0.25, 0.5));
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_constant_color = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 vertexColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vertexColor;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_vertex_color = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = Color;
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_lightpass = R"(
|
||||
#version 150
|
||||
|
||||
in vec4 Color;
|
||||
in vec2 UV;
|
||||
in vec3 PosW;
|
||||
in vec3 Normal;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 stencilColor;
|
||||
uniform vec4 lightPosAndRadius;
|
||||
uniform vec3 lightOrientation; // this is a vector that points in light's direction
|
||||
uniform vec2 light2Radius; // this is used with spotlights
|
||||
uniform vec4 lightColor;
|
||||
uniform float ignoreNormals; // ignore normals in lighting equation. used for non-attenuated lights on models.
|
||||
uniform float spotLight; // use lightOrientation
|
||||
uniform float desaturation;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
vec4 desaturate(vec4 texel)
|
||||
{
|
||||
float gray = (texel.r * 0.3 + texel.g * 0.56 + texel.b * 0.14);
|
||||
return vec4(mix(texel.rgb, vec3(gray), desaturation), texel.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
//is face facing away from light source?
|
||||
// update 01.02.2017: offset the equation by 3px back to try to emulate GZDoom's broken visibility check.
|
||||
float diffuseContribution = dot(Normal, normalize(lightPosAndRadius.xyz - PosW + Normal * 3.0));
|
||||
if (diffuseContribution < 0.0 && ignoreNormals < 0.5)
|
||||
discard;
|
||||
diffuseContribution = max(diffuseContribution, 0.0); // to make sure
|
||||
|
||||
//is pixel in light range?
|
||||
float dist = distance(PosW, lightPosAndRadius.xyz);
|
||||
if (dist > lightPosAndRadius.w)
|
||||
discard;
|
||||
|
||||
//is pixel tranparent?
|
||||
vec4 tcolor = texture(texture1, UV);
|
||||
tcolor = mix(tcolor, vec4(stencilColor.rgb, tcolor.a), stencilColor.a);
|
||||
if (tcolor.a == 0.0)
|
||||
discard;
|
||||
|
||||
//if it is - calculate color at current pixel
|
||||
vec4 lightColorMod = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
lightColorMod.rgb = lightColor.rgb * max(lightPosAndRadius.w - dist, 0.0) / lightPosAndRadius.w;
|
||||
|
||||
if (spotLight > 0.5)
|
||||
{
|
||||
vec3 lightDirection = normalize(lightPosAndRadius.xyz - PosW);
|
||||
float cosDir = dot(lightDirection, lightOrientation);
|
||||
float df = smoothstep(light2Radius.y, light2Radius.x, cosDir);
|
||||
lightColorMod.rgb *= df;
|
||||
}
|
||||
|
||||
if (lightColor.a > 0.979f && lightColor.a < 0.981f) // attenuated light 98%
|
||||
lightColorMod.rgb *= diffuseContribution;
|
||||
|
||||
if (lightColorMod.r <= 0.0 && lightColorMod.g <= 0.0 && lightColorMod.b <= 0.0)
|
||||
discard;
|
||||
|
||||
lightColorMod.rgb *= lightColor.a;
|
||||
if (lightColor.a > 0.4) //Normal, vavoom or negative light (or attenuated)
|
||||
lightColorMod *= tcolor;
|
||||
|
||||
FragColor = desaturate(lightColorMod); //Additive light
|
||||
}
|
||||
)";
|
||||
|
||||
static const char* world3D_ps_skybox = R"(
|
||||
#version 150
|
||||
|
||||
in vec3 Tex;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 highlightcolor;
|
||||
|
||||
uniform samplerCube texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 ncolor = texture(texture1, Tex);
|
||||
FragColor = vec4(highlightcolor.rgb * highlightcolor.a + (ncolor.rgb - 0.4 * highlightcolor.a), 1.0);
|
||||
}
|
||||
)";
|
Loading…
Reference in a new issue