Commit e099cf39 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

First proof-of-concept implementation to use LightSourceData

* Introducing base module with LightSourceProvider processor
* Updated GeometryRenderer and GeometryRendererDemo to use LightSourceData instead of ProcessorDecoratorShading
* Introducing LightSourceData::bind()

refs #547
parent 2658175d
......@@ -31,6 +31,7 @@
#include "application/gui/qtdatahandle.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/lightsourcedata.h"
#include "core/datastructures/facegeometry.h"
#include "core/datastructures/meshgeometry.h"
#include "core/datastructures/indexedmeshgeometry.h"
......@@ -132,6 +133,10 @@ namespace campvis {
else if (const ImageSeries* tester = dynamic_cast<const ImageSeries*>(data)) {
return QVariant(QString("Image Series"));
}
else if (const LightSourceData* tester = dynamic_cast<const LightSourceData*>(data)) {
return QVariant(QString("Light Source"));
}
}
else
return QVariant();
......
......@@ -23,6 +23,7 @@
// ================================================================================================
#include "lightsourcedata.h"
#include "tgt/shadermanager.h"
namespace campvis {
......@@ -54,4 +55,13 @@ namespace campvis {
return 0;
}
void LightSourceData::bind(tgt::Shader* shader, const std::string& uniformName) const {
shader->setUniform(uniformName + "._position", _lightPosition);
shader->setUniform(uniformName + "._ambientColor", _ambientColor);
shader->setUniform(uniformName + "._diffuseColor", _diffuseColor);
shader->setUniform(uniformName + "._specularColor", _specularColor);
shader->setUniform(uniformName + "._shininess", _shininess);
shader->setUniform(uniformName + "._attenuation", _attenuation);
}
}
\ No newline at end of file
......@@ -34,6 +34,10 @@
#include "core/datastructures/abstractdata.h"
namespace tgt {
class Shader;
}
namespace campvis {
/**
......@@ -73,6 +77,13 @@ namespace campvis {
/// \see AbstractData::getVideoMemoryFootprint()
virtual size_t getVideoMemoryFootprint() const;
/**
* Binds this light source to the given shader by setting the corresponding uniforms.
* \param shader Shader to bind to.
* \param uniformName Uniform name to use.
*/
void bind(tgt::Shader* shader, const std::string& uniformName) const;
/**
* Gets the light positoin.
* \return _lightPosition
......
# CMake file for base module
IF(${ModuleEnabled})
# Source files:
FILE(GLOB ThisModSources RELATIVE ${ModulesDir}
modules/base/processors/*.cpp
)
# Header files (including GLSL files so that they'll appear in VS projects)
FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir}
modules/base/processors/*.h
)
ENDIF(${ModuleEnabled})
SET(ThisModStatus STABLE)
SET(ThisModExternalDependencies FALSE)
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "lightsourceprovider.h"
#include "core/datastructures/lightsourcedata.h"
namespace campvis {
const std::string LightSourceProvider::loggerCat_ = "CAMPVis.modules.io.LightSourceProvider";
LightSourceProvider::LightSourceProvider()
: AbstractProcessor()
, p_lightId("LightId", "Light Name/ID", "lightsource", DataNameProperty::WRITE)
, p_lightPosition("LightPosition", "Light Position", tgt::vec3(-100.f), tgt::vec3(-500.f), tgt::vec3(500.f), tgt::vec3(1.f))
, p_ambientColor("AmbientColor", "Ambient Light Color", tgt::vec3(0.4f), tgt::vec3(0.f), tgt::vec3(1.f))
, p_diffuseColor("DiffuseColor", "Diffuse Light Color", tgt::vec3(0.75f), tgt::vec3(0.f), tgt::vec3(1.f))
, p_specularColor("SpecularColor", "Specular Light Color", tgt::vec3(0.6f), tgt::vec3(0.f), tgt::vec3(1.f))
, p_shininess("Shininess", "Specular Shininess", 24.f, 0.f, 64.f, 0.5f)
, p_attenuation("Attenuation", "Attenuation Factors", tgt::vec3(0.f), tgt::vec3(0.f), tgt::vec3(1.f))
{
addProperty(p_lightId);
addProperty(p_lightPosition);
addProperty(p_ambientColor);
addProperty(p_diffuseColor);
addProperty(p_specularColor);
addProperty(p_shininess);
addProperty(p_attenuation);
}
LightSourceProvider::~LightSourceProvider() {
}
void LightSourceProvider::updateResult(DataContainer& data) {
LightSourceData* lsd = new LightSourceData(
p_lightPosition.getValue(),
p_ambientColor.getValue(),
p_diffuseColor.getValue(),
p_specularColor.getValue(),
p_shininess.getValue(),
p_attenuation.getValue());
data.addData(p_lightId.getValue(), lsd);
validate(INVALID_RESULT);
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef LIGHTSOURCEPROVIDER_H__
#define LIGHTSOURCEPROVIDER_H__
#include <string>
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
namespace campvis {
/**
* Creates LightSourceData and stores it in the DataContainer.
* \see LightSourceData
*/
class LightSourceProvider : public AbstractProcessor {
public:
/**
* Constructs a new LightSourceProvider Processor.
**/
LightSourceProvider();
/**
* Destructor
**/
virtual ~LightSourceProvider();
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "LightSourceProvider"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Creates LightSourceData and stores it in the DataContainer."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Christian Schulte zu Berge <christian.szb@in.tum.de>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::STABLE; };
DataNameProperty p_lightId; ///< Name/ID for the LightSource to create
Vec3Property p_lightPosition; ///< Light position
Vec3Property p_ambientColor; ///< Ambient light color
Vec3Property p_diffuseColor; ///< Diffuse light color
Vec3Property p_specularColor; ///< Specular light color
FloatProperty p_shininess; ///< Specular shininess
Vec3Property p_attenuation; ///< Attenuation factors
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
static const std::string loggerCat_;
};
}
#endif // LIGHTSOURCEPROVIDER_H__
......@@ -39,6 +39,7 @@ namespace campvis {
GeometryRendererDemo::GeometryRendererDemo(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _camera("camera", "Camera")
, _lsp()
, _geometryReader()
, _lvRenderer(&_canvasSize)
, _teapotRenderer(&_canvasSize)
......@@ -52,6 +53,7 @@ namespace campvis {
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
addEventListenerToBack(_trackballEH);
addProcessor(&_lsp);
addProcessor(&_geometryReader);
addProcessor(&_teapotRenderer);
addProcessor(&_lvRenderer);
......
......@@ -28,6 +28,7 @@
#include "core/eventhandlers/trackballnavigationeventlistener.h"
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/vtkimagereader.h"
#include "modules/vis/processors/geometryrenderer.h"
#include "modules/vis/processors/rendertargetcompositor.h"
......@@ -65,6 +66,8 @@ namespace campvis {
virtual void onProcessorValidated(AbstractProcessor* processor);
CameraProperty _camera;
LightSourceProvider _lsp;
VtkImageReader _geometryReader;
GeometryRenderer _lvRenderer;
GeometryRenderer _teapotRenderer;
......
......@@ -30,6 +30,7 @@
#include "tgt/textureunit.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/lightsourcedata.h"
#include "core/datastructures/renderdata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/meshgeometry.h"
......@@ -60,6 +61,8 @@ namespace campvis {
, p_textureID("TextureId", "Input Texture ID (optional)", "gr.inputtexture", DataNameProperty::READ)
, p_renderTargetID("p_renderTargetID", "Output Image", "gr.output", DataNameProperty::WRITE)
, p_camera("camera", "Camera")
, p_enableShading("EnableShading", "Enable Shading", true)
, p_lightId("LightId", "Input Light Source", "lightsource", DataNameProperty::READ)
, p_renderMode("RenderMode", "Render Mode", renderOptions, 7)
, p_coloringMode("ColoringMode", "ColoringMode", coloringOptions, 3)
, p_solidColor("SolidColor", "Solid Color", tgt::vec4(1.f, .5f, 0.f, 1.f), tgt::vec4(0.f), tgt::vec4(1.f))
......@@ -72,13 +75,14 @@ namespace campvis {
{
p_coloringMode.selectByOption(SOLID_COLOR);
addDecorator(new ProcessorDecoratorShading());
addProperty(p_geometryID);
addProperty(p_textureID);
addProperty(p_renderTargetID);
addProperty(p_camera);
addProperty(p_enableShading, INVALID_RESULT | INVALID_PROPERTIES | INVALID_SHADER);
addProperty(p_lightId);
addProperty(p_renderMode, INVALID_RESULT | INVALID_PROPERTIES);
addProperty(p_coloringMode, INVALID_RESULT | INVALID_SHADER | INVALID_PROPERTIES);
addProperty(p_solidColor);
......@@ -87,8 +91,6 @@ namespace campvis {
addProperty(p_lineWidth);
addProperty(p_showWireframe, INVALID_RESULT | INVALID_SHADER | INVALID_PROPERTIES);
addProperty(p_wireframeColor);
decoratePropertyCollection(this);
}
GeometryRenderer::~GeometryRenderer() {
......@@ -112,6 +114,7 @@ namespace campvis {
void GeometryRenderer::updateResult(DataContainer& data) {
ScopedTypedData<GeometryData> proxyGeometry(data, p_geometryID.getValue());
ScopedTypedData<LightSourceData> light(data, p_lightId.getValue());
ScopedTypedData<RenderData> rd(data, p_textureID.getValue());
ImageRepresentationGL::ScopedRepresentation repGl(data, p_textureID.getValue());
......@@ -128,7 +131,11 @@ namespace campvis {
}
}
if (proxyGeometry != 0 && (p_coloringMode.getOptionValue() != TEXTURE_COLOR || texture != nullptr) && _pointShader != 0 && _meshShader != 0) {
if (proxyGeometry != 0
&& (p_enableShading.getValue() == false || light != nullptr)
&& (p_coloringMode.getOptionValue() != TEXTURE_COLOR || texture != nullptr)
&& _pointShader != 0 && _meshShader != 0)
{
// select correct shader
tgt::Shader* leShader = 0;
if (p_renderMode.getOptionValue() == GL_POINTS || p_renderMode.getOptionValue() == GL_LINES || p_renderMode.getOptionValue() == GL_LINE_STRIP)
......@@ -150,7 +157,11 @@ namespace campvis {
// set modelview and projection matrices
leShader->setIgnoreUniformLocationError(true);
decorateRenderProlog(data, leShader);
if (p_enableShading.getValue() && light != nullptr) {
light->bind(leShader, "_lightSource");
}
leShader->setUniform("_projectionMatrix", p_camera.getValue().getProjectionMatrix());
leShader->setUniform("_viewMatrix", p_camera.getValue().getViewMatrix());
leShader->setUniform("_viewportMatrix", viewportMatrix);
......@@ -187,7 +198,6 @@ namespace campvis {
else if (p_renderMode.getOptionValue() == GL_LINES || p_renderMode.getOptionValue() == GL_LINE_STRIP)
glLineWidth(1.f);
decorateRenderEpilog(leShader);
leShader->deactivate();
glDepthFunc(GL_LESS);
glDisable(GL_DEPTH_TEST);
......@@ -204,7 +214,10 @@ namespace campvis {
}
std::string GeometryRenderer::generateGlslHeader(bool hasGeometryShader) const {
std::string toReturn = getDecoratedHeader();
std::string toReturn;
if (p_enableShading.getValue())
toReturn += "#define ENABLE_SHADING\n";
if (hasGeometryShader && p_showWireframe.getValue())
toReturn += "#define WIREFRAME_RENDERING\n";
......@@ -228,6 +241,7 @@ namespace campvis {
void GeometryRenderer::updateProperties(DataContainer& dataContainer) {
p_solidColor.setVisible(p_coloringMode.getOptionValue() == SOLID_COLOR);
p_lightId.setVisible(p_enableShading.getValue());
switch (p_renderMode.getOptionValue()) {
case GL_POINTS:
......
......@@ -43,7 +43,7 @@ namespace campvis {
/**
* Genereates entry-/exit point textures for the given image and camera.
*/
class GeometryRenderer : public VisualizationProcessor, public HasProcessorDecorators {
class GeometryRenderer : public VisualizationProcessor {
public:
/// Coloring mode for fragments used during rendering
enum ColoringMode {
......@@ -82,6 +82,9 @@ namespace campvis {
DataNameProperty p_renderTargetID; ///< image ID for output image
CameraProperty p_camera;
BoolProperty p_enableShading; ///< Flag whether to enable shading
DataNameProperty p_lightId; ///< Name/ID for the LightSource to use
GenericOptionProperty<GLenum> p_renderMode; ///< Render mode for the geometry
GenericOptionProperty<ColoringMode> p_coloringMode; ///< Coloring mode for fragments used during rendering
......
......@@ -17,7 +17,7 @@ IF(${ModuleEnabled})
)
SET(ThisModShaderDirectories "modules/vis/glsl")
SET(ThisModDependencies io)
SET(ThisModDependencies base io)
ENDIF(${ModuleEnabled})
SET(ThisModStatus STABLE)
......
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