Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
polyester-CTRL committed Mar 10, 2024
2 parents edf5be8 + c81400c commit 5126913
Show file tree
Hide file tree
Showing 260 changed files with 20,101 additions and 10,798 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Developers:
Yama.can
naga-karupi
comefrombottom
sashi0034
緑獺おがめ
Kaito

Document Authors:
Ryo Suzuki (@Reputeless)
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors:
given-names: "Ryo"
title: "Siv3D"
license: MIT
version: 0.6.13
date-released: 2023-11-15
version: 0.6.14
date-released: 2024-02-05
url: "https://github.com/Siv3D/OpenSiv3D"
4 changes: 2 additions & 2 deletions Linux/App/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// Example non-graphical program
//
# include <Siv3D.hpp> // Siv3D v0.6.13
# include <Siv3D.hpp> // Siv3D v0.6.14
SIV3D_SET(EngineOption::Renderer::Headless) // Force non-graphical mode
void Main()
{
Expand All @@ -22,7 +22,7 @@ void Main()
//
// Example graphical program
//
# include <Siv3D.hpp> // Siv3D v0.6.13
# include <Siv3D.hpp> // Siv3D v0.6.14
void Main()
{
Expand Down
68 changes: 68 additions & 0 deletions Linux/App/example/shader/glsl/default3d_forward_shadow_depth.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2008-2023 Ryo Suzuki.
// Copyright (c) 2016-2023 OpenSiv3D Project.
// Licensed under the MIT License.

# version 410

//
// Textures
//
uniform sampler2D Texture0;

//
// PSInput
//
layout(location = 0) in vec3 WorldPosition;
layout(location = 1) in vec2 UV;
layout(location = 2) in vec3 Normal;

//
// PSOutput
//
layout(location = 0) out vec2 FragColor;

//
// Constant Buffer
//
layout(std140) uniform PSPerFrame // slot 0
{
vec3 g_globalAmbientColor;
vec3 g_sunColor;
vec3 g_sunDirection;
};

layout(std140) uniform PSPerView // slot 1
{
vec3 g_eyePosition;
};

layout(std140) uniform PSPerMaterial // slot 3
{
vec3 g_ambientColor;
uint g_hasTexture;
vec4 g_diffuseColor;
vec3 g_specularColor;
float g_shininess;
vec3 g_emissionColor;
};

////////////////////////////////////////////////////////////
//
// Depth
//

layout(std140) uniform PSShadow // slot 4
{
mat4x4 g_worldToProjectedShadow;
vec3 g_sunPosition;
float g_lightBleedingReduction;
};

void main()
{
float depth = length(g_sunPosition - WorldPosition);
FragColor = vec2(depth, (depth * depth));
}

//
////////////////////////////////////////////////////////////
150 changes: 150 additions & 0 deletions Linux/App/example/shader/glsl/default3d_forward_shadow_shading.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// Copyright (c) 2008-2023 Ryo Suzuki.
// Copyright (c) 2016-2023 OpenSiv3D Project.
// Licensed under the MIT License.

# version 410

//
// Textures
//
uniform sampler2D Texture0;

//
// PSInput
//
layout(location = 0) in vec3 WorldPosition;
layout(location = 1) in vec2 UV;
layout(location = 2) in vec3 Normal;

//
// PSOutput
//
layout(location = 0) out vec4 FragColor;

//
// Constant Buffer
//
layout(std140) uniform PSPerFrame // slot 0
{
vec3 g_globalAmbientColor;
vec3 g_sunColor;
vec3 g_sunDirection;
};

layout(std140) uniform PSPerView // slot 1
{
vec3 g_eyePosition;
};

layout(std140) uniform PSPerMaterial // slot 3
{
vec3 g_ambientColor;
uint g_hasTexture;
vec4 g_diffuseColor;
vec3 g_specularColor;
float g_shininess;
vec3 g_emissionColor;
};

//
// Functions
//
vec4 GetDiffuseColor(vec2 uv)
{
vec4 diffuseColor = g_diffuseColor;

if (g_hasTexture == 1)
{
diffuseColor *= texture(Texture0, uv);
}

return diffuseColor;
}

vec3 CalculateDiffuseReflection(vec3 n, vec3 l, vec3 lightColor, vec3 diffuseColor, vec3 ambientColor)
{
vec3 directColor = lightColor * max(dot(n, l), 0.0f);
return ((ambientColor + directColor) * diffuseColor);
}

vec3 CalculateSpecularReflection(vec3 n, vec3 h, float shininess, float nl, vec3 lightColor, vec3 specularColor)
{
float highlight = pow(max(dot(n, h), 0.0f), shininess) * float(0.0f < nl);
return (lightColor * specularColor * highlight);
}

////////////////////////////////////////////////////////////
//
// Shading
//

uniform sampler2D Texture1;

layout(std140) uniform PSShadow // slot 4
{
mat4x4 g_worldToProjectedShadow;
vec3 g_sunPosition;
float g_lightBleedingReduction;
};

float LineStep(float min, float max, float value)
{
return clamp((value - min) / (max - min), 0.0, 1.0);
}

float ReduceLightBleeding(float p_max, float amount)
{
return LineStep(amount, 1.0, p_max);
}

float CalculateShadow(vec3 worldPosition)
{
vec4 projectedPosition = (vec4(worldPosition, 1.0) * g_worldToProjectedShadow);

if (any(notEqual(clamp(projectedPosition.xyz, 0.0, 1.0), projectedPosition.xyz)))
{
return 1.0;
}

vec2 uv = vec2(projectedPosition.x, (1.0 - projectedPosition.y));
float depth = (length(g_sunPosition - worldPosition) - 0.03125);
vec2 moments = texture(Texture1, uv).rg;

if (depth <= moments.x)
{
return 1.0;
}

float variance = (moments.y - (moments.x * moments.x));
float d = (moments.x - depth);
float lit = (variance / (variance + (d * d)));

return ReduceLightBleeding(lit, g_lightBleedingReduction);
}

void main()
{
// Shadow
float lit = CalculateShadow(WorldPosition);

vec3 lightColor = (g_sunColor * lit);
vec3 lightDirection = g_sunDirection;

vec3 n = normalize(Normal);
vec3 l = lightDirection;
vec4 diffuseColor = GetDiffuseColor(UV);
vec3 ambientColor = (g_ambientColor * g_globalAmbientColor);

// Diffuse
vec3 diffuseReflection = CalculateDiffuseReflection(n, l, lightColor, diffuseColor.rgb, ambientColor);

// Specular
vec3 v = normalize(g_eyePosition - WorldPosition);
vec3 h = normalize(v + lightDirection);
vec3 specularReflection = CalculateSpecularReflection(n, h, g_shininess, dot(n, l), lightColor, g_specularColor);

FragColor = vec4(diffuseReflection + specularReflection + g_emissionColor, diffuseColor.a);
}

//
////////////////////////////////////////////////////////////
Loading

0 comments on commit 5126913

Please sign in to comment.