Getters/Setters for basic lights

This commit is contained in:
Dane Johnson 2021-03-02 11:48:18 -06:00
parent ec0eedddcb
commit 6efd17da5a
4 changed files with 100 additions and 12 deletions

View File

@ -22,7 +22,37 @@
*/
#include "Light.h"
Name Light::GetType() const {return "Light";}
Vector3 Light::GetColor() {
return color;
}
void Light::SetColor(Vector3 color) {
this->color = color;
}
float Light::GetAmbient() {
return ambient;
}
void Light::SetAmbient(float ambient) {
this->ambient = ambient;
}
float Light::GetDiffuse() {
return diffuse;
}
void Light::SetDiffuse(float diffuse) {
this->diffuse = diffuse;
}
float Light::GetSpecular() {
return specular;
}
void Light::SetSpecular(float specular) {
this->specular = specular;
}
Light *Light::Duplicate() {
Light *light = static_cast<Light*>(Spatial::Duplicate());
@ -42,6 +72,8 @@ Light *Light::Create() {
return new Light;
}
Name Light::GetType() const {return "Light";}
Name DirectionalLight::GetType() const {return "DirectionalLight";}
DirectionalLight::DirectionalLight() {

View File

@ -27,16 +27,72 @@
#include "types.h"
#include "Spatial.h"
/**
All lights have color as well as ambient, diffuse, and specular properties.
In the future, light properties might be a color, but for now they are
strength modulations on the main light color.
*/
class Light : public Spatial {
public:
Vector3 color;
float ambient, diffuse, specular;
virtual Name GetType() const;
/**
Get the color property of this light
@returns The color property
*/
Vector3 GetColor();
/**
Set the color property of this light
@param color The desired color.
*/
void SetColor(Vector3 color);
/** Ambient light is how much light is emitted from an object illuminated by
this light with no accounting for incidence angle or the location of the observer.
@returns The ambient intensity
*/
float GetAmbient();
/** Set the ambient light intensity.
@param ambient The desired ambient intensity for this light.
*/
void SetAmbient(float ambient);
/** Diffuse light is how much light is reflected by an object illuminated
by this light, accounting for incidence angle of the light but not the
location of the observer.
@returns The diffuse intensity.
*/
float GetDiffuse();
/** Set the diffuse intensity.
@param diffuse The desired diffuse intensity for this light
*/
void SetDiffuse(float diffuse);
/** Specular light is how much light is reflected by an object illuminated
by this light, taking into account both the incidence angle of the light
as well as the location of the observer. This is what creates the
"Specular Artifact", the shiny bit on a 3D sphere.
@returns The specular intensity
*/
float GetSpecular();
/** Set the specular intensity.
@param specular The desired specular intensity for this light.
*/
void SetSpecular(float specular);
virtual Light *Create();
virtual Light *Duplicate();
virtual Light *Instance();
virtual Name GetType() const;
protected:
Vector3 color;
float ambient, diffuse, specular;
};
/**
Directional lights are infinitely far away lights that illuminate the whole world.
*/
class DirectionalLight : public Light {
public:
Vector3 direction;

View File

@ -75,11 +75,11 @@ void Shader::UpdateMaterial(Material material) {
void Shader::UpdateDirectionalLight(DirectionalLight directionalLight) {
glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.direction));
glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.color));
glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.GetColor()));
glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.ambient);
glUniform1f(glGetUniformLocation(id, "directionalLight.diffuse"), directionalLight.diffuse);
glUniform1f(glGetUniformLocation(id, "directionalLight.specular"), directionalLight.specular);
glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.GetAmbient());
glUniform1f(glGetUniformLocation(id, "directionalLight.diffuse"), directionalLight.GetDiffuse());
glUniform1f(glGetUniformLocation(id, "directionalLight.specular"), directionalLight.GetSpecular());
}
Name Shader::GetName() const {

View File

@ -38,10 +38,10 @@ function init()
local light = couch.DirectionalLight()
light.direction = couch.Vector3(0.0, -1.0, -1.0)
light.color = couch.Vector3(1.0, 1.0, 1.0)
light.ambient = 0.2
light.diffuse = 1.0
light.specular = 0.1
light:SetColor(couch.Vector3(1.0, 1.0, 1.0))
light:SetAmbient(0.2)
light:SetDiffuse(1.0)
light:SetSpecular(0.1)
couch.Node.GetRoot():AddChild(light:Instance())
local skybox = couch.Skybox.FromFiles(