added shading to GeometryRenderer

parent 88006c0b
......@@ -33,6 +33,7 @@ in vec4 in_Color; ///< incoming color
out vec3 ex_TexCoord; ///< outgoing texture coordinate
out vec4 ex_Color; ///< outgoing color
out vec4 ex_Position; ///< outgoing world coordinates
/// Matrix defining model-to-world transformation
uniform mat4 _modelMatrix = mat4(
......@@ -58,6 +59,8 @@ uniform mat4 _projectionMatrix = mat4(
void main() {
gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
ex_Position = gl_Position;
ex_TexCoord = in_TexCoord;
ex_Color = in_Color;
}
......@@ -36,8 +36,8 @@ namespace campvis {
ProcessorDecoratorShading::ProcessorDecoratorShading(const std::string& lightUniformName /*= "_lightSource"*/)
: AbstractProcessorDecorator()
, _enableShading("EnableShading", "Enable Shading", true, AbstractProcessor::INVALID_SHADER)
, _centralDifferences("CentralDifferences", "Use Central instead of Forward Differences", false, AbstractProcessor::INVALID_SHADER)
, _enableShading("EnableShading", "Enable Shading", true, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT)
, _centralDifferences("CentralDifferences", "Use Central instead of Forward Differences", false, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT)
, _lightPosition("LightPosition", "Light Position", tgt::vec3(-8.f), tgt::vec3(-500.f), tgt::vec3(500.f))
, _ambientColor("AmbientColor", "Ambient Light Color", tgt::vec3(0.5f), tgt::vec3(0.f), tgt::vec3(1.f))
, _diffuseColor("DiffuseColor", "Diffuse Light Color", tgt::vec3(0.75f), tgt::vec3(0.f), tgt::vec3(1.f))
......
......@@ -27,11 +27,24 @@
//
// ================================================================================================
#include "tools/shading.frag"
in vec3 ex_TexCoord; ///< incoming texture coordinate
in vec4 ex_Position; ///< incoming texture coordinate
out vec4 out_Color; ///< outgoing fragment color
uniform vec4 _color;
uniform LightSource _lightSource;
uniform vec3 _cameraPosition;
void main() {
out_Color = _color;
#ifdef ENABLE_SHADING
// compute gradient (needed for shading and normals)
vec3 gradient = ex_TexCoord;
out_Color.rgb = calculatePhongShading(ex_Position.xyz / ex_Position.z, _lightSource, _cameraPosition, gradient, _color.rgb, _color.rgb, vec3(1.0, 1.0, 1.0));
#endif
}
......@@ -38,6 +38,7 @@
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/imagerepresentationrendertarget.h"
#include "core/datastructures/meshgeometry.h"
#include "core/pipeline/processordecoratorshading.h"
namespace campvis {
const std::string GeometryRenderer::loggerCat_ = "CAMPVis.modules.vis.GeometryRenderer";
......@@ -50,10 +51,14 @@ namespace campvis {
, p_color("color", "Rendering Color", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, _shader(0)
{
addDecorator(new ProcessorDecoratorShading());
addProperty(&p_geometryID);
addProperty(&p_renderTargetID);
addProperty(&p_camera);
addProperty(&p_color);
decoratePropertyCollection(this);
}
GeometryRenderer::~GeometryRenderer() {
......@@ -78,8 +83,15 @@ namespace campvis {
DataContainer::ScopedTypedData<GeometryData> proxyGeometry(data, p_geometryID.getValue());
if (proxyGeometry != 0 && _shader != 0) {
if (hasInvalidShader()) {
_shader->setHeaders(generateGlslHeader());
_shader->rebuild();
validate(INVALID_SHADER);
}
// set modelview and projection matrices
_shader->activate();
decorateRenderProlog(data, _shader);
_shader->setUniform("_projectionMatrix", p_camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", p_camera.getValue().getViewMatrix());
_shader->setUniform("_color", p_color.getValue());
......@@ -95,6 +107,7 @@ namespace campvis {
proxyGeometry->render();
rt.second->deactivate();
decorateRenderEpilog(_shader);
_shader->deactivate();
glDisable(GL_DEPTH_TEST);
LGL_ERROR;
......@@ -109,4 +122,9 @@ namespace campvis {
validate(INVALID_RESULT);
}
std::string GeometryRenderer::generateGlslHeader() const {
std::string toReturn = getDecoratedHeader();
return toReturn;
}
}
......@@ -33,6 +33,7 @@
#include <string>
#include "core/pipeline/visualizationprocessor.h"
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/properties/cameraproperty.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
......@@ -46,7 +47,7 @@ namespace campvis {
/**
* Genereates entry-/exit point textures for the given image and camera.
*/
class GeometryRenderer : public VisualizationProcessor {
class GeometryRenderer : public VisualizationProcessor, public HasProcessorDecorators {
public:
/**
* Constructs a new GeometryRenderer Processor
......@@ -78,6 +79,10 @@ namespace campvis {
Vec4Property p_color; ///< rendering color
protected:
/**
* Generates the GLSL header.
*/
std::string generateGlslHeader() const;
tgt::Shader* _shader; ///< Shader for EEP generation
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment