Skip to content

Commit 976108d

Browse files
committed
improve lighting calculations
1 parent fbeee24 commit 976108d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Assets/Shaders/DirectVolumeRenderingShader.shader

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include "UnityCG.cginc"
4848
#include "Include/TricubicSampling.cginc"
4949

50-
#define AMBIENT_LIGHTING_FACTOR 0.5
50+
#define AMBIENT_LIGHTING_FACTOR 0.2
5151
#define JITTER_FACTOR 5.0
5252

5353
struct vert_in
@@ -252,13 +252,15 @@
252252
// Optimised version of: if(dot(normal, eyeDir) < 0.0) normal *= -1.0
253253
normal *= (step(0.0, dot(normal, eyeDir)) * 2.0 - 1.0);
254254

255-
float ndotl = max(lerp(0.0f, 1.5f, dot(normal, lightDir)), AMBIENT_LIGHTING_FACTOR);
255+
float ndotl = max(dot(normal, lightDir), 0.0f);
256256
float3 diffuse = ndotl * col;
257+
float3 ambient = AMBIENT_LIGHTING_FACTOR * col;
257258
float3 v = eyeDir;
258259
float3 r = normalize(reflect(-lightDir, normal));
259260
float rdotv = max( dot( r, v ), 0.0 );
260261
float3 specular = pow(rdotv, 32.0f) * float3(1.0f, 1.0f, 1.0f) * specularIntensity;
261-
return diffuse + specular;
262+
float3 result = diffuse + ambient + specular;
263+
return float3(min(result.r, 1.0f), min(result.g, 1.0f), min(result.b, 1.0f));
262264
}
263265

264266
float calculateShadow(float3 pos, float3 lightDir)
@@ -355,6 +357,7 @@
355357
#if defined(TF2D_ON) || defined(LIGHTING_ON)
356358
float3 gradient = getGradient(currPos);
357359
float gradMag = length(gradient);
360+
358361
float gradMagNorm = gradMag / 1.75f;
359362
#endif
360363

0 commit comments

Comments
 (0)