Skip to content

Commit

Permalink
Changed lighting type definition in fragment shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
dorosch committed Sep 15, 2022
1 parent 0683f62 commit c5b197e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
16 changes: 8 additions & 8 deletions resources/shaders/default.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#version 420 core

#define DIRECTIONAL 0
#define POINT 1
#define SPOT 2

struct Light {
// Only for directional lighting
vec3 direction;
Expand All @@ -13,11 +17,7 @@ struct Light {
float cutOff;
float outerCutOff;

// Type of lighting
int isDirection;
int isPoint;
int isSpot;

int type;
vec3 position;
vec3 color;
vec3 ambient;
Expand Down Expand Up @@ -46,13 +46,13 @@ void main() {
vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPosition - FragPos);

if (light.isDirection == 1) {
if (light.type == DIRECTIONAL) {
result = calculateDirectionLight(light, norm, viewDir);
}
else if (light.isPoint == 1) {
else if (light.type == POINT) {
result = calculatePointLight(light, norm, FragPos, viewDir);
}
else if (light.isSpot == 1) {
else if (light.type == SPOT) {
result = calculateSpotLight(light, norm, FragPos, viewDir);
}

Expand Down
17 changes: 8 additions & 9 deletions resources/shaders/material.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#version 420 core

#define DIRECTIONAL 0
#define POINT 1
#define SPOT 2

struct Light {
// Only for directional lighting
vec3 direction;
Expand All @@ -13,12 +17,7 @@ struct Light {
float cutOff;
float outerCutOff;

// TODO: Investigate to change on boolean
// Type of lighting
int isDirection;
int isPoint;
int isSpot;

int type;
vec3 position;
vec3 color;
vec3 ambient;
Expand Down Expand Up @@ -55,13 +54,13 @@ void main() {
vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPosition - FragPos);

if (light.isDirection == 1) {
if (light.type == DIRECTIONAL) {
result = calculateDirectionLight(light, material, norm, viewDir);
}
else if (light.isPoint == 1) {
else if (light.type == POINT) {
result = calculatePointLight(light, material, norm, FragPos, viewDir);
}
else if (light.isSpot == 1) {
else if (light.type == SPOT) {
result = calculateSpotLight(light, material, norm, FragPos, viewDir);
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/render/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,22 @@ void Render::RenderObject(Object *object, glm::mat4 projection, glm::mat4 view,
shader->UniformFloat("light.intensity", lighting->light->intensity);

if (lighting->light->lightType == Graphics::Lighting::Type::DIRECTIONAL) {
shader->UniformInt("light.type", Graphics::Lighting::Type::DIRECTIONAL);
shader->UniformPosition(
"light.direction",
lighting->light->direction.x,
lighting->light->direction.y,
lighting->light->direction.z
);
shader->UniformInt("light.isDirection", 1);
}
else if (lighting->light->lightType == Graphics::Lighting::Type::POINT) {
shader->UniformInt("light.type", Graphics::Lighting::Type::POINT);
shader->UniformFloat("light.constant", lighting->light->constant);
shader->UniformFloat("light.linear", lighting->light->linear);
shader->UniformFloat("light.quadratic", lighting->light->quadratic);
shader->UniformInt("light.isPoint", 1);
}
else if (lighting->light->lightType == Graphics::Lighting::Type::SPOT) {
shader->UniformInt("light.isSpot", 1);
shader->UniformInt("light.type", Graphics::Lighting::Type::SPOT);
shader->UniformPosition(
"light.direction",
lighting->light->direction.x,
Expand Down

0 comments on commit c5b197e

Please sign in to comment.