Permalink
Browse files

Merge with upstream 0bdb20f

# Conflicts:
#	.appveyor.yml
#	.bash_helpers.sh
#	.travis.yml
#	CMake/Modules/CheckCompilerToolchain.cmake
#	CMake/Modules/FindDirectX.cmake
#	CMake/Modules/FindUrho3D.cmake
#	CMake/Modules/UrhoCommon.cmake
#	CMakeLists.txt
#	Docs/AngelScriptAPI.h
#	Docs/Doxyfile.in
#	Docs/GettingStarted.dox
#	Docs/LuaScriptAPI.dox
#	Docs/Reference.dox
#	Docs/ScriptAPI.dox
#	Docs/Urho3D.dox
#	README.md
#	Rakefile
#	Resources/EditorData/AtomicEditor/eulas/atomic_thirdparty_eula.txt
#	Source/Atomic/Atomic2D/ParticleEmitter2D.cpp
#	Source/Atomic/Atomic2D/PhysicsWorld2D.cpp
#	Source/Atomic/Atomic2D/SpriteSheet2D.cpp
#	Source/Atomic/Atomic2D/TmxFile2D.cpp
#	Source/Atomic/Audio/Sound.h
#	Source/Atomic/Core/Context.cpp
#	Source/Atomic/Core/Main.h
#	Source/Atomic/Core/ProcessUtils.cpp
#	Source/Atomic/Core/ProcessUtils.h
#	Source/Atomic/Engine/Application.cpp
#	Source/Atomic/Engine/Application.h
#	Source/Atomic/Engine/Engine.cpp
#	Source/Atomic/Graphics/Animation.h
#	Source/Atomic/Graphics/Model.cpp
#	Source/Atomic/Graphics/Model.h
#	Source/Atomic/Graphics/Text3D/Text3D.cpp
#	Source/Atomic/Graphics/Text3D/Text3D.h
#	Source/Atomic/Graphics/Text3D/Text3DBatch.cpp
#	Source/Atomic/Graphics/Text3D/Text3DBatch.h
#	Source/Atomic/Graphics/Text3D/Text3DBitmap.cpp
#	Source/Atomic/Graphics/Text3D/Text3DFont.cpp
#	Source/Atomic/Graphics/Text3D/Text3DFont.h
#	Source/Atomic/Graphics/Text3D/Text3DFontFace.cpp
#	Source/Atomic/Graphics/Text3D/Text3DFreeType.cpp
#	Source/Atomic/Graphics/Text3D/Text3DText.cpp
#	Source/Atomic/Graphics/Text3D/Text3DText.h
#	Source/Atomic/Graphics/Texture.h
#	Source/Atomic/Graphics/VertexBuffer.cpp
#	Source/Atomic/IO/Log.cpp
#	Source/Atomic/Physics/PhysicsWorld.cpp
#	Source/Atomic/Resource/JSONFile.cpp
#	Source/Atomic/Scene/Node.h
#	Source/CMakeLists.txt
#	Source/Samples/40_Localization/L10n.cpp
#	Source/Samples/42_PBRMaterials/PBRMaterials.cpp
#	Source/Samples/45_InverseKinematics/CMakeLists.txt
#	Source/ThirdParty/Civetweb/CMakeLists.txt
#	Source/ThirdParty/Lua/CMakeLists.txt
#	Source/ThirdParty/Lua/src/loslib.c
#	Source/ThirdParty/LuaJIT/CMakeLists.txt
#	Source/ThirdParty/LuaJIT/src/lj_arch.h
#	Source/ThirdParty/SQLite/CMakeLists.txt
#	Source/ThirdParty/boost/preprocessor/cat.hpp
#	Source/ThirdParty/boost/preprocessor/config/config.hpp
#	Source/ThirdParty/boost/preprocessor/seq/detail/binary_transform.hpp
#	Source/ThirdParty/boost/preprocessor/seq/to_list.hpp
#	Source/ThirdParty/rapidjson/include/rapidjson/internal/dtoa.h
#	Source/ThirdParty/rapidjson/include/rapidjson/internal/ieee754.h
#	Source/ThirdParty/rapidjson/include/rapidjson/internal/regex.h
#	Source/ThirdParty/rapidjson/include/rapidjson/internal/strtod.h
#	Source/ThirdParty/rapidjson/include/rapidjson/istreamwrapper.h
#	Source/ThirdParty/rapidjson/include/rapidjson/pointer.h
#	Source/ThirdParty/rapidjson/include/rapidjson/schema.h
#	Source/Tools/AssetImporter/AssetImporter.cpp
#	Source/Tools/CMakeLists.txt
#	Source/Tools/PackageTool/PackageTool.cpp
#	Source/Tools/Urho3DPlayer/CMakeLists.txt
#	Source/Tools/Urho3DPlayer/Urho3DPlayer.cpp
#	Source/Urho3D/.soversion
#	Source/Urho3D/AngelScript/APITemplates.h
#	Source/Urho3D/AngelScript/AudioAPI.cpp
#	Source/Urho3D/AngelScript/CoreAPI.cpp
#	Source/Urho3D/AngelScript/GraphicsAPI.cpp
#	Source/Urho3D/AngelScript/IKAPI.cpp
#	Source/Urho3D/AngelScript/IOAPI.cpp
#	Source/Urho3D/AngelScript/InputAPI.cpp
#	Source/Urho3D/AngelScript/MathAPI.cpp
#	Source/Urho3D/AngelScript/PhysicsAPI.cpp
#	Source/Urho3D/AngelScript/ResourceAPI.cpp
#	Source/Urho3D/AngelScript/ScriptAPI.h
#	Source/Urho3D/AngelScript/ScriptAPIDump.cpp
#	Source/Urho3D/AngelScript/ScriptFile.cpp
#	Source/Urho3D/AngelScript/UIAPI.cpp
#	Source/Urho3D/AngelScript/Urho2DAPI.cpp
#	Source/Urho3D/CMakeLists.txt
#	Source/Urho3D/LuaScript/pkgs/Audio/Sound.pkg
#	Source/Urho3D/LuaScript/pkgs/Audio/SoundSource.pkg
#	Source/Urho3D/LuaScript/pkgs/Core/ProcessUtils.pkg
#	Source/Urho3D/LuaScript/pkgs/Graphics/Animation.pkg
#	Source/Urho3D/LuaScript/pkgs/Graphics/Model.pkg
#	Source/Urho3D/LuaScript/pkgs/Graphics/Texture.pkg
#	Source/Urho3D/LuaScript/pkgs/Input/Input.pkg
#	Source/Urho3D/LuaScript/pkgs/Math/Quaternion.pkg
#	Source/Urho3D/LuaScript/pkgs/Math/Vector3.pkg
#	Source/Urho3D/LuaScript/pkgs/PhysicsLuaAPI.pkg
#	Source/Urho3D/LuaScript/pkgs/Resource/JSONValue.pkg
#	Source/Urho3D/LuaScript/pkgs/Resource/Resource.pkg
#	Source/Urho3D/LuaScript/pkgs/Scene/Node.pkg
#	Source/Urho3D/LuaScript/pkgs/UI/Font.pkg
#	Source/Urho3D/LuaScript/pkgs/UI/Text.pkg
#	Source/Urho3D/LuaScript/pkgs/UI/Text3D.pkg
#	Source/Urho3D/LuaScript/pkgs/UI/UI.pkg
#	Source/Urho3D/LuaScript/pkgs/Urho2D/ParticleEmitter2D.pkg
#	Source/Urho3D/UI/Cursor.cpp
#	Source/Urho3D/UI/UI.cpp
#	Source/Urho3D/UI/UI.h
#	Source/Urho3D/Urho2D/PhysicsEvents2D.h
#	bin/Autoload/LargeData/Materials/PBR/Check.xml
#	bin/Autoload/LargeData/Materials/PBR/HighRoughMetallic0.xml
#	bin/Autoload/LargeData/Materials/PBR/HighRoughMetallic10.xml
#	bin/Autoload/LargeData/Materials/PBR/HighRoughMetallic3.xml
#	bin/Autoload/LargeData/Materials/PBR/HighRoughMetallic5.xml
#	bin/Autoload/LargeData/Materials/PBR/HighRoughMetallic7.xml
#	bin/Autoload/LargeData/Materials/PBR/Metallic0.xml
#	bin/Autoload/LargeData/Materials/PBR/Metallic10.xml
#	bin/Autoload/LargeData/Materials/PBR/Metallic3.xml
#	bin/Autoload/LargeData/Materials/PBR/Metallic5.xml
#	bin/Autoload/LargeData/Materials/PBR/Metallic7.xml
#	bin/Autoload/LargeData/Materials/PBR/MetallicRough0.xml
#	bin/Autoload/LargeData/Materials/PBR/MetallicRough10.xml
#	bin/Autoload/LargeData/Materials/PBR/MetallicRough3.xml
#	bin/Autoload/LargeData/Materials/PBR/MetallicRough5.xml
#	bin/Autoload/LargeData/Materials/PBR/MetallicRough7.xml
#	bin/Autoload/LargeData/Materials/PBR/Mud.xml
#	bin/Autoload/LargeData/Materials/PBR/Roughness0.xml
#	bin/Autoload/LargeData/Materials/PBR/Roughness10.xml
#	bin/Autoload/LargeData/Materials/PBR/Roughness3.xml
#	bin/Autoload/LargeData/Materials/PBR/Roughness5.xml
#	bin/Autoload/LargeData/Materials/PBR/Roughness7.xml
#	bin/Autoload/LargeData/Materials/PBR/Tile.xml
#	bin/Data/LuaScripts/40_Localization.lua
#	bin/Data/LuaScripts/42_PBRMaterials.lua
#	bin/Data/Scenes/PBRExample.xml
#	bin/Data/Scripts/40_Localization.as
#	bin/Data/Scripts/42_PBRMaterials.as
#	bin/Data/Scripts/Editor.as
#	bin/Data/Scripts/Editor/EditorUI.as
#	bin/Data/Scripts/Editor/EditorView.as
#	cmake_generic.sh
  • Loading branch information...
rokups committed Jun 30, 2017
1 parent 0c52b46 commit d91f7ab817d7dae37c80b769ee7472ef0b840d04
Showing 718 changed files with 27,779 additions and 12,339 deletions.
@@ -22,3 +22,4 @@ Script/TypeScript/**/*.d.ts
!Script/TypeScript/**/*Work.d.ts
Script/Haxe/*
**/.vscode
.idea
@@ -20,4 +20,4 @@ else ()
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -framework AudioToolbox -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreVideo -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices -framework Security")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -framework AudioToolbox -framework Carbon -framework Cocoa -framework CoreAudio -framework CoreVideo -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices -framework Security -framework SystemConfiguration")
@@ -0,0 +1,35 @@
#
# Copyright (c) 2008-2017 the Urho3D project.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Post process to glue the main module and side module(s) together
string (REPLACE " " .js',' SIDE_MODULES "'${SIDE_MODULES}.js'") # Stringify for string replacement
if (HAS_SHELL_FILE)
file (READ ${TARGET_FILE} CONTENT)
string (REPLACE ${TARGET_NAME}.js libUrho3D.js CONTENT "${CONTENT}") # Stringify to preserve semicolons
# Assume HTML shell-file has Module object without the 'dynamicLibraries' prop defined yet
string (REGEX REPLACE "(var Module *= *{)" \\1dynamicLibraries:[${SIDE_MODULES}], CONTENT "${CONTENT}")
file (WRITE ${TARGET_FILE} "${CONTENT}")
else ()
file (READ ${TARGET_DIR}/libUrho3D.js CONTENT)
file (WRITE ${TARGET_DIR}/${TARGET_NAME}.main.js "var Module={dynamicLibraries:[${SIDE_MODULES}]};${CONTENT}")
endif ()
@@ -21,12 +21,23 @@
return specular + (vec3(1.0, 1.0, 1.0) - specular) * sphericalGaussian;
}
vec3 SchlickFresnelCustom(vec3 specular, float LdotH)
{
float ior = 0.25;
float airIor = 1.000277;
float f0 = (ior - airIor) / (ior + airIor);
float max_ior = 2.5;
f0 = clamp(f0 * f0, 0.0, (max_ior - airIor) / (max_ior + airIor));
return specular * (f0 + (1 - f0) * pow(2, (-5.55473 * LdotH - 6.98316) * LdotH));
}
//Get Fresnel
//specular = the rgb specular color value of the pixel
//VdotH = the dot product of the camera view direction and the half vector
vec3 Fresnel(vec3 specular, float VdotH)
vec3 Fresnel(vec3 specular, float VdotH, float LdotH)
{
return SchlickFresnel(specular, VdotH);
return SchlickFresnelCustom(specular, LdotH);
//return SchlickFresnel(specular, VdotH);
}
// Smith GGX corrected Visibility
@@ -42,13 +53,19 @@
return 0.5 / (lambdaV + lambdaL);
}
float NeumannVisibility(float NdotV, float NdotL)
{
return NdotL * NdotV / max(1e-7, max(NdotL, NdotV));
}
// Get Visibility
// NdotL = the dot product of the normal and direction to the light
// NdotV = the dot product of the normal and the camera view direction
// roughness = the roughness of the pixel
float Visibility(float NdotL, float NdotV, float roughness)
{
return SmithGGXSchlickVisibility(NdotL, NdotV, roughness);
return NeumannVisibility(NdotV, NdotL);
//return SmithGGXSchlickVisibility(NdotL, NdotV, roughness);
}
// Blinn Distribution
@@ -96,9 +113,20 @@
// NdotV = the normal dot with the camera view direction
// NdotL = the normal dot with the light direction
// VdotH = the camera view direction dot with the half vector
vec3 LambertianDiffuse(vec3 diffuseColor, float NdotL)
vec3 LambertianDiffuse(vec3 diffuseColor)
{
return diffuseColor * (1.0 / M_PI) ;
}
// Custom Lambertian Diffuse
// diffuseColor = the rgb color value of the pixel
// roughness = the roughness of the pixel
// NdotV = the normal dot with the camera view direction
// NdotL = the normal dot with the light direction
// VdotH = the camera view direction dot with the half vector
vec3 CustomLambertianDiffuse(vec3 diffuseColor, float NdotV, float roughness)
{
return diffuseColor * NdotL;
return diffuseColor * (1.0 / M_PI) * pow(NdotV, 0.5 + 0.3 * roughness);
}
// Burley Diffuse
@@ -127,8 +155,9 @@
// VdotH = the camera view direction dot with the half vector
vec3 Diffuse(vec3 diffuseColor, float roughness, float NdotV, float NdotL, float VdotH)
{
//return LambertianDiffuse(diffuseColor, NdotL);
return BurleyDiffuse(diffuseColor, roughness, NdotV, NdotL, VdotH);
//return LambertianDiffuse(diffuseColor);
return CustomLambertianDiffuse(diffuseColor, NdotV, roughness);
//return BurleyDiffuse(diffuseColor, roughness, NdotV, NdotL, VdotH);
}
#endif
@@ -2,6 +2,6 @@
#define M_EPSILON 0.0001
#ifdef PBR
#define ROUGHNESS_FLOOR 0.003
#define ROUGHNESS_FLOOR 0.004
#define METALNESS_FLOOR 0.03
#endif
@@ -229,17 +229,16 @@
/// normal: surface normal
/// reflection: vector of reflection off of the surface
/// roughness: surface roughness
vec3 GetSpecularDominantDir(vec3 normal, vec3 reflection, float roughness)
{
float smoothness = 1.0 - roughness;
float lerpFactor = smoothness * (sqrt(smoothness) + roughness);
return mix(normal, reflection, lerpFactor);
}
// vec3 GetSpecularDominantDir(vec3 normal, vec3 reflection, float roughness)
// {
// float smoothness = 1.0 - roughness;
// float lerpFactor = smoothness * (sqrt(smoothness) + roughness);
// return mix(normal, reflection, lerpFactor);
// }
float GetMipFromRoughness(float roughness)
{
float Level = 3 - 1.15 * log2( roughness );
return 9.0 - 1 - Level;
return (roughness * 12.0 - pow(roughness, 6.0) * 1.5);
}
@@ -273,6 +272,7 @@
/// ambientOcclusion: ambient occlusion
vec3 ImageBasedLighting(vec3 reflectVec, vec3 tangent, vec3 bitangent, vec3 wsNormal, vec3 toCamera, vec3 diffColor, vec3 specColor, float roughness, inout vec3 reflectionCubeColor)
{
roughness = max(roughness, 0.08);
reflectVec = GetSpecularDominantDir(wsNormal, reflectVec, roughness);
float ndv = clamp(dot(-toCamera, wsNormal), 0.0, 1.0);
@@ -1,38 +1,70 @@
#include "BRDF.glsl"
#ifdef COMPILEPS
#line 100
vec3 GetSpecularDominantDir(vec3 normal, vec3 reflection, float roughness)
{
float smoothness = 1.0 - roughness;
float lerpFactor = smoothness * (sqrt(smoothness) + roughness);
return mix(normal, reflection, lerpFactor);
}
vec3 SphereLight(vec3 worldPos, vec3 lightVec, vec3 normal, vec3 toCamera, float roughness, vec3 specColor, out float ndl)
vec3 SphereLight(vec3 worldPos, vec3 lightVec, vec3 normal, vec3 toCamera, float roughness, vec3 specColor, vec3 diffColor, out float ndl)
{
vec3 pos = (cLightPosPS.xyz - worldPos);
float radius = cLightRad;
float specEnergy = 1.0f;
vec3 reflectVec = reflect(-toCamera, normal);
vec3 centreToRay = dot(pos, reflectVec) * reflectVec - pos;
vec3 closestPoint = pos + centreToRay * clamp(radius / length(centreToRay), 0.0, 1.0);
float radius = cLightRad / 100;
float rough2 = max(roughness, 0.08);
rough2 *= rough2;
vec3 l = normalize(closestPoint);
vec3 h = normalize(toCamera + l);
float radius2 = radius * radius;
float distToLightSqrd = dot(lightVec,lightVec);
float invDistToLight = inversesqrt(distToLightSqrd);
float sinAlphaSqr = clamp(radius2 / distToLightSqrd, 0.0, 1.0);
float sinAlpha = sqrt(sinAlphaSqr);
ndl = clamp(dot(normal, l), 0.0, 1.0);
float hdn = clamp(dot(h, normal), 0.0, 1.0);
float hdv = dot(h, toCamera);
float ndv = clamp(dot(normal, toCamera), 0.0, 1.0);
ndl = dot(normal, (lightVec * invDistToLight));
float distL = length(pos);
float alpha = roughness * roughness;
float alphaPrime = clamp(radius / (distL * 2.0) + alpha, 0.0, 1.0);
if(ndl < sinAlpha)
{
ndl = max(ndl, -sinAlpha);
ndl = ((sinAlpha + ndl) * (sinAlpha + ndl)) / (4 * sinAlpha);
}
float sphereAngle = clamp(radius * invDistToLight, 0.0, 1.0);
specEnergy = rough2 / (rough2 + 0.5f * sphereAngle);
specEnergy *= specEnergy;
vec3 fresnelTerm = Fresnel(specColor, hdv) ;
float distTerm = Distribution(hdn, alphaPrime);
float visTerm = Visibility(ndl, ndv, roughness);
vec3 R = 2 * dot(toCamera, normal) * normal - toCamera;
R = GetSpecularDominantDir(normal, R, roughness);
return distTerm * visTerm * fresnelTerm ;
// Find closest point on sphere to ray
vec3 closestPointOnRay = dot(lightVec, R) * R;
vec3 centerToRay = closestPointOnRay - lightVec;
float invDistToRay = inversesqrt(dot(centerToRay, centerToRay));
vec3 closestPointOnSphere = lightVec + centerToRay * clamp(radius * invDistToRay, 0.0, 1.0);
lightVec = closestPointOnSphere;
vec3 L = normalize(lightVec);
vec3 h = normalize(toCamera + L);
float hdn = clamp(dot(h, normal), 0.0, 1.0);
float hdv = dot(h, toCamera);
float ndv = clamp(dot(normal, toCamera),0.0, 1.0);
float hdl = clamp(dot(h, lightVec), 0.0, 1.0);
vec3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, hdv) * ndl;
vec3 fresnelTerm = Fresnel(specColor, hdv, hdl) ;
float distTerm = Distribution(hdn, roughness);
float visTerm = Visibility(ndl, ndv, roughness);
vec3 specularFactor = distTerm * visTerm * fresnelTerm * ndl/ M_PI;
return diffuseFactor + specularFactor;
}
vec3 TubeLight(vec3 worldPos, vec3 lightVec, vec3 normal, vec3 toCamera, float roughness, vec3 specColor, out float ndl)
vec3 TubeLight(vec3 worldPos, vec3 lightVec, vec3 normal, vec3 toCamera, float roughness, vec3 specColor, vec3 diffColor, out float ndl)
{
float radius = cLightRad;
float len = cLightLength;
float radius = cLightRad / 100;
float len = cLightLength / 10;
vec3 pos = (cLightPosPS.xyz - worldPos);
vec3 reflectVec = reflect(-toCamera, normal);
@@ -60,20 +92,22 @@
vec3 l = normalize(closestPoint);
vec3 h = normalize(toCamera + l);
ndl = clamp(dot(normal, lightVec), 0.0, 1.0);
ndl = clamp(dot(normal, lightVec), 0.0, 1.0);
float hdn = clamp(dot(h, normal), 0.0, 1.0);
float hdv = dot(h, toCamera);
float ndv = clamp(dot(normal, toCamera), 0.0 ,1.0);
float ndv = clamp(dot(normal, toCamera), 0.0, 1.0);
float hdl = clamp(dot(h, lightVec), 0.0, 1.0);
float distL = length(closestPoint);
float alpha = roughness * roughness;
float alpha = max(roughness, 0.08) * max(roughness, 0.08);
float alphaPrime = clamp(radius / (distL * 2.0) + alpha, 0.0, 1.0);
vec3 fresnelTerm = Fresnel(specColor, hdv) ;
float distTerm = Distribution(hdn, alphaPrime);
float visTerm = Visibility(ndl, ndv, roughness);
return distTerm * visTerm * fresnelTerm ;
vec3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, hdv) * ndl;
vec3 fresnelTerm = Fresnel(specColor, hdv, hdl) ;
float distTerm = Distribution(hdn, roughness);
float visTerm = Visibility(ndl, ndv, roughness);
vec3 specularFactor = distTerm * visTerm * fresnelTerm * ndl/ M_PI;
return diffuseFactor + specularFactor;
}
//Return the PBR BRDF value
@@ -87,10 +121,11 @@
vec3 GetBRDF(vec3 worldPos, vec3 lightDir, vec3 lightVec, vec3 toCamera, vec3 normal, float roughness, vec3 diffColor, vec3 specColor)
{
vec3 Hn = normalize(toCamera + lightDir);
float vdh = clamp((dot(toCamera, Hn)), M_EPSILON, 1.0);
float ndh = clamp((dot(normal, Hn)), M_EPSILON, 1.0);
float ndl = clamp((dot(normal, lightVec)), M_EPSILON, 1.0);
float ndv = clamp((dot(normal, toCamera)), M_EPSILON, 1.0);
float vdh = clamp(dot(toCamera, Hn), M_EPSILON, 1.0);
float ndh = clamp(dot(normal, Hn), M_EPSILON, 1.0);
float ndl = clamp(dot(normal, lightVec), M_EPSILON, 1.0);
float ldh = clamp(dot(lightVec, Hn), M_EPSILON, 1.0);
float ndv = abs(dot(normal, toCamera)) + 1e-5;
vec3 diffuseFactor = Diffuse(diffColor, roughness, ndv, ndl, vdh);
vec3 specularFactor = vec3(0.0, 0.0, 0.0);
@@ -100,22 +135,23 @@
{
if(cLightLength > 0.0)
{
specularFactor = TubeLight(worldPos, lightVec, normal, toCamera, roughness, specColor, ndl);
specularFactor = TubeLight(worldPos, lightVec, normal, toCamera, roughness, specColor, diffColor, ndl);
specularFactor *= ndl;
}
else
{
specularFactor = SphereLight(worldPos, lightVec, normal, toCamera, roughness, specColor, ndl);
specularFactor = SphereLight(worldPos, lightVec, normal, toCamera, roughness, specColor, diffColor, ndl);
specularFactor *= ndl;
}
}
else
{
vec3 fresnelTerm = Fresnel(specColor, vdh) ;
vec3 fresnelTerm = Fresnel(specColor, vdh, ldh) ;
float distTerm = Distribution(ndh, roughness);
float visTerm = Visibility(ndl, ndv, roughness);
specularFactor = fresnelTerm * distTerm * visTerm / M_PI;
return diffuseFactor + specularFactor;
}
#endif
Oops, something went wrong.

0 comments on commit d91f7ab

Please sign in to comment.