Modify lighting to use a point light
This commit is contained in:
7 files changed
+183
-81
No files matched your search
+64
-21
@@ -20,18 +20,6 @@ struct ColorU32
|
||||
struct ColorF32
|
||||
{
|
||||
float b, g, r, a;
|
||||
|
||||
static inline ColorU32 ConvertToU32(ColorF32 c)
|
||||
{
|
||||
ColorU32 result;
|
||||
|
||||
result.b = (uint8_t)(c.b * 255);
|
||||
result.g = (uint8_t)(c.g * 255);
|
||||
result.r = (uint8_t)(c.r * 255);
|
||||
result.a = (uint8_t)(c.a * 255);
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -41,10 +29,10 @@ inline ColorF32 operator+(ColorF32 c1, ColorF32 c2)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
result.b = MIN((c1.b + c2.b), 1.0f);
|
||||
result.g = MIN((c1.g + c2.g), 1.0f);
|
||||
result.r = MIN((c1.r + c2.r), 1.0f);
|
||||
result.a = MIN((c1.a + c2.a), 1.0f);
|
||||
result.b = c1.b + c2.b;
|
||||
result.g = c1.g + c2.g;
|
||||
result.r = c1.r + c2.r;
|
||||
result.a = c1.a + c2.a;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -54,7 +42,7 @@ inline ColorF32 &operator+=(ColorF32 &c1, ColorF32 c2)
|
||||
{
|
||||
c1 = c1 + c2;
|
||||
|
||||
return(c1);
|
||||
return c1;
|
||||
}
|
||||
|
||||
// c * f
|
||||
@@ -62,10 +50,10 @@ inline ColorF32 operator*(ColorF32 c, float f)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
result.b = MIN((f * c.b), 1.0f);
|
||||
result.g = MIN((f * c.g), 1.0f);
|
||||
result.r = MIN((f * c.r), 1.0f);
|
||||
result.a = MIN((f * c.a), 1.0f);
|
||||
result.b = f * c.b;
|
||||
result.g = f * c.g;
|
||||
result.r = f * c.r;
|
||||
result.a = f * c.a;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -80,6 +68,61 @@ inline ColorF32 operator*(float f, ColorF32 c)
|
||||
return result;
|
||||
}
|
||||
|
||||
// c1 * c2
|
||||
inline ColorF32 operator*(ColorF32 c1, ColorF32 c2)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
result.b = c1.b * c2.b;
|
||||
result.g = c1.g * c2.g;
|
||||
result.r = c1.r * c2.r;
|
||||
result.a = c1.a * c2.a;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// c / f
|
||||
inline ColorF32 operator/(ColorF32 c, float f)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
float invF = 1.0f / f;
|
||||
|
||||
result.b = c.b * invF;
|
||||
result.g = c.g * invF;
|
||||
result.r = c.r * invF;
|
||||
result.a = c.a * invF;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// c /= f
|
||||
inline ColorF32 &operator/=(ColorF32 &c, float f)
|
||||
{
|
||||
c = c / f;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
inline void ScaleColor(ColorF32 &c)
|
||||
{
|
||||
float blue = MAX(c.b, 0.0f);
|
||||
float green = MAX(c.g, 0.0f);
|
||||
float red = MAX(c.r, 0.0f);
|
||||
float alpha = MAX(c.a, 0.0f);
|
||||
float max = MAX(MAX(MAX(blue,green),red),1.0f);
|
||||
|
||||
ColorF32 scaled = {blue, green, red, alpha};
|
||||
scaled /= max;
|
||||
|
||||
c.b = scaled.b;
|
||||
c.g = scaled.g;
|
||||
c.r = scaled.r;
|
||||
c.a = scaled.a;
|
||||
}
|
||||
|
||||
|
||||
#define COLOR_H
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
// GEOMETRY CONFIGURATION
|
||||
#define FACE_LIMIT (30000)
|
||||
#define MATERIAL_LIMIT (10)
|
||||
#define MATERIAL_LIMIT (5)
|
||||
#define TEXTURE_SIZE_LIMIT (1024)
|
||||
#define VERTEX_LIMIT (20000)
|
||||
|
||||
|
||||
+9
-33
@@ -2,47 +2,23 @@
|
||||
|
||||
|
||||
#include "color.h"
|
||||
#include "vec.h"
|
||||
#include <cstdint>
|
||||
#include "geometry.h"
|
||||
#include "point.h"
|
||||
|
||||
|
||||
// STRUCTURES
|
||||
struct LightAmbient
|
||||
struct Light
|
||||
{
|
||||
inline ColorF32 ComputeColor(ColorF32 reflectivity)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
result = reflectivity * intensity;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Point position;
|
||||
ColorF32 color;
|
||||
float intensity;
|
||||
float falloffConstant;
|
||||
float falloffLinear;
|
||||
};
|
||||
|
||||
struct LightDiffuse
|
||||
{
|
||||
inline ColorF32 ComputeColor(ColorF32 reflectivity, Vector normal)
|
||||
{
|
||||
ColorF32 result;
|
||||
|
||||
float dot = Vector::Dot(normal, direction);
|
||||
|
||||
result = reflectivity * intensity * dot;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float intensity;
|
||||
Vector direction;
|
||||
};
|
||||
|
||||
struct LightList
|
||||
{
|
||||
LightAmbient ambient;
|
||||
LightDiffuse diffuse;
|
||||
};
|
||||
// PUBLIC FUNCTIONS
|
||||
ColorF32 ComputeLight(Vertex &vert, Material &material, Light &light);
|
||||
|
||||
|
||||
#define LIGHT_H
|
||||
|
||||
Reference in new issue
Block a user