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

Fix OpenGl backend #496

Closed
wants to merge 97 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
dfc0ca0
integrate fbx workflow
T-rvw Mar 4, 2024
f9ed320
change emitcomponent build format
OVOAOVO Mar 5, 2024
159a845
Add Range Of Particle Life Time
OVOAOVO Mar 5, 2024
717d715
NPR Render Based On UTS (#2)
VTui22 Mar 9, 2024
8aad638
beta ribbon
OVOAOVO Mar 11, 2024
6e2e9b7
Merge branch 'main' into Ribbon
OVOAOVO Mar 11, 2024
da7efb0
skybox
roeas Mar 12, 2024
a334501
fix Ribbon index
OVOAOVO Mar 12, 2024
304498d
ibl
roeas Mar 12, 2024
e15bba1
add Ibl strength for sky component
T-rvw Mar 12, 2024
c01ef2d
Minor refine (#4)
roeas Mar 13, 2024
ac95807
Merge branch 'main' into Ribbon
OVOAOVO Mar 14, 2024
118681f
cs Ribbon(no texture)
OVOAOVO Mar 19, 2024
b4eb790
cs Ribbon (fixed texture color)
OVOAOVO Mar 19, 2024
c61f325
Add Materialcomponent Uber shader
OVOAOVO Mar 20, 2024
dabfd1a
fix null material import
T-rvw Mar 21, 2024
a4ad982
Merge https://github.com/CatDogEngine/CatDogEngine into integrate_fbx…
T-rvw Mar 21, 2024
cf24d5d
fix release post build
T-rvw Mar 21, 2024
a19e317
minor fix
T-rvw Mar 21, 2024
18b8ac0
Integrate fbx producer/consumer
T-rvw Mar 22, 2024
bd32f5a
Shader resource (#5)
roeas Mar 22, 2024
f327f6e
update AssetPipeline
OVOAOVO Mar 25, 2024
45ff69d
AssetPipeline conflict
OVOAOVO Mar 25, 2024
4c6694e
conflict fix
OVOAOVO Mar 25, 2024
2d6e17c
uber vertex shader (#8)
roeas Mar 25, 2024
e49be18
merged main
OVOAOVO Mar 25, 2024
962d7db
Merge branch 'main' of https://github.com/CatDogEngine/CatDogEngine
OVOAOVO Mar 25, 2024
30d0faa
Merge branch 'main' into Ribbon
OVOAOVO Mar 25, 2024
3619462
vs shader feature
OVOAOVO Mar 25, 2024
5ab835d
Fixed Ribbon Count
OVOAOVO Apr 1, 2024
a0eef0f
Visibility functions with different levels of exactness. (#9)
roeas Apr 2, 2024
74230b1
Delete obsolete compiled uber shader file. (#11)
roeas Apr 6, 2024
2320dfa
PBR reflectance parameter (#10)
roeas Apr 6, 2024
c2d4c2f
Ues std::format instead of bundled fmt for spdlog. (#12)
roeas Apr 22, 2024
cf1a754
Low-precision pow approximation (#15)
roeas Apr 26, 2024
0e33e7e
IBL minor adjustments (#14)
roeas Apr 27, 2024
02c121c
Optimize Path::Join by fold expression (#16)
roeas May 11, 2024
69100f2
Fix "Use texture" checkbox crash bug (#17)
roeas May 11, 2024
98e53d5
add skeleton resource (#13)
VTui22 May 11, 2024
93422a4
merge Skeleton resource (#18)
VTui22 May 13, 2024
7c5babd
add pbr and ibl demo and add light shadow switch (#19)
VTui22 May 16, 2024
2af93aa
AssetPipline update
OVOAOVO May 18, 2024
42f9f9c
Merge branch 'main' of https://github.com/CatDogEngine/CatDogEngine
OVOAOVO May 18, 2024
9c27e06
update AssetPipline
OVOAOVO May 18, 2024
c9db3b3
Merge branch 'main' into Ribbon
OVOAOVO May 18, 2024
8cdf767
fix generic producer and free skeleton resource
VTui22 May 18, 2024
67d1abd
Fix generic producer and skeleton resource memory free
T-rvw May 22, 2024
c1ffb47
Add Ribbon Particle
T-rvw May 22, 2024
370289e
add file
OVOAOVO Aug 16, 2024
c0a67c0
add file
OVOAOVO Aug 16, 2024
16883d6
fixed instance
OVOAOVO Aug 17, 2024
11a34eb
remove some test
OVOAOVO Aug 19, 2024
9120a6d
fix unpackHalf2x16
OVOAOVO Aug 19, 2024
91146ec
Index fix(Pack to float Needed)
OVOAOVO Aug 19, 2024
519ec6f
Texture Debug
OVOAOVO Aug 20, 2024
dfa30d3
fix sizeList type
OVOAOVO Aug 20, 2024
cc653f2
fix depthIndex Value
OVOAOVO Aug 21, 2024
0942f79
texture type change
OVOAOVO Aug 22, 2024
f55fc9e
fix color
OVOAOVO Aug 24, 2024
c600a0d
fix ply buffer data
OVOAOVO Aug 27, 2024
416c5ba
fix texturedata
OVOAOVO Aug 27, 2024
9da039c
f_buffer review over
OVOAOVO Aug 27, 2024
70bf0f4
camera define
OVOAOVO Aug 28, 2024
8472bd4
u_view to view
OVOAOVO Aug 28, 2024
3150d84
fix depthIndex
OVOAOVO Aug 28, 2024
3c2895b
Camera Add
OVOAOVO Aug 29, 2024
3b5647f
Add Camera
OVOAOVO Aug 29, 2024
9d47818
change Camera to commented
OVOAOVO Aug 29, 2024
4fcd624
Clear code
roeas Aug 30, 2024
7ebb923
Fix sort
roeas Aug 30, 2024
96e981c
Merge pull request #22 from CatDogEngine/gaussian
OVOAOVO Aug 30, 2024
759de75
Fix vertex data and use BGFX_STATE_PT_TRISTRIP
roeas Aug 31, 2024
de4bcf5
Fix uniform uploading
roeas Aug 31, 2024
9216115
Merge pull request #23 from CatDogEngine/gaussian
OVOAOVO Aug 31, 2024
dd382c1
log close
OVOAOVO Sep 4, 2024
35d5ac3
first achieve
OVOAOVO Sep 4, 2024
194939a
TEXCOORD0_To_TEXCOORD7
OVOAOVO Sep 4, 2024
a3ae49d
backend_To_Vulkkan
OVOAOVO Sep 4, 2024
725ec1a
bgfx state blend change
OVOAOVO Sep 5, 2024
3e08cfb
State Note
OVOAOVO Sep 5, 2024
907a66d
UpdateView change(Not right)
OVOAOVO Sep 6, 2024
53a7ba4
camera review over
OVOAOVO Sep 7, 2024
c35c1f8
vec3 position-> vec2 position
OVOAOVO Sep 10, 2024
2a28c0f
alpha blend
OVOAOVO Sep 10, 2024
06c738d
backend to OpenGL(fix rotation)
OVOAOVO Sep 20, 2024
651822b
aspect fix
OVOAOVO Sep 20, 2024
f0947c4
remove aspect
OVOAOVO Sep 20, 2024
6c0c943
fixed all
OVOAOVO Sep 23, 2024
edf12c8
Remove some comments
OVOAOVO Sep 23, 2024
33609eb
backend To Vulkan (open other renderer)
OVOAOVO Sep 26, 2024
d49f1de
far to near sort
OVOAOVO Sep 26, 2024
084dca9
depth and blend renderer
OVOAOVO Sep 28, 2024
002a315
fix rotation
OVOAOVO Oct 9, 2024
393b600
fix import bug
OVOAOVO Oct 14, 2024
b2cdf69
Code style
roeas Oct 23, 2024
43c0d7e
Fix OpenGL backend
roeas Oct 23, 2024
424275c
Temporary solution
roeas Oct 23, 2024
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
28 changes: 18 additions & 10 deletions Engine/Auto/Scripts/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ project("Editor")

if ENABLE_SPDLOG then
defines {
-- TODO : Remove _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING after spdlog updates the format to the right version.
"SPDLOG_ENABLE", "SPDLOG_NO_EXCEPTIONS", "FMT_USE_NONTYPE_TEMPLATE_ARGS=0", "_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING",
"SPDLOG_NO_EXCEPTIONS", "SPDLOG_USE_STD_FORMAT",
}

includedirs {
Expand Down Expand Up @@ -112,18 +111,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 +137,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
3 changes: 1 addition & 2 deletions Engine/Auto/Scripts/engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ project("Engine")
}

defines {
-- TODO : Remove _SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING after spdlog updates the format to the right version.
"SPDLOG_ENABLE", "SPDLOG_NO_EXCEPTIONS", "FMT_USE_NONTYPE_TEMPLATE_ARGS=0", "_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING",
"SPDLOG_NO_EXCEPTIONS", "SPDLOG_USE_STD_FORMAT",
}
end

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/UniformDefines/U_Particle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define PT_RIBBON_VERTEX_STAGE 1
43 changes: 31 additions & 12 deletions Engine/BuiltInShaders/common/BRDF.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,36 @@ float DistributionGGX(float NdotH, float rough) {
return a2 * CD_PI_INV * denom_inv * denom_inv;
}

// Geometry
float Visibility(float NdotV, float NdotL, float rough) {
// Specular BRDF = (F * D * G) / (4 * NdotV * NdotL)
// = (F * D * (NdotV / (NdotV * (1 - K) + K)) * (NdotL / (NdotL * (1 - K) + K))) / (4 * NdotV * NdotL)
// = (F * D * (1 / (NdotV * (1 - K) + K)) * (1 / (NdotL * (1 - K) + K))) / 4
// = F * D * Vis
// Vis = 1 / (NdotV * (1 - K) + K) / (NdotL * (1 - K) + K) / 4
float Visibility_HighQuality(float NdotV, float NdotL, float rough) {
// BRDF = (F * D * G) / (4 * NdotV * NdotL) = F * D * V
// V = G / (4 * NdotV * NdotL)
// = 0.5 / (NdotL * sqrt(a2 + (1 - a2) * NdotV^2) + NdotV * sqrt(a2 + (1 - a2) * NdotL^2))

// rough = (rough + 1) / 2, by Disney
// a = rough^2
float a2 = pow((rough + 1.0) * 0.5, 4);
float lambda_v = NdotL * sqrt(a2 + (1.0 - a2) * NdotV * NdotV);
float lambda_l = NdotV * sqrt(a2 + (1.0 - a2) * NdotL * NdotL);

return 0.5 / (lambda_v + lambda_l);
}

float Visibility_LowQuality(float NdotV, float NdotL, float rough) {
// BRDF = (F * D * G) / (4 * NdotV * NdotL) = F * D * V
// V = G / (4 * NdotV * NdotL)
// = 1 / ((NdotV * (2 - a) + a) * (NdotL * (2 - a) + a))

// rough = (rough + 1) / 2, by Disney
// a = rough^2
float a = (rough + 1.0) * (rough + 1.0) * 0.25;
float g1_v_inv = NdotV * (2.0 - a) + a;
float g1_l_inv = NdotL * (2.0 - a) + a;

float f = rough + 1.0;
float k = f * f * 0.125;
float ggxV = 1.0 / (NdotV * (1.0 - k) + k);
float ggxL = 1.0 / (NdotL * (1.0 - k) + k);
return ggxV * ggxL * 0.25;
return 1.0 / (g1_v_inv * g1_l_inv);
}

// Geometry
float Visibility(float NdotV, float NdotL, float rough) {
// TODO : Wrap them in macros after we've collected enough approximate / exact formulas.
return Visibility_LowQuality(NdotV, NdotL, rough);
}
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;
17 changes: 9 additions & 8 deletions Engine/BuiltInShaders/common/Envirnoment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ SAMPLERCUBE(s_texCubeIrr, IBL_IRRADIANCE_SLOT);
SAMPLERCUBE(s_texCubeRad, IBL_RADIANCE_SLOT);
SAMPLER2D(s_texLUT, BRDF_LUT_SLOT);

vec3 SampleEnvIrradiance(vec3 normal, float mip) {
uniform vec4 u_iblStrength;

vec3 SampleEnvIrradiance(vec3 normal) {
// We use the HDR texture which in linear space.
vec3 cubeNormalDir = normalize(fixCubeLookup(normal, mip, 256.0));
return textureCube(s_texCubeIrr, cubeNormalDir).xyz;
return textureCube(s_texCubeIrr, normal).xyz;
}

vec3 SampleEnvRadiance(vec3 reflectDir, float mip) {
// We use the HDR texture which in linear space.
vec3 cubeReflectDir = normalize(fixCubeLookup(reflectDir, mip, 256.0));
return textureCubeLod(s_texCubeRad, cubeReflectDir, mip).xyz;
return textureCubeLod(s_texCubeRad, reflectDir, mip).xyz;
}

vec2 SampleIBLSpecularBRDFLUT(float NdotV, float roughness) {
Expand All @@ -55,11 +55,10 @@ vec3 GetIBL(Material material, vec3 vertexNormal, vec3 viewDir) {
horizonOcclusion *= horizonOcclusion;
float finalSpecularOcclusion = min(specularOcclusion, horizonOcclusion);

float mip = clamp(6.0 * material.roughness, 0.1, 6.0);

// Environment Prefiltered Irradiance
vec3 envIrradiance = SampleEnvIrradiance(material.normal, 0.0);
vec3 envIrradiance = SampleEnvIrradiance(material.normal);
// Environment Specular Radiance
float mip = material.roughness * 6.0;
vec3 envRadiance = SampleEnvRadiance(reflectDir, mip);

// Environment Specular BRDF
Expand All @@ -74,6 +73,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
Loading
Loading