Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skeleton resource #492

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions Engine/Auto/Scripts/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,15 @@ project("Editor")
staticruntime "on"
filter { "configurations:Debug" }
runtime "Debug" -- /MTd
libdirs {
BinariesPath,
path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug"),
}
filter { "configurations:Release" }
runtime "Release" -- /MT
libdirs {
BinariesPath,
path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release"),
}
filter {}

libdirs {
BinariesPath,
path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}"),
}

links {
"Engine",
"AssetPipelineCore",
Expand All @@ -141,6 +138,18 @@ project("Editor")
}
end

if ENABLE_FBX_WORKFLOW then
links {
"FbxConsumer",
"FbxProducer",
}

defines {
"ENABLE_FBX_CONSUMER",
"ENABLE_FBX_PRODUCER",
}
end

-- Disable these options can reduce the size of compiled binaries.
justmycode("Off")
editAndContinue("Off")
Expand Down
123 changes: 55 additions & 68 deletions Engine/Auto/Scripts/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ function IsIOSPlatform()
return ChoosePlatform == "IOS"
end

USE_CLANG_TOOLSET = false
if os.getenv("USE_CLANG_TOOLSET") then
USE_CLANG_TOOLSET = true
end

DDGI_SDK_PATH = os.getenv("DDGI_SDK_PATH") or ""
if not os.isdir(DDGI_SDK_PATH) then
DDGI_SDK_PATH = ""
end

ENABLE_FREETYPE = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_SPDLOG = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_SUBPROCESS = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_TRACY = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_DDGI = DDGI_SDK_PATH ~= ""

ShouldTreatWaringAsError = not (ENABLE_DDGI or USE_CLANG_TOOLSET)

PlatformSettings = {}
PlatformSettings["Windows"] = {
DisplayName = "Win64",
Expand Down Expand Up @@ -77,6 +59,33 @@ function GetPlatformMacroName()
return PlatformSettings[ChoosePlatform].MacroName
end

dofile("path.lua")

--------------------------------------------------------------------------------------------------------
-- Build Options
--------------------------------------------------------------------------------------------------------
USE_CLANG_TOOLSET = false
if os.getenv("USE_CLANG_TOOLSET") then
USE_CLANG_TOOLSET = true
end

DDGI_SDK_PATH = os.getenv("DDGI_SDK_PATH") or ""
if not os.isdir(DDGI_SDK_PATH) then
DDGI_SDK_PATH = ""
end

FBX_SDK_DEBUG_PATH = path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/libfbxsdk.dll")
FBX_SDK_RELEASE_PATH = path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/libfbxsdk.dll")

ENABLE_DDGI = DDGI_SDK_PATH ~= ""
ENABLE_FBX_WORKFLOW = os.isfile(FBX_SDK_DEBUG_PATH) and os.isfile(FBX_SDK_RELEASE_PATH)
ENABLE_FREETYPE = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_SPDLOG = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_SUBPROCESS = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()
ENABLE_TRACY = not USE_CLANG_TOOLSET and not IsLinuxPlatform() and not IsAndroidPlatform()

ShouldTreatWaringAsError = not (ENABLE_DDGI or USE_CLANG_TOOLSET)

IDEConfigs = {}
IDEConfigs.BuildIDEName = os.getenv("BUILD_IDE_NAME")

Expand All @@ -92,8 +101,7 @@ function SetLanguageAndToolset(projectName)
targetdir(BinariesPath)
end

-- Parse folder path
dofile("path.lua")
-- Information about make
print("================================================================")
print("EngineBuildLibKind = "..EngineBuildLibKind)
print("CurrentWorkingDirectory = "..CurrentWorkingDirectory)
Expand All @@ -105,7 +113,12 @@ print("EngineSourcePath = "..EngineSourcePath)
print("GameSourcePath = "..GameSourcePath)
print("RuntimeSourcePath = "..RuntimeSourcePath)
print("IDEConfigs.BuildIDEName = "..IDEConfigs.BuildIDEName)
print("DDGI_SDK_PATH = "..DDGI_SDK_PATH)
print("================================================================")
print("ENABLE_FBX_WORKFLOW = "..tostring(ENABLE_FBX_WORKFLOW))
print("ENABLE_FREETYPE = "..tostring(ENABLE_FREETYPE))
print("ENABLE_SPDLOG = "..tostring(ENABLE_SPDLOG))
print("ENABLE_SUBPROCESS = "..tostring(ENABLE_SUBPROCESS))
print("ENABLE_TRACY = "..tostring(ENABLE_TRACY))
print("================================================================")

-- workspace means solution in Visual Studio
Expand Down Expand Up @@ -156,53 +169,27 @@ function CopyDllAutomatically()
end

-- copy dll into binary folder automatically.
filter { "configurations:Debug" }
if IsAndroidPlatform() then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Debug/SDL2d.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/AssetPipelineCore.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/CDProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Debug/CDConsumer.*").."\" \""..BinariesPath.."\"",
}
else
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Debug/SDL2d.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/AssetPipelineCore.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/CDProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/CDConsumer.*").."\" \""..BinariesPath.."\"",
}
end

if not USE_CLANG_TOOLSET then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/GenericProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Debug/assimp-*-mtd.*").."\" \""..BinariesPath.."\"",
}
end
filter { "configurations:Release" }
if IsAndroidPlatform() then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Release/SDL2.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/AssetPipelineCore.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/CDProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/ARM64/Release/CDConsumer.*").."\" \""..BinariesPath.."\"",
}
else
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/Release/SDL2.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/AssetPipelineCore.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/CDProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/CDConsumer.*").."\" \""..BinariesPath.."\"",
}
end

if not USE_CLANG_TOOLSET then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/GenericProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/Release/assimp-*-mt.*").."\" \""..BinariesPath.."\"",
}
end
filter {}
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "sdl/build/%{cfg.buildcfg}/SDL2*.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/AssetPipelineCore.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/CDProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/CDConsumer.*").."\" \""..BinariesPath.."\"",
}

if not USE_CLANG_TOOLSET then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/GenericProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/assimp-*-mt*.*").."\" \""..BinariesPath.."\"",
}
end

if ENABLE_FBX_WORKFLOW then
postbuildcommands {
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/FbxConsumer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/FbxProducer.*").."\" \""..BinariesPath.."\"",
"{COPYFILE} \""..path.join(ThirdPartySourcePath, "AssetPipeline/build/bin/%{cfg.buildcfg}/libfbxsdk.*").."\" \""..BinariesPath.."\"",
}
end

if ENABLE_DDGI then
postbuildcommands {
Expand Down
1 change: 1 addition & 0 deletions Engine/BuiltInShaders/common/CelMaterial.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uniform vec4 u_outLine;
4 changes: 4 additions & 0 deletions Engine/BuiltInShaders/common/Envirnoment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SAMPLERCUBE(s_texCubeIrr, IBL_IRRADIANCE_SLOT);
SAMPLERCUBE(s_texCubeRad, IBL_RADIANCE_SLOT);
SAMPLER2D(s_texLUT, BRDF_LUT_SLOT);

uniform vec4 u_iblStrength;

vec3 SampleEnvIrradiance(vec3 normal, float mip) {
// We use the HDR texture which in linear space.
vec3 cubeNormalDir = normalize(fixCubeLookup(normal, mip, 256.0));
Expand Down Expand Up @@ -74,6 +76,8 @@ vec3 GetIBL(Material material, vec3 vertexNormal, vec3 viewDir) {

// Specular
envColor += (envSpecularBRDF * envRadiance * finalSpecularOcclusion);

envColor *= vec3_splat(u_iblStrength.x);
#endif

return envColor;
Expand Down
78 changes: 77 additions & 1 deletion Engine/BuiltInShaders/common/LightSource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uniform vec4 u_lightCountAndStride;
uniform vec4 u_lightParams[LIGHT_LENGTH];
uniform mat4 u_lightViewProjs[4*3];
uniform vec4 u_clipFrustumDepth;
uniform vec4 u_bias[3];//[LIGHT_NUM]
uniform vec4 u_bias[3]; // [LIGHT_NUM]

SAMPLERCUBE(s_texCubeShadowMap_1, SHADOW_MAP_CUBE_FIRST_SLOT);
SAMPLERCUBE(s_texCubeShadowMap_2, SHADOW_MAP_CUBE_SECOND_SLOT);
Expand Down Expand Up @@ -49,6 +49,16 @@ U_Light GetLightParams(int pointer) {
return light;
}

struct CelParameter
{
vec4 dividLine;
vec4 specular;
vec3 firstShadowColor;
vec3 secondShadowColor;
vec3 rimLightColor;
vec3 rimLight;
};

// -------------------- Utils -------------------- //

// Distance Attenuation
Expand Down Expand Up @@ -304,6 +314,39 @@ vec3 CalculateDirectionalLight(U_Light light, Material material, vec3 worldPos,
return (1.0 - shadow) * (KD * diffuseBRDF + specularBRDF) * irradiance * NdotL;
}

vec3 CalculateCelDirectionalLight(U_Light light, Material material, vec3 worldPos, vec3 viewDir, float csmDepth, int lightIndex, CelParameter celParameter) {
// TODO : Remove this normalize in the future and add shadow in cartoon renderer.
vec3 lightDir = normalize(-light.direction);
vec3 harfDir = normalize(lightDir + viewDir);

float NdotV = dot(material.normal, viewDir);
float NdotL = dot(material.normal, lightDir);
float NdotH = max(dot(material.normal, harfDir), 0.0);

float halfLambert = 0.5 * NdotL + 0.5;
vec4 dividLine = celParameter.dividLine;

float firstShadowMask = saturate(1.0 - (halfLambert - (dividLine.x - dividLine.y)) / dividLine.y); // albedo and 1st shadow
float secondShadowMask = saturate (1.0 - (halfLambert - (dividLine.z - dividLine.w)) / dividLine.w); // 1st shadow and 2st shadow
vec3 finalBaseColor = lerp(material.albedo, lerp(celParameter.firstShadowColor, celParameter.secondShadowColor, secondShadowMask), firstShadowMask);

// Specular
float halfSpecular = 0.5 * NdotH + 0.5;
vec4 specular = celParameter.specular;
vec3 specularMask = specular.y * lerp(1.0 - step(halfSpecular, (1.0 - pow(specular.x, 5.0))), pow(halfSpecular, exp2(lerp(11.0, 1.0, specular.x))), specular.w);
vec3 specularColor = light.color * specularMask * vec3_splat(((1.0 - firstShadowMask) + (firstShadowMask * specular.z)) * light.intensity);

// Rim
// TODO : Screen Space rim
float f = 1.0 - saturate(NdotV);
vec3 rimLight = celParameter.rimLight;
f = smoothstep(1.0 - rimLight.x, 1.0, f);
f = smoothstep(0.0, rimLight.y, f);
vec3 rim = f * rimLight.xyz * rimLight.z;

return rim + specularColor + finalBaseColor;
}

// -------------------- Sphere -------------------- //

vec3 CalculateSphereDiffuse(U_Light light, Material material, vec3 worldPos, vec3 diffuseBRDF) {
Expand Down Expand Up @@ -676,6 +719,29 @@ vec3 CalculateLight(U_Light light, Material material, vec3 worldPos, vec3 viewDi
return color;
}

vec3 CalculateCelLight(U_Light light, Material material, vec3 normal, vec3 viewDir, float csmDepth, int lightIndex, CelParameter celParameter) {
vec3 color = vec3_splat(0.0);
if (light.type == POINT_LIGHT)
{
// TODO : Add cartoon point light.
color = vec3_splat(0.0);
}
else if (light.type == SPOT_LIGHT)
{
// TODO : Add cartoon spot light.
color = vec3_splat(0.0);
}
else if (light.type == DIRECTIONAL_LIGHT)
{
color = CalculateCelDirectionalLight(light, material, normal, viewDir, csmDepth, lightIndex, celParameter);
}
else
{
color = vec3_splat(0.0);
}
return color;
}

vec3 CalculateLights(Material material, vec3 worldPos, vec3 viewDir, vec3 diffuseBRDF, float csmDepth) {
vec3 color = vec3_splat(0.0);
for(int lightIndex = 0; lightIndex < int(u_lightCountAndStride.x); ++lightIndex) {
Expand All @@ -685,3 +751,13 @@ vec3 CalculateLights(Material material, vec3 worldPos, vec3 viewDir, vec3 diffus
}
return color;
}

vec3 CalculateCelLights(Material material, vec3 worldPos, vec3 viewDir, float csmDepth, CelParameter celParameter) {
vec3 color = vec3_splat(0.0);
for(int lightIndex = 0; lightIndex < int(u_lightCountAndStride.x); ++lightIndex) {
int pointer = int(lightIndex * u_lightCountAndStride.y);
U_Light light = GetLightParams(pointer);
color += CalculateCelLight(light, material, worldPos, viewDir, csmDepth, lightIndex, celParameter);
}
return color;
}
56 changes: 56 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_celluloid.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$input v_worldPos, v_normal, v_texcoord0, v_TBN, v_color0

#include "../common/common.sh"
#include "../common/BRDF.sh"
#include "../common/Material.sh"
#include "../common/Camera.sh"

#include "../common/LightSource.sh"
#include "../common/Envirnoment.sh"

uniform vec4 u_emissiveColorAndFactor;
uniform vec4 u_cameraNearFarPlane;

uniform vec4 u_dividLine;
uniform vec4 u_specular;
uniform vec4 u_firstShadowColor;
uniform vec4 u_secondShadowColor;
uniform vec4 u_rimLightColor;
uniform vec4 u_rimLight;

vec3 GetCelDirectional(Material material, vec3 worldPos, vec3 viewDir, float csmDepth, CelParameter celParameter) {
return CalculateCelLights(material, worldPos, viewDir, csmDepth, celParameter);
}

// TODO : add envirnoment light

void main()
{
Material material = GetMaterial(v_texcoord0, v_normal, v_TBN);
if (material.opacity < u_alphaCutOff.x) {
discard;
}

vec3 cameraPos = GetCamera().position.xyz;
vec3 viewDir = normalize(cameraPos - v_worldPos);

// Directional Light
float csmDepth = (v_color0.z - u_cameraNearFarPlane.x) / (u_cameraNearFarPlane.y - u_cameraNearFarPlane.x);
CelParameter celParameter;
celParameter.dividLine = u_dividLine;
celParameter.specular = u_specular;
celParameter.firstShadowColor = u_firstShadowColor;
celParameter.secondShadowColor = u_secondShadowColor;
celParameter.rimLightColor = u_rimLightColor;
celParameter.rimLight = u_rimLight;
vec3 dirColor = GetCelDirectional(material, v_worldPos, viewDir, csmDepth, celParameter);

// Emissive
vec3 emiColor = material.emissive * u_emissiveColorAndFactor.xyz * vec3_splat(u_emissiveColorAndFactor.w);

// Fragment Color
gl_FragData[0] = vec4(dirColor + emiColor, 1.0);
gl_FragData[1] = vec4(emiColor, 1.0);

// Post-processing will be used in the last pass.
}
9 changes: 9 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_outline.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "../common/common.sh"
#include "../common/Material.sh"

uniform vec4 u_outLineColor;

void main()
{
gl_FragColor = vec4(u_outLineColor.xyz, 1.0);
}
Loading
Loading