refactor: Drop directional light type for simplicity

This commit is contained in:
Vsevolod Kremianskii 2021-02-17 20:55:23 +07:00
parent 6ffd09db49
commit 455ba0e60c
7 changed files with 11 additions and 23 deletions

View file

@ -615,11 +615,9 @@ void main() {
float spec = pow(max(dot(N, H), 0.0), uMaterialShininess);
vec3 specular = uLights[i].color.rgb * spec * vec3(uMaterialSpecular);
if (uLights[i].position.w == 1.0) {
float attenuation = getLightAttenuation(i);
diffuse *= attenuation;
specular *= attenuation;
}
float attenuation = getLightAttenuation(i);
diffuse *= attenuation;
specular *= attenuation;
objectColor += (1.0 - shadow) * (diffuse + specular);
}
@ -737,11 +735,9 @@ void main() {
vec3 L = normalize(uLights[i].position.xyz - fragPosition);
vec3 H = normalize(V + L);
float attenuation = getLightAttenuation(i);
vec3 radiance = uLights[i].color.rgb;
if (uLights[i].position.w == 1.0) {
float attenuation = getLightAttenuation(i);
radiance *= attenuation;
}
radiance *= attenuation;
float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, roughness);

View file

@ -107,7 +107,7 @@ struct SkeletalUniforms {
};
struct ShaderLight {
glm::vec4 position { 0.0f }; /**< w = 0.0 indicates a directional light, and w = 1.0 indicates a point light */
glm::vec4 position { 0.0f };
glm::vec4 color { 1.0f };
float multiplier { 1.0f };
float radius { 1.0f };

View file

@ -25,9 +25,8 @@ namespace reone {
namespace scene {
LightSceneNode::LightSceneNode(LightType type, glm::vec3 color, int priority, SceneGraph *sceneGraph) :
LightSceneNode::LightSceneNode(glm::vec3 color, int priority, SceneGraph *sceneGraph) :
SceneNode(sceneGraph),
_type(type),
_color(move(color)),
_priority(priority) {
}

View file

@ -27,9 +27,8 @@ namespace scene {
class LightSceneNode : public SceneNode {
public:
LightSceneNode(LightType type, glm::vec3 color, int priority, SceneGraph *sceneGraph);
LightSceneNode(glm::vec3 color, int priority, SceneGraph *sceneGraph);
bool isDirectional() const { return _type == LightType::Directional; }
bool isShadow() const { return _shadow; }
bool isAmbientOnly() const { return _ambientOnly; }
@ -44,7 +43,6 @@ public:
void setAmbientOnly(bool ambientOnly);
private:
LightType _type;
glm::vec3 _color;
int _priority;

View file

@ -229,7 +229,7 @@ void ModelNodeSceneNode::renderSingle(bool shadowPass) {
for (int i = 0; i < uniforms.lighting.lightCount; ++i) {
ShaderLight &shaderLight = uniforms.lighting.lights[i];
shaderLight.position = glm::vec4(glm::vec3(lights[i]->absoluteTransform()[3]), lights[i]->isDirectional() ? 0.0f : 1.0f);
shaderLight.position = lights[i]->absoluteTransform()[3];
shaderLight.color = glm::vec4(lights[i]->color(), 1.0f);
shaderLight.multiplier = lights[i]->multiplier();
shaderLight.radius = lights[i]->radius();

View file

@ -122,14 +122,14 @@ void ModelSceneNode::initModelNodes() {
} else {
radius = 1.0f;
}
auto lightNode = make_shared<LightSceneNode>(LightType::Point, child->selfIllumColor(), kSelfIlluminatedPriority, _sceneGraph);
auto lightNode = make_shared<LightSceneNode>(child->selfIllumColor(), kSelfIlluminatedPriority, _sceneGraph);
lightNode->setRadius(radius);
childNode->addChild(lightNode);
}
shared_ptr<ModelNode::Light> light(child->light());
if (light) {
auto lightNode = make_shared<LightSceneNode>(LightType::Point, child->color(), light->priority, _sceneGraph);
auto lightNode = make_shared<LightSceneNode>(child->color(), light->priority, _sceneGraph);
lightNode->setMultiplier(child->multiplier());
lightNode->setRadius(child->radius());
lightNode->setShadow(light->shadow);

View file

@ -21,11 +21,6 @@ namespace reone {
namespace scene {
enum class LightType {
Directional,
Point
};
struct AnimationFlags {
static constexpr int loop = 1;
static constexpr int blend = 4; /**< blend previous animation into the next one */