ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
LightMaterial.tpp
Go to the documentation of this file.
1#pragma once
2
3template<size_t lightCount>
4LightMaterial<lightCount>::LightMaterial() {
5 for (uint8_t i = 0; i < lightCount; i++){
6 lights[lightCount].Set(Vector3D(1000, 0, 0), Vector3D(255, 0, 0), 1000.0f, 0.5f, 0.5f);
7 }
8}
9
10template<size_t lightCount>
11Light* LightMaterial<lightCount>::GetLights(){
12 return &lights[0];
13}
14
15template<size_t lightCount>
16uint8_t LightMaterial<lightCount>::GetLightCount(){
17 return lightCount;
18}
19
20template<size_t lightCount>
21RGBColor LightMaterial<lightCount>::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
22 Vector3D color;
23
24 for (uint8_t l = 0; l < lightCount; l++) {
25 Vector3D lVector = lights[l].GetPosition();
26
27 float angle = normal.DotProduct(lVector.UnitSphere());
28
29 if (angle > 0) {
30 float lDistance = lights[l].GetPosition().CalculateEuclideanDistance(position) / lights[l].GetFalloff();
31 float intensity = 1.0f / (1.0f + lDistance * lights[l].GetCurveA() + powf(lDistance / lights[l].GetFalloff(), 2.0f) * lights[l].GetCurveB());
32
33 color = color + (lights[l].GetIntensity() * angle * intensity);
34 }
35 }
36
37 return RGBColor(color);
38}