From c5b197eb03c3036620f9343a93e1589d43975dfd Mon Sep 17 00:00:00 2001 From: Andrey Doroschenko Date: Thu, 15 Sep 2022 10:53:22 +0300 Subject: [PATCH] Changed lighting type definition in fragment shaders --- resources/shaders/default.frag | 16 ++++++++-------- resources/shaders/material.frag | 17 ++++++++--------- src/core/render/api.cpp | 6 +++--- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/resources/shaders/default.frag b/resources/shaders/default.frag index 29244e5..7f7de8f 100644 --- a/resources/shaders/default.frag +++ b/resources/shaders/default.frag @@ -1,5 +1,9 @@ #version 420 core +#define DIRECTIONAL 0 +#define POINT 1 +#define SPOT 2 + struct Light { // Only for directional lighting vec3 direction; @@ -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; @@ -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); } diff --git a/resources/shaders/material.frag b/resources/shaders/material.frag index 25be696..f7b9b7d 100644 --- a/resources/shaders/material.frag +++ b/resources/shaders/material.frag @@ -1,5 +1,9 @@ #version 420 core +#define DIRECTIONAL 0 +#define POINT 1 +#define SPOT 2 + struct Light { // Only for directional lighting vec3 direction; @@ -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; @@ -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); } diff --git a/src/core/render/api.cpp b/src/core/render/api.cpp index a90b491..95e7679 100644 --- a/src/core/render/api.cpp +++ b/src/core/render/api.cpp @@ -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,