-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Traktor: Refactored PBR lighting shaders.
- Loading branch information
Showing
7 changed files
with
1,503 additions
and
1,925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<object type="traktor.render.ShaderModule"> | ||
<text> | ||
<![CDATA[ | ||
// https://learnopengl.com/PBR/Lighting | ||
vec3 FresnelSchlick(float cosTheta, vec3 F0) | ||
{ | ||
cosTheta = max(cosTheta, 0.0f); | ||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); | ||
} | ||
float DistributionGGX(vec3 N, vec3 H, float roughness) | ||
{ | ||
const float PI = 3.14159265359f; | ||
const float a = roughness * roughness; | ||
const float a2 = a * a; | ||
const float NdotH = max(dot(N, H), 0.0f); | ||
const float NdotH2 = NdotH * NdotH; | ||
const float num = a2; | ||
float denom = (NdotH2 * (a2 - 1.0f) + 1.0f); | ||
denom = PI * denom * denom; | ||
return num / denom; | ||
} | ||
float GeometrySchlickGGX(float NdotV, float roughness) | ||
{ | ||
const float r = (roughness + 1.0f); | ||
const float k = (r * r) / 8.0f; | ||
const float num = NdotV; | ||
const float denom = NdotV * (1.0f - k) + k; | ||
return num / denom; | ||
} | ||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) | ||
{ | ||
const float NdotV = max(dot(N, V), 0.0f); | ||
const float NdotL = max(dot(N, L), 0.0f); | ||
const float ggx2 = GeometrySchlickGGX(NdotV, roughness); | ||
const float ggx1 = GeometrySchlickGGX(NdotL, roughness); | ||
return ggx1 * ggx2; | ||
} | ||
vec3 CalculateLighting(vec3 N, vec3 V, vec3 L, vec3 albedo, float metallic, float roughness, vec3 radiance) | ||
{ | ||
const float PI = 3.14159265359f; | ||
const vec3 H = normalize(V + L); | ||
const float NdotL = max(dot(N, L), 0.0f); | ||
const float NdotV = max(dot(N, V), 0.0f); | ||
const vec3 F0 = mix(vec3(0.04), albedo, metallic); | ||
const vec3 F = FresnelSchlick(max(dot(H, V), 0.0), F0); | ||
const float NDF = DistributionGGX(N, H, roughness); | ||
const float G = GeometrySmith(N, V, L, roughness); | ||
const vec3 numerator = NDF * G * F; | ||
const float denominator = 4.0f * NdotV * NdotL + 0.0001f; | ||
const vec3 specular = numerator / denominator; | ||
const vec3 kS = F; | ||
const vec3 kD = (vec3(1.0f) - kS) * (1.0f - metallic); | ||
return (kD * albedo / PI + specular) * radiance * NdotL; | ||
} | ||
vec3 CalculateReflection(vec3 N, vec3 V, vec3 albedo, float metallic, float roughness) | ||
{ | ||
// Use the view reflection vector as light direction. | ||
const vec3 L = -reflect(V, N); | ||
const vec3 H = normalize(V + L); | ||
const float NdotL = max(dot(N, L), 0.0f); | ||
const float NdotV = max(dot(N, V), 0.0f); | ||
const vec3 F0 = mix(vec3(0.04), albedo, metallic); | ||
const vec3 F = FresnelSchlick(max(dot(H, V), 0.0), F0); | ||
const float NDF = DistributionGGX(N, H, roughness); | ||
const float G = GeometrySmith(N, V, L, roughness); | ||
const vec3 numerator = NDF * G * F; | ||
const float denominator = 4.0f * NdotV * NdotL + 0.0001f; | ||
const vec3 specular = numerator / denominator; | ||
return clamp(specular, 0.0f, 1.0f); | ||
} | ||
]]> | ||
</text> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<object type="traktor.db.LocalInstanceMeta" version="2"> | ||
<guid>{8541C8B0-4A05-AA42-BFE7-7DBF639AAF8B}</guid> | ||
<primaryType>traktor.render.ShaderModule</primaryType> | ||
<blobs/> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<object type="traktor.world.IrradianceGridAsset" version="2"> | ||
<object type="traktor.world.IrradianceGridAsset" version="3"> | ||
<fileName></fileName> | ||
<intensity>1</intensity> | ||
<intensity>1.5</intensity> | ||
<saturation>0.25</saturation> | ||
<cancelSun>false</cancelSun> | ||
</object> |
Oops, something went wrong.