summaryrefslogtreecommitdiffstats
path: root/src/extras/shaders/lighting.h
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2020-08-18 10:58:15 +0200
committeraap <aap@papnet.eu>2020-08-18 10:58:15 +0200
commitc556cbbbe016858537ebc2950e2803bcb85f93d5 (patch)
treeb301c8f091840a378b82b27806546a28abd6d221 /src/extras/shaders/lighting.h
parentMove stuff to vendor (diff)
downloadre3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar.gz
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar.bz2
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar.lz
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar.xz
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.tar.zst
re3-c556cbbbe016858537ebc2950e2803bcb85f93d5.zip
Diffstat (limited to 'src/extras/shaders/lighting.h')
-rw-r--r--src/extras/shaders/lighting.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/extras/shaders/lighting.h b/src/extras/shaders/lighting.h
new file mode 100644
index 00000000..4b081962
--- /dev/null
+++ b/src/extras/shaders/lighting.h
@@ -0,0 +1,44 @@
+struct Light
+{
+ float4 color; // and radius
+ float4 position; // and -cos(angle)
+ float4 direction; // and falloff clamp
+};
+
+float3 DoDirLight(Light L, float3 N)
+{
+ float l = max(0.0, dot(N, -L.direction.xyz));
+ return l*L.color.xyz;
+}
+
+float3 DoDirLightSpec(Light L, float3 N, float3 V, float power)
+{
+ return pow(saturate(dot(N, normalize(V + -L.direction.xyz))), power)*L.color.xyz;
+}
+
+float3 DoPointLight(Light L, float3 V, float3 N)
+{
+ // As on PS2
+ float3 dir = V - L.position.xyz;
+ float dist = length(dir);
+ float atten = max(0.0, (1.0 - dist/L.color.w));
+ float l = max(0.0, dot(N, -normalize(dir)));
+ return l*L.color.xyz*atten;
+}
+
+float3 DoSpotLight(Light L, float3 V, float3 N)
+{
+ // As on PS2
+ float3 dir = V - L.position.xyz;
+ float dist = length(dir);
+ float atten = max(0.0, (1.0 - dist/L.color.w));
+ dir /= dist;
+ float l = max(0.0, dot(N, -dir));
+ float pcos = dot(dir, L.direction.xyz); // cos to point
+ float ccos = -L.position.w; // cos of cone
+ float falloff = (pcos-ccos)/(1.0-ccos);
+ if(falloff < 0) // outside of cone
+ l = 0;
+ l *= max(falloff, L.direction.w); // falloff clamp
+ return l*L.color.xyz*atten;
+}