mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Add derivative-based normal mapping to terrain for per-pixel detail
This commit is contained in:
parent
f2f6ffd2cd
commit
b7da2408c8
2 changed files with 14 additions and 0 deletions
|
|
@ -85,6 +85,20 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
|
|
||||||
|
// Derivative-based normal mapping: perturb vertex normal using texture detail
|
||||||
|
{
|
||||||
|
float lum = dot(finalColor.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
float dLdx = dFdx(lum);
|
||||||
|
float dLdy = dFdy(lum);
|
||||||
|
vec3 dpdx = dFdx(FragPos);
|
||||||
|
vec3 dpdy = dFdy(FragPos);
|
||||||
|
// Bump strength controls how much texture detail affects lighting
|
||||||
|
const float bumpStrength = 9.0;
|
||||||
|
vec3 perturbation = (dLdx * cross(norm, dpdy) + dLdy * cross(dpdx, norm)) * bumpStrength;
|
||||||
|
norm = normalize(norm - perturbation);
|
||||||
|
}
|
||||||
|
|
||||||
vec3 lightDir2 = normalize(-lightDir.xyz);
|
vec3 lightDir2 = normalize(-lightDir.xyz);
|
||||||
vec3 ambient = ambientColor.rgb * finalColor.rgb;
|
vec3 ambient = ambientColor.rgb * finalColor.rgb;
|
||||||
float diff = max(abs(dot(norm, lightDir2)), 0.2);
|
float diff = max(abs(dot(norm, lightDir2)), 0.2);
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue