Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
STARK: Move maxShadowLength from RenderEntry to Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougaak committed Aug 4, 2018
1 parent fedd800 commit 801fc74
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
10 changes: 5 additions & 5 deletions engines/stark/gfx/openglsactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ OpenGLSActorRenderer::~OpenGLSActorRenderer() {
delete _shadowShader;
}

void OpenGLSActorRenderer::render(const Math::Vector3d &position, float direction, const LightEntryArray &lights, uint32 maxShadowLength) {
void OpenGLSActorRenderer::render(const Math::Vector3d &position, float direction, const LightEntryArray &lights) {
if (_modelIsDirty) {
// Update the OpenGL Buffer Objects if required
clearVertices();
Expand Down Expand Up @@ -136,7 +136,7 @@ void OpenGLSActorRenderer::render(const Math::Vector3d &position, float directio

Math::Matrix4 modelInverse = model;
modelInverse.inverse();
setShadowUniform(lights, position, maxShadowLength / 1000.0, modelInverse.getRotation());
setShadowUniform(lights, position, modelInverse.getRotation());

for (Common::Array<Face *>::const_iterator face = faces.begin(); face != faces.end(); ++face) {
GLuint ebo = _faceEBO[*face];
Expand Down Expand Up @@ -303,8 +303,8 @@ void OpenGLSActorRenderer::setLightArrayUniform(const LightEntryArray &lights) {
}
}

void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
float maxShadowLength, Math::Matrix3 worldToModelRot) {
void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights,
const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot) {
Math::Vector3d sumDirection;
bool hasLight = false;

Expand Down Expand Up @@ -339,7 +339,7 @@ void OpenGLSActorRenderer::setShadowUniform(const LightEntryArray &lights, const
if (hasLight) {
// Clip the horizontal length
Math::Vector2d horizontalProjection(sumDirection.x(), sumDirection.y());
float shadowLength = MIN(horizontalProjection.getMagnitude(), maxShadowLength);
float shadowLength = MIN(horizontalProjection.getMagnitude(), StarkScene->getMaxShadowLength());

horizontalProjection.normalize();
horizontalProjection *= shadowLength;
Expand Down
5 changes: 2 additions & 3 deletions engines/stark/gfx/openglsactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OpenGLSActorRenderer : public VisualActor {
OpenGLSActorRenderer(OpenGLSDriver *gfx);
virtual ~OpenGLSActorRenderer();

void render(const Math::Vector3d &position, float direction, const LightEntryArray &lights, uint32 maxShadowLength) override;
void render(const Math::Vector3d &position, float direction, const LightEntryArray &lights) override;

protected:
typedef Common::HashMap<Face *, uint32> FaceBufferMap;
Expand All @@ -62,8 +62,7 @@ class OpenGLSActorRenderer : public VisualActor {
void setBoneRotationArrayUniform(OpenGL::Shader *shader, const char *uniform);
void setLightArrayUniform(const LightEntryArray &lights);

void setShadowUniform(const LightEntryArray &lights, const Math::Vector3d &actorPosition,
float maxShadowLength, Math::Matrix3 worldToModelRot);
void setShadowUniform(const LightEntryArray &lights, const Math::Vector3d &actorPosition, Math::Matrix3 worldToModelRot);

bool getPointLightContribution(LightEntry *light, const Math::Vector3d &actorPosition,
Math::Vector3d &direction, float weight = 1.0f);
Expand Down
5 changes: 2 additions & 3 deletions engines/stark/gfx/renderentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ RenderEntry::RenderEntry(Resources::ItemVisual *owner, const Common::String &nam
_owner(owner),
_direction3D(0.0),
_sortKey(0.0),
_clickable(true),
_maxShadowLength(0) {
_clickable(true) {
}

void RenderEntry::render(const LightEntryArray &lights) {
Expand All @@ -61,7 +60,7 @@ void RenderEntry::render(const LightEntryArray &lights) {

VisualActor *actor = _visual->get<VisualActor>();
if (actor) {
actor->render(_position3D, _direction3D, lights, _maxShadowLength);
actor->render(_position3D, _direction3D, lights);
}

VisualProp *prop = _visual->get<VisualProp>();
Expand Down
3 changes: 0 additions & 3 deletions engines/stark/gfx/renderentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class RenderEntry {
void setPosition3D(const Math::Vector3d &position, float direction);
void setSortKey(float sortKey);
void setClickable(bool clickable);
void setMaxShadowLength(uint32 length) { _maxShadowLength = length; }

/** Gets the position */
Common::Point getPosition() const { return _position; }
Expand Down Expand Up @@ -116,8 +115,6 @@ class RenderEntry {
float _direction3D;
float _sortKey;
bool _clickable;

uint32 _maxShadowLength;
};

typedef Common::Array<RenderEntry *> RenderEntryArray;
Expand Down
8 changes: 6 additions & 2 deletions engines/stark/resources/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include "engines/stark/resources/item.h"
#include "engines/stark/resources/light.h"

#include "engines/stark/services/services.h"
#include "engines/stark/services/stateprovider.h"

#include "engines/stark/scene.h"

#include "common/debug.h"

namespace Stark {
Expand Down Expand Up @@ -220,6 +223,9 @@ Gfx::RenderEntry *Layer3D::getBackgroundRenderEntry() {
}

Gfx::RenderEntryArray Layer3D::listRenderEntries() {
// Set the shadow length
StarkScene->setMaxShadowLength(_maxShadowLength / 1000.0f);

// Sort the items by distance to the camera
Gfx::RenderEntryArray itemEntries;
for (uint i = 0; i < _items.size(); i++) {
Expand All @@ -233,8 +239,6 @@ Gfx::RenderEntryArray Layer3D::listRenderEntries() {
continue;
}

renderEntry->setMaxShadowLength(_maxShadowLength);

itemEntries.push_back(renderEntry);
}
}
Expand Down
3 changes: 2 additions & 1 deletion engines/stark/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Scene::Scene(Gfx::Driver *gfx) :
_nearClipPlane(100.0),
_farClipPlane(64000.0),
_fadeLevel(1.0),
_floatOffset(0.0) {
_floatOffset(0.0),
_maxShadowLength(0.075f) {
}

Scene::~Scene() {
Expand Down
6 changes: 6 additions & 0 deletions engines/stark/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class Scene {
void setFloatOffset(float floatOffset);
float getFloatOffset() const;

/** Access the maximum length of the horizontal light direction for casting shadows */
void setMaxShadowLength(float length) { _maxShadowLength = length; }
float getMaxShadowLength() const { return _maxShadowLength; }

private:
void computeClippingRect(float *xmin, float *xmax, float *ymin, float *ymax);

Expand All @@ -106,6 +110,8 @@ class Scene {
float _fadeLevel;
Math::Angle _swayAngle;
float _floatOffset;

float _maxShadowLength;
};

} // End of namespace Stark
Expand Down
2 changes: 1 addition & 1 deletion engines/stark/visual/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class VisualActor : public Visual {
void setCastShadow(bool cast) { _castsShadow = cast; }

bool intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction);
virtual void render(const Math::Vector3d &position, float direction, const Common::Array<Gfx::LightEntry *> &lights, uint32 maxShadowLength) = 0;
virtual void render(const Math::Vector3d &position, float direction, const Common::Array<Gfx::LightEntry *> &lights) = 0;

protected:
AnimHandler *_animHandler;
Expand Down

0 comments on commit 801fc74

Please sign in to comment.