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

* Extended GeometryRendererDemo to render two different geometries and combine...

* Extended GeometryRendererDemo to render two different geometries and combine the renderings using the RenderTargetCompositor
* Fixed point size in GeometryRenderer
parent 70807b3f
......@@ -26,7 +26,7 @@
#include "tools/texture3d.frag"
// input from geometry shader
in vec4 geom_Position;
in vec3 geom_Position;
in vec3 geom_TexCoord;
in vec4 geom_Color;
in vec3 geom_Normal;
......@@ -50,12 +50,12 @@ void main() {
#ifdef ENABLE_SHADING
// perform Phong shading
out_Color.rgb = calculatePhongShading(geom_Position.xyz / geom_Position.w, _lightSource, _cameraPosition, geom_Normal, out_Color.rgb, out_Color.rgb, vec3(1.0, 1.0, 1.0));
out_Color.rgb = calculatePhongShading(geom_Position, _lightSource, _cameraPosition, geom_Normal, out_Color.rgb, out_Color.rgb, vec3(1.0, 1.0, 1.0));
#endif
#ifdef WIREFRAME_RENDERING
// Find the smallest distance to the edges
float d = min(geom_EdgeDistance.x, min(geom_EdgeDistance.y, geom_EdgeDistance.z));
float d = min(geom_EdgeDistance.x, min(geom_EdgeDistance.y, geom_EdgeDistance.z)) * 2.0;
// Determine the mix factor with the line color
float aliasingWidth = min(1.0, (_lineWidth/8.0));
......
......@@ -28,12 +28,12 @@
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
in vec4 vert_Position[];
in vec3 vert_Position[];
in vec3 vert_TexCoord[]; ///< incoming texture coordinate
in vec4 vert_Color[];
in vec3 vert_Normal[];
out vec4 geom_Position;
out vec3 geom_Position;
out vec3 geom_TexCoord;
out vec4 geom_Color; ///< outgoing fragment color
out vec3 geom_Normal;
......@@ -66,6 +66,7 @@ void main() {
geom_Normal = _computeNormals ? normal : vert_Normal[0];
geom_Position = vert_Position[0];
geom_TexCoord = vert_TexCoord[0];
geom_Color = vert_Color[0];
gl_Position = gl_in[0].gl_Position;
EmitVertex();
......@@ -73,6 +74,7 @@ void main() {
geom_Normal = _computeNormals ? normal : vert_Normal[1];
geom_Position = vert_Position[1];
geom_TexCoord = vert_TexCoord[1];
geom_Color = vert_Color[1];
gl_Position = gl_in[1].gl_Position;
EmitVertex();
......@@ -80,6 +82,7 @@ void main() {
geom_Normal = _computeNormals ? normal : vert_Normal[2];
geom_Position = vert_Position[2];
geom_TexCoord = vert_TexCoord[2];
geom_Color = vert_Color[2];
gl_Position = gl_in[2].gl_Position;
EmitVertex();
......
......@@ -28,12 +28,12 @@ layout (location = 2) in vec4 in_Color; ///< incoming color
layout (location = 3) in vec3 in_Normal; ///< incoming normals
#ifdef HAS_GEOMETRY_SHADER
out vec4 vert_Position; ///< outgoing world coordinates
out vec3 vert_Position; ///< outgoing world coordinates
out vec3 vert_TexCoord; ///< outgoing texture coordinate
out vec4 vert_Color; ///< outgoing color
out vec3 vert_Normal; ///< outgoing world normals
#else
out vec4 geom_Position; ///< outgoing texture coordinate
out vec3 geom_Position; ///< outgoing texture coordinate
out vec3 geom_TexCoord; ///< outgoing color
out vec4 geom_Color; ///< outgoing world coordinates
out vec3 geom_Normal; ///< outgoing world normals
......@@ -66,7 +66,7 @@ void main() {
#ifdef HAS_GEOMETRY_SHADER
// set outputs for geometry shader
vert_Position = vec4(in_Position, 1.0);
vert_Position = in_Position;
gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
vert_TexCoord = in_TexCoord;
......@@ -76,7 +76,7 @@ void main() {
#else
// set outputs for fragment shader
geom_Position = vec4(in_Position, 1.0);
geom_Position = in_Position;
gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
geom_TexCoord = in_TexCoord;
......
......@@ -37,40 +37,63 @@ namespace campvis {
: AutoEvaluationPipeline(dc)
, _camera("camera", "Camera")
, _geometryReader()
, _gr(&_canvasSize)
, _lvRenderer(&_canvasSize)
, _teapotRenderer(&_canvasSize)
, _compositor(&_canvasSize)
, _trackballEH(0)
{
addProperty(&_camera);
_trackballEH = new TrackballNavigationEventListener(&_camera, &_canvasSize);
_trackballEH->addLqModeProcessor(&_gr);
addEventListenerToBack(_trackballEH);
addProcessor(&_geometryReader);
addProcessor(&_gr);
addProcessor(&_teapotRenderer);
addProcessor(&_lvRenderer);
addProcessor(&_compositor);
}
GeometryRendererDemo::~GeometryRendererDemo() {
_geometryReader.s_validated.disconnect(this);
delete _trackballEH;
}
void GeometryRendererDemo::init() {
AutoEvaluationPipeline::init();
// connect slots
_geometryReader.s_validated.connect(this, &GeometryRendererDemo::onProcessorValidated);
_camera.addSharedProperty(&_gr.p_camera);
_gr.p_renderTargetID.setValue("combine");
_gr.p_renderMode.selectById("triangles");
_renderTargetID.setValue("combine");
// create Teapot
MultiIndexedGeometry* teapot = GeometryDataFactory::createTeapot();
teapot->applyTransformation(tgt::mat4::createTranslation(tgt::vec3(5.f, 10.f, 5.f)) * tgt::mat4::createScale(tgt::vec3(16.f)));
getDataContainer().addData("teapot", teapot);
_trackballEH->reinitializeCamera(teapot);
// setup pipeline
_camera.addSharedProperty(&_lvRenderer.p_camera);
_camera.addSharedProperty(&_teapotRenderer.p_camera);
_geometryReader.p_url.setValue(CAMPVIS_SOURCE_DIR "/modules/vis/sampledata/left_ventricle_mesh.vtk");
_geometryReader.p_targetImageID.setValue("reader.output");
_geometryReader.p_targetImageID.addSharedProperty(&_gr.p_geometryID);
MeshGeometry* cube = GeometryDataFactory::createCube(tgt::Bounds(tgt::vec3(0.f), tgt::vec3(1.f)), tgt::Bounds(tgt::vec3(0.f), tgt::vec3(1.f)));
getDataContainer().addData("reader.output", cube);
_trackballEH->reinitializeCamera(cube);
_lvRenderer.p_geometryID.setValue("reader.output");
_lvRenderer.p_renderTargetID.setValue("lv.render");
_lvRenderer.p_renderMode.selectById("triangles");
_lvRenderer.p_solidColor.setValue(tgt::vec4(0.8f, 0.f, 0.f, 1.f));
_teapotRenderer.p_geometryID.setValue("teapot");
_teapotRenderer.p_renderTargetID.setValue("teapot.render");
_teapotRenderer.p_renderMode.selectById("trianglestrip");
_teapotRenderer.p_showWireframe.setValue(false);
_teapotRenderer.p_solidColor.setValue(tgt::vec4(0.75f, 0.75f, 0.75f, 1.f));
_compositor.p_firstImageId.setValue("lv.render");
_compositor.p_secondImageId.setValue("teapot.render");
_compositor.p_compositingMethod.selectById("depth");
_compositor.p_targetImageId.setValue("combine");
_renderTargetID.setValue("combine");
}
void GeometryRendererDemo::deinit() {
......@@ -81,12 +104,17 @@ namespace campvis {
void GeometryRendererDemo::onProcessorValidated(AbstractProcessor* processor) {
if (processor == &_geometryReader) {
// update camera
ScopedTypedData<IHasWorldBounds> img(*_data, _geometryReader.p_targetImageID.getValue());
if (img != 0) {
_trackballEH->reinitializeCamera(img);
ScopedTypedData<IHasWorldBounds> lv(*_data, _geometryReader.p_targetImageID.getValue());
ScopedTypedData<IHasWorldBounds> teapot(*_data, "teapot");
if (lv != 0 && teapot != 0) {
tgt::Bounds unionBounds;
unionBounds.addVolume(lv->getWorldBounds());
unionBounds.addVolume(teapot->getWorldBounds());
_trackballEH->reinitializeCamera(unionBounds);
}
}
}
}
\ No newline at end of file
}
......@@ -30,6 +30,7 @@
#include "core/properties/cameraproperty.h"
#include "modules/io/processors/vtkimagereader.h"
#include "modules/vis/processors/geometryrenderer.h"
#include "modules/vis/processors/rendertargetcompositor.h"
namespace campvis {
class GeometryRendererDemo : public AutoEvaluationPipeline {
......@@ -65,7 +66,9 @@ namespace campvis {
CameraProperty _camera;
VtkImageReader _geometryReader;
GeometryRenderer _gr;
GeometryRenderer _lvRenderer;
GeometryRenderer _teapotRenderer;
RenderTargetCompositor _compositor;
TrackballNavigationEventListener* _trackballEH;
......
......@@ -88,12 +88,15 @@ namespace campvis {
void GeometryRenderer::init() {
VisualizationProcessor::init();
_pointShader = ShdrMgr.loadSeparate("modules/vis/glsl/geometryrenderer.vert", "modules/vis/glsl/geometryrenderer.frag", generateGlslHeader(false), false);
_meshShader = ShdrMgr.loadSeparate("modules/vis/glsl/geometryrenderer.vert", "modules/vis/glsl/geometryrenderer.geom", "modules/vis/glsl/geometryrenderer.frag", generateGlslHeader(true), false);
_meshShader = ShdrMgr.loadSeparate("modules/vis/glsl/geometryrenderer.vert", "modules/vis/glsl/geometryrenderer_faces.geom", "modules/vis/glsl/geometryrenderer.frag", generateGlslHeader(true), false);
}
void GeometryRenderer::deinit() {
ShdrMgr.dispose(_pointShader);
_pointShader = 0;
ShdrMgr.dispose(_meshShader);
_meshShader = 0;
VisualizationProcessor::deinit();
}
......@@ -138,8 +141,13 @@ namespace campvis {
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (p_renderMode.getOptionValue() == GL_POINTS)
glPointSize(p_pointSize.getValue());
proxyGeometry->render(p_renderMode.getOptionValue());
if (p_renderMode.getOptionValue() == GL_POINTS)
glPointSize(1.f);
decorateRenderEpilog(leShader);
leShader->deactivate();
glDisable(GL_DEPTH_TEST);
......
Supports Markdown
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