Navigation Menu

Skip to content

Commit

Permalink
Gloom|Renderer: Setting up a test light/entity
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 17, 2020
1 parent 8ec0250 commit d31fd85
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 17 deletions.
50 changes: 37 additions & 13 deletions doomsday/apps/client/src/render/gloomworldrenderer.cpp
Expand Up @@ -29,6 +29,7 @@
#include <gloom/world/map.h>
#include <gloom/render/icamera.h>
#include <gloom/render/maprender.h>
#include <gloom/render/lightrender.h>
#include <de/ImageBank>
#include <de/FS>
#include <de/Value>
Expand Down Expand Up @@ -66,22 +67,27 @@ DE_PIMPL(GloomWorldRenderer)
viewdata_t *vd = &player->viewport();

pos = vd->current.origin.xzy() * metersPerUnit * worldMirror;
up = vd->upVec * worldMirror;
front = vd->frontVec * worldMirror;
up = vd->upVec; // * worldMirror;
front = vd->frontVec; // * worldMirror;

// These axis flips are a bit silly, but they are here because the view matrices
// come from Doomsday's old renderer. They also assume clockwise triangle winding.
// Gloom uses counterclockwise (OpenGL default). We need to invert the coordinate
// axes accordingly.

mvMat = Mat4f::scale(metersPerUnit.x) *
/*mvMat = Mat4f::scale(metersPerUnit.x) * // matrix applied VGA aspect
Mat4f::rotate(180, Vec3f(0, 1, 0)) *
Rend_GetModelViewMatrix(console) *
Mat4f::scale(Vec3f(1.0f) / metersPerUnit) *
Mat4f::scale(worldMirror);
Mat4f::scale(worldMirror);*/

mvMat = Mat4f::rotate(vd->current.pitch * 85.0f / 110.0f, Vec3f(-1, 0, 0)) *
Mat4f::rotate(float(vd->current.angle()) / float(ANG180) * 180 - 90.0f,
Vec3f(0, -1, 0)) *
Mat4f::translate(-pos);

projMat = Rend_GetProjectionMatrix(0.0f, metersPerUnit.x /* clip planes in meters */) *
Mat4f::scale(Vec3f(-1, 1, -1));
Mat4f::scale(Vec3f(1, 1, -1));
}

Vec3f cameraPosition() const
Expand Down Expand Up @@ -110,11 +116,12 @@ DE_PIMPL(GloomWorldRenderer)
}
};

PlayerCamera playerCamera;
std::unique_ptr<gloom::World> glWorld;
Set<const world::Plane *> planesToUpdate;
List<gloom::ID> sectorLut; // sector number => gloom ID
ImageBank images;
PlayerCamera playerCamera;
std::unique_ptr<gloom::World> glWorld;
Set<const world::Plane *> planesToUpdate;
List<gloom::ID> sectorLut; // sector number => gloom ID
ImageBank images;
std::shared_ptr<gloom::Entity> testLight;

Impl(Public *i) : Base(i)
{
Expand Down Expand Up @@ -169,10 +176,21 @@ void GloomWorldRenderer::loadMap(const String &mapId)
*i++ = value->asUInt();
}
}

// Test light.
{
d->testLight = std::make_shared<gloom::Entity>();
d->testLight->setType(gloom::Entity::Light);
auto &map = d->glWorld->map();
map.append(map.entities(), d->testLight);

d->glWorld->mapRender().rebuild();
}
}

void GloomWorldRenderer::unloadMap()
{
d->testLight.reset();
d->sectorLut.clear();
}

Expand All @@ -195,11 +213,17 @@ void GloomWorldRenderer::advanceTime(TimeSpan elapsed)
plane->initialHeightOfMovement(),
plane->movementBeganAt(),
plane->speed() * TICSPERSEC);

// TODO: Pass the target height and speed to glWorld and let the shaders update
// the heights on the GPU. Only update the plane heights buffer when a move begins.
}
}

// Test light.
if (d->testLight)
{
Vec3d delta = d->playerCamera.cameraPosition() - d->testLight->position();

d->testLight->setPosition(d->testLight->position() + delta * elapsed * 0.5);
}

d->glWorld->update(elapsed);
d->glWorld->setCurrentTime(world::World::get().time());
// TODO: time sync should happen once, and after that `elapsed` should be scaled
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gloom/include/gloom/render/lightrender.h
Expand Up @@ -32,7 +32,7 @@ class Light;
/**
* Renders light source shadow maps and the deferred shading pass.
*/
class LightRender : public Render
class LIBGLOOM_PUBLIC LightRender : public Render
{
public:
LightRender();
Expand Down
1 change: 1 addition & 0 deletions doomsday/libs/gloom/include/gloom/world.h
Expand Up @@ -57,6 +57,7 @@ class LIBGLOOM_PUBLIC World : public IWorld
void update(TimeSpan elapsed);
void render(const ICamera &camera);

Map & map();
const Map &map() const;
MapRender &mapRender();
User * localUser() const;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libs/gloom/src/render/light.cpp
Expand Up @@ -92,7 +92,8 @@ Vec3d Light::origin() const
if (d->entity)
{
const auto p = d->entity->position();
return p + Vec3d(0, 2, 0); // <---TESTING---
// TODO: Add the light origin within entity.
return p; // + Vec3d(0, 2, 0); // <---TESTING---
}
return d->origin;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libs/gloom/src/render/lightrender.cpp
Expand Up @@ -578,7 +578,7 @@ void LightRender::createLights()
light->setEntity(ent);
light->setType(Light::Omni);
light->setCastShadows(true);
light->setIntensity(Vec3f(15, 15, 15));
light->setIntensity(Vec3f(25, 25, 25));
d->lights.insert(ent->id(), light);
d->activeLights.insert(light.get());
}
Expand Down
9 changes: 8 additions & 1 deletion doomsday/libs/gloom/src/world.cpp
Expand Up @@ -237,9 +237,10 @@ DE_PIMPL(World), public Asset
currentTime += elapsed;
renderContext.uCurrentTime = float(currentTime);

updateEntities(elapsed);
// updateEntities(elapsed);
}

#if 0
void updateEntities(TimeSpan)
{
for (const auto &i : map.entities())
Expand All @@ -250,6 +251,7 @@ DE_PIMPL(World), public Asset
ent.setPosition(pos);
}
}
#endif
};

World::World(GLShaderBank &shaders, ImageBank &images)
Expand Down Expand Up @@ -408,6 +410,11 @@ void World::render(const ICamera &camera)
#endif
}

Map &World::map()
{
return d->map;
}

User *World::localUser() const
{
return d->localUser;
Expand Down

0 comments on commit d31fd85

Please sign in to comment.