Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # include/version.h
- Loading branch information
Showing
27 changed files
with
640 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#version 130 | ||
|
||
uniform sampler2D u_LightProjectionTexture; // light projection texture | ||
uniform sampler2D u_LightFallOffTexture; // light falloff texture | ||
uniform vec4 u_BlendColour; // light colour | ||
|
||
varying vec4 var_tex_atten_xy_z; | ||
|
||
void main() | ||
{ | ||
// Light texture lookups | ||
vec4 attenuation_xy = vec4(0,0,0,0); | ||
|
||
// Discard s/t coords outside the light texture (clamp) | ||
if (var_tex_atten_xy_z.x < 0 || var_tex_atten_xy_z.x > 1 || | ||
var_tex_atten_xy_z.y < 0 || var_tex_atten_xy_z.y > 1) | ||
{ | ||
discard; | ||
} | ||
|
||
if (var_tex_atten_xy_z.w > 0.0) | ||
{ | ||
attenuation_xy = texture2DProj(u_LightProjectionTexture, var_tex_atten_xy_z.xyw); | ||
} | ||
|
||
vec4 attenuation_z = texture2D(u_LightFallOffTexture, vec2(var_tex_atten_xy_z.z, 0.5)); | ||
|
||
gl_FragColor = u_BlendColour * attenuation_xy * attenuation_z; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#version 130 | ||
|
||
in vec4 attr_Position; // bound to attribute 0 in source, in object space | ||
|
||
uniform mat4 u_ModelViewProjection; // combined modelview and projection matrix | ||
uniform mat4 u_ObjectTransform; // object transform (object2world) | ||
uniform mat4 u_LightTextureMatrix; // light texture transform (world-to-light-UV) | ||
|
||
varying vec4 var_tex_atten_xy_z; | ||
|
||
void main() | ||
{ | ||
vec4 worldVertex = u_ObjectTransform * attr_Position; | ||
|
||
// calc light xy,z attenuation in light space | ||
var_tex_atten_xy_z = u_LightTextureMatrix * worldVertex; | ||
|
||
// Apply the supplied object transform to the incoming vertex | ||
// transform vertex position into homogenous clip-space | ||
gl_Position = u_ModelViewProjection * worldVertex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include "BlendLight.h" | ||
|
||
#include "OpenGLShader.h" | ||
#include "glprogram/BlendLightProgram.h" | ||
|
||
namespace render | ||
{ | ||
|
||
BlendLight::BlendLight(RendererLight& light, IGeometryStore& store, IObjectRenderer& objectRenderer) : | ||
_light(light), | ||
_store(store), | ||
_objectRenderer(objectRenderer), | ||
_lightBounds(light.lightAABB()), | ||
_objectCount(0) | ||
{} | ||
|
||
bool BlendLight::isInView(const IRenderView& view) | ||
{ | ||
return view.TestAABB(_lightBounds) != VOLUME_OUTSIDE; | ||
} | ||
|
||
void BlendLight::collectSurfaces(const IRenderView& view, const std::set<IRenderEntityPtr>& entities) | ||
{ | ||
// Now check all the entities intersecting with this light | ||
for (const auto& entity : entities) | ||
{ | ||
entity->foreachRenderableTouchingBounds(_lightBounds, | ||
[&](const IRenderableObject::Ptr& object, Shader* shader) | ||
{ | ||
// Skip empty objects and invisible surfaces | ||
if (!object->isVisible() || !shader->isVisible()) return; | ||
|
||
// Cull surfaces that are not in view | ||
if (object->isOriented()) | ||
{ | ||
if (view.TestAABB(object->getObjectBounds(), object->getObjectTransform()) == VOLUME_OUTSIDE) | ||
{ | ||
return; | ||
} | ||
} | ||
else if (view.TestAABB(object->getObjectBounds()) == VOLUME_OUTSIDE) // non-oriented AABB test | ||
{ | ||
return; | ||
} | ||
|
||
auto glShader = static_cast<OpenGLShader*>(shader); | ||
|
||
// We only consider materials designated for camera rendering | ||
if (!glShader->isApplicableTo(RenderViewType::Camera)) | ||
{ | ||
return; | ||
} | ||
|
||
// Blend lights only affect materials that interact with lighting | ||
if (!glShader->getInteractionPass()) | ||
{ | ||
return; | ||
} | ||
|
||
_objects.emplace_back(std::ref(*object)); | ||
|
||
++_objectCount; | ||
}); | ||
} | ||
} | ||
|
||
void BlendLight::draw(OpenGLState& state, RenderStateFlags globalFlagsMask, | ||
BlendLightProgram& program, const IRenderView& view, std::size_t time) | ||
{ | ||
program.setLightTextureTransform(_light.getLightTextureTransformation()); | ||
auto lightShader = static_cast<OpenGLShader*>(_light.getShader().get()); | ||
|
||
std::vector<IGeometryStore::Slot> untransformedObjects; | ||
untransformedObjects.reserve(500); | ||
|
||
lightShader->foreachPass([&](OpenGLShaderPass& pass) | ||
{ | ||
// Evaluate the stage before deciding whether it's active | ||
pass.evaluateShaderStages(time, &_light.getLightEntity()); | ||
|
||
if (!pass.stateIsActive()) return; | ||
|
||
// Apply our state to the current state object | ||
pass.applyState(state, globalFlagsMask); | ||
|
||
// The light textures will be bound by applyState. | ||
// The texture0/texture1 fields were filled in when constructing the pass | ||
|
||
program.setBlendColour(pass.state().getColour()); | ||
|
||
for (const auto& objectRef : _objects) | ||
{ | ||
auto& object = objectRef.get(); | ||
|
||
// We submit all objects with an identity matrix in a single multi draw call | ||
if (!object.isOriented()) | ||
{ | ||
untransformedObjects.push_back(object.getStorageLocation()); | ||
continue; | ||
} | ||
|
||
program.setObjectTransform(object.getObjectTransform()); | ||
|
||
_objectRenderer.submitGeometry(object.getStorageLocation(), GL_TRIANGLES); | ||
++_drawCalls; | ||
} | ||
|
||
if (!untransformedObjects.empty()) | ||
{ | ||
program.setObjectTransform(Matrix4::getIdentity()); | ||
|
||
_objectRenderer.submitGeometry(untransformedObjects, GL_TRIANGLES); | ||
++_drawCalls; | ||
|
||
untransformedObjects.clear(); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
#include "irender.h" | ||
|
||
namespace render | ||
{ | ||
|
||
class OpenGLState; | ||
class IGeometryStore; | ||
class IObjectRenderer; | ||
class BlendLightProgram; | ||
|
||
/** | ||
* BlendLights are non-shadowcasting lights performing a simple blend operation | ||
* on any surfaces they intersect with. | ||
* The type of blend operation is defined in the stages of the light material. | ||
* | ||
* Instances only live through the course of a single render pass, therefore direct | ||
* references without ref-counting are used. | ||
*/ | ||
class BlendLight | ||
{ | ||
private: | ||
RendererLight& _light; | ||
IGeometryStore& _store; | ||
IObjectRenderer& _objectRenderer; | ||
AABB _lightBounds; | ||
|
||
using ObjectList = std::vector<std::reference_wrapper<IRenderableObject>>; | ||
ObjectList _objects; | ||
|
||
std::size_t _objectCount; | ||
std::size_t _drawCalls; | ||
|
||
public: | ||
BlendLight(RendererLight& light, IGeometryStore& store, IObjectRenderer& objectRenderer); | ||
BlendLight(BlendLight&& other) = default; | ||
|
||
bool isInView(const IRenderView& view); | ||
void collectSurfaces(const IRenderView& view, const std::set<IRenderEntityPtr>& entities); | ||
|
||
std::size_t getObjectCount() const | ||
{ | ||
return _objectCount; | ||
} | ||
|
||
std::size_t getDrawCalls() const | ||
{ | ||
return _drawCalls; | ||
} | ||
|
||
void draw(OpenGLState& state, RenderStateFlags globalFlagsMask, BlendLightProgram& program, | ||
const IRenderView& view, std::size_t renderTime); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ enum class ShaderProgram | |
CubeMap, | ||
ShadowMap, | ||
RegularStage, | ||
BlendLight, | ||
}; | ||
|
||
/** | ||
|
Oops, something went wrong.