04.06., 9:00 - 12:00: GitLab will be migrated to a new server environment and upgraded to Enterprise Edition Ultimate. The estimated downtime will be 2-3 hours. Please see https://doku.lrz.de/display/PUBLIC/GitLab+Ultimate+Migration for more details about changes related to the migration.

Commit 0034e5c4 authored by Jakob Weiss's avatar Jakob Weiss

Local Light Sources, Extended ImageMappingInformation

* Light sources now have an additional camera input. If this is set, the light source position is relative to the camera coordinate system
* ImageMappingInformation and Texture3D now supply an additional pair of matrices: textureToWorldMatrixInvTransp to transform normals between world and texture space
parent 31ba23bf
...@@ -66,6 +66,8 @@ namespace campvis { ...@@ -66,6 +66,8 @@ namespace campvis {
_textureToWorldTransformation = _customTransformation * cgt::mat4::createTranslation(_offset) * cgt::mat4::createScale(_voxelSize * _size); _textureToWorldTransformation = _customTransformation * cgt::mat4::createTranslation(_offset) * cgt::mat4::createScale(_voxelSize * _size);
if (! _textureToWorldTransformation.invert(_worldToTextureTransformation)) if (! _textureToWorldTransformation.invert(_worldToTextureTransformation))
cgtAssert(false, "Could not invert texture-to-world matrix. That should not happen!"); cgtAssert(false, "Could not invert texture-to-world matrix. That should not happen!");
_textureToWorldTransformationInvTransp = cgt::transpose(_worldToTextureTransformation);
_worldToTextureTransformation = cgt::transpose(_textureToWorldTransformation);
_voxelToWorldTransformation = _customTransformation * cgt::mat4::createTranslation(_offset) * cgt::mat4::createScale(_voxelSize); _voxelToWorldTransformation = _customTransformation * cgt::mat4::createTranslation(_offset) * cgt::mat4::createScale(_voxelSize);
if (! _voxelToWorldTransformation.invert(_worldToVoxelTransformation)) if (! _voxelToWorldTransformation.invert(_worldToVoxelTransformation))
...@@ -76,10 +78,20 @@ namespace campvis { ...@@ -76,10 +78,20 @@ namespace campvis {
return _textureToWorldTransformation; return _textureToWorldTransformation;
} }
const cgt::mat4 & ImageMappingInformation::getTextureToWorldMatrixInvTransp() const
{
return _textureToWorldTransformationInvTransp;
}
const cgt::mat4& ImageMappingInformation::getWorldToTextureMatrix() const { const cgt::mat4& ImageMappingInformation::getWorldToTextureMatrix() const {
return _worldToTextureTransformation; return _worldToTextureTransformation;
} }
const cgt::mat4 & ImageMappingInformation::getWorldToTextureMatrixInvTransp() const
{
return _worldToTextureTransformationInvTransp;
}
const cgt::mat4& ImageMappingInformation::getVoxelToWorldMatrix() const { const cgt::mat4& ImageMappingInformation::getVoxelToWorldMatrix() const {
return _voxelToWorldTransformation; return _voxelToWorldTransformation;
} }
......
...@@ -90,12 +90,26 @@ namespace campvis { ...@@ -90,12 +90,26 @@ namespace campvis {
*/ */
const cgt::mat4& getTextureToWorldMatrix() const; const cgt::mat4& getTextureToWorldMatrix() const;
/**
* Gets the inverse of the transpose of the the transformation matrix
* from texture to world coordinates.
* \return _textureToWorldTransformation
*/
const cgt::mat4& getTextureToWorldMatrixInvTransp() const;
/** /**
* Gets the transformation matrix from world to texture coordinates. * Gets the transformation matrix from world to texture coordinates.
* \return _worldToTextureTransformation * \return _worldToTextureTransformation
*/ */
const cgt::mat4& getWorldToTextureMatrix() const; const cgt::mat4& getWorldToTextureMatrix() const;
/**
* Gets the inverse of the transpose of the transformation matrix
* from world to texture coordinates.
* \return _worldToTextureTransformation
*/
const cgt::mat4& getWorldToTextureMatrixInvTransp() const;
/** /**
* Gets the transformation matrix from voxel to world coordinates. * Gets the transformation matrix from voxel to world coordinates.
* \return _voxelToWorldTransformation * \return _voxelToWorldTransformation
...@@ -134,6 +148,9 @@ namespace campvis { ...@@ -134,6 +148,9 @@ namespace campvis {
cgt::mat4 _textureToWorldTransformation; ///< Transformation matrix from texture to world coordinates cgt::mat4 _textureToWorldTransformation; ///< Transformation matrix from texture to world coordinates
cgt::mat4 _worldToTextureTransformation; ///< Transformation matrix from world to texture coordinates cgt::mat4 _worldToTextureTransformation; ///< Transformation matrix from world to texture coordinates
cgt::mat4 _textureToWorldTransformationInvTransp;///< Transformation matrix from texture to world coordinates
cgt::mat4 _worldToTextureTransformationInvTransp;///< Transformation matrix from world to texture coordinates
cgt::mat4 _voxelToWorldTransformation; ///< Transformation matrix from voxel to world coordinates cgt::mat4 _voxelToWorldTransformation; ///< Transformation matrix from voxel to world coordinates
cgt::mat4 _worldToVoxelTransformation; ///< Transformation matrix from world to voxel coordinates cgt::mat4 _worldToVoxelTransformation; ///< Transformation matrix from world to voxel coordinates
}; };
......
...@@ -169,6 +169,8 @@ namespace campvis { ...@@ -169,6 +169,8 @@ namespace campvis {
shader->setUniform(texParamsUniform + "._voxelSizeRCP", cgt::vec3(1.f) / _parent->getMappingInformation().getVoxelSize()); shader->setUniform(texParamsUniform + "._voxelSizeRCP", cgt::vec3(1.f) / _parent->getMappingInformation().getVoxelSize());
shader->setUniform(texParamsUniform + "._textureToWorldMatrix", _parent->getMappingInformation().getTextureToWorldMatrix()); shader->setUniform(texParamsUniform + "._textureToWorldMatrix", _parent->getMappingInformation().getTextureToWorldMatrix());
shader->setUniform(texParamsUniform + "._worldToTextureMatrix", _parent->getMappingInformation().getWorldToTextureMatrix()); shader->setUniform(texParamsUniform + "._worldToTextureMatrix", _parent->getMappingInformation().getWorldToTextureMatrix());
shader->setUniform(texParamsUniform + "._textureToWorldMatrixInvTransp", _parent->getMappingInformation().getTextureToWorldMatrixInvTransp());
shader->setUniform(texParamsUniform + "._worldToTextureMatrixInvTransp", _parent->getMappingInformation().getWorldToTextureMatrixInvTransp());
break; break;
default: default:
...@@ -215,4 +217,4 @@ namespace campvis { ...@@ -215,4 +217,4 @@ namespace campvis {
return WeaklyTypedPointer(WeaklyTypedPointer::baseType(dataType), _texture->getNumChannels(), data); return WeaklyTypedPointer(WeaklyTypedPointer::baseType(dataType), _texture->getNumChannels(), data);
} }
} }
\ No newline at end of file
...@@ -28,7 +28,7 @@ const float positiveInfinity = 1.0 / 0.0; ...@@ -28,7 +28,7 @@ const float positiveInfinity = 1.0 / 0.0;
* Code adapted from: https://www.marcusbannerman.co.uk/index.php/component/content/article/42-articles/97-vol-render-optimizations.htm * Code adapted from: https://www.marcusbannerman.co.uk/index.php/component/content/article/42-articles/97-vol-render-optimizations.htm
*/ */
void jitterEntryPoint(inout vec3 position, in vec3 direction, in float stepSize) { void jitterEntryPoint(inout vec3 position, in vec3 direction, in float stepSize) {
float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453); float random = fract(sin(gl_FragCoord.x * 12.9898 + gl_FragCoord.y * 78.233) * 43758.5453) - 0.5;
position = position + direction * (stepSize * random); position = position + direction * (stepSize * random);
} }
...@@ -167,4 +167,4 @@ float calculateDepthValue(float t, float entryPointsDepth, float exitPointsDepth ...@@ -167,4 +167,4 @@ float calculateDepthValue(float t, float entryPointsDepth, float exitPointsDepth
float zw_current = (1.0/ze_current)*const_to_z_w_1 + const_to_z_w_2; float zw_current = (1.0/ze_current)*const_to_z_w_1 + const_to_z_w_2;
return zw_current; return zw_current;
} }
\ No newline at end of file
...@@ -39,6 +39,10 @@ struct TextureParameters3D { ...@@ -39,6 +39,10 @@ struct TextureParameters3D {
// Transformation matrices // Transformation matrices
mat4 _textureToWorldMatrix; mat4 _textureToWorldMatrix;
mat4 _worldToTextureMatrix; mat4 _worldToTextureMatrix;
// inverse of transpose of the respective matrices, used to transform normals
mat4 _textureToWorldMatrixInvTransp;
mat4 _worldToTextureMatrixInvTransp;
}; };
/** /**
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "lightsourceprovider.h" #include "lightsourceprovider.h"
#include "core/datastructures/lightsourcedata.h" #include "core/datastructures/lightsourcedata.h"
#include "core/datastructures/cameradata.h"
namespace campvis { namespace campvis {
const std::string LightSourceProvider::loggerCat_ = "CAMPVis.modules.io.LightSourceProvider"; const std::string LightSourceProvider::loggerCat_ = "CAMPVis.modules.io.LightSourceProvider";
...@@ -31,6 +32,7 @@ namespace campvis { ...@@ -31,6 +32,7 @@ namespace campvis {
LightSourceProvider::LightSourceProvider() LightSourceProvider::LightSourceProvider()
: AbstractProcessor() : AbstractProcessor()
, p_lightId("LightId", "Light Name/ID", "lightsource", DataNameProperty::WRITE) , p_lightId("LightId", "Light Name/ID", "lightsource", DataNameProperty::WRITE)
, p_cameraId("CameraId", "Camera ID", "", DataNameProperty::READ)
, p_lightPosition("LightPosition", "Light Position", cgt::vec3(-100.f), cgt::vec3(-500.f), cgt::vec3(500.f), cgt::vec3(1.f)) , p_lightPosition("LightPosition", "Light Position", cgt::vec3(-100.f), cgt::vec3(-500.f), cgt::vec3(500.f), cgt::vec3(1.f))
, p_ambientColor("AmbientColor", "Ambient Light Color", cgt::vec4(0.4f), cgt::vec4(0.f), cgt::vec4(1.f)) , p_ambientColor("AmbientColor", "Ambient Light Color", cgt::vec4(0.4f), cgt::vec4(0.f), cgt::vec4(1.f))
, p_diffuseColor("DiffuseColor", "Diffuse Light Color", cgt::vec4(0.75f), cgt::vec4(0.f), cgt::vec4(1.f)) , p_diffuseColor("DiffuseColor", "Diffuse Light Color", cgt::vec4(0.75f), cgt::vec4(0.f), cgt::vec4(1.f))
...@@ -39,6 +41,7 @@ namespace campvis { ...@@ -39,6 +41,7 @@ namespace campvis {
, p_attenuation("Attenuation", "Attenuation Factors", cgt::vec3(0.f), cgt::vec3(0.f), cgt::vec3(1.f)) , p_attenuation("Attenuation", "Attenuation Factors", cgt::vec3(0.f), cgt::vec3(0.f), cgt::vec3(1.f))
{ {
addProperty(p_lightId); addProperty(p_lightId);
addProperty(p_cameraId);
addProperty(p_lightPosition); addProperty(p_lightPosition);
addProperty(p_ambientColor); addProperty(p_ambientColor);
addProperty(p_diffuseColor); addProperty(p_diffuseColor);
...@@ -52,8 +55,15 @@ namespace campvis { ...@@ -52,8 +55,15 @@ namespace campvis {
} }
void LightSourceProvider::updateResult(DataContainer& data) { void LightSourceProvider::updateResult(DataContainer& data) {
ScopedTypedData<CameraData> cam(data, p_cameraId.getValue(), true);
cgt::mat4 trafoMatrix = cgt::mat4::identity;
if (cam) {
trafoMatrix = cam->getCamera().getViewMatrixInverse() * cgt::mat4::createTranslation(cam->getCamera().getFocus());
}
LightSourceData* lsd = new LightSourceData( LightSourceData* lsd = new LightSourceData(
p_lightPosition.getValue(), trafoMatrix * p_lightPosition.getValue(),
p_ambientColor.getValue().xyz(), p_ambientColor.getValue().xyz(),
p_diffuseColor.getValue().xyz(), p_diffuseColor.getValue().xyz(),
p_specularColor.getValue().xyz(), p_specularColor.getValue().xyz(),
...@@ -62,4 +72,4 @@ namespace campvis { ...@@ -62,4 +72,4 @@ namespace campvis {
data.addData(p_lightId.getValue(), lsd); data.addData(p_lightId.getValue(), lsd);
} }
} }
\ No newline at end of file
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
namespace campvis { namespace campvis {
/** /**
* Creates LightSourceData and stores it in the DataContainer. * Creates LightSourceData and stores it in the DataContainer.
* If p_cameraId is supplied, the position is relative to the camera coordinate system and centered
* on the camera's focus.
*
* \see LightSourceData * \see LightSourceData
*/ */
class CAMPVIS_MODULES_API LightSourceProvider : public AbstractProcessor { class CAMPVIS_MODULES_API LightSourceProvider : public AbstractProcessor {
...@@ -51,7 +54,7 @@ namespace campvis { ...@@ -51,7 +54,7 @@ namespace campvis {
* Destructor * Destructor
**/ **/
virtual ~LightSourceProvider(); virtual ~LightSourceProvider();
/** /**
* To be used in ProcessorFactory static methods * To be used in ProcessorFactory static methods
*/ */
...@@ -66,6 +69,7 @@ namespace campvis { ...@@ -66,6 +69,7 @@ namespace campvis {
virtual ProcessorState getProcessorState() const { return AbstractProcessor::STABLE; }; virtual ProcessorState getProcessorState() const { return AbstractProcessor::STABLE; };
DataNameProperty p_lightId; ///< Name/ID for the LightSource to create DataNameProperty p_lightId; ///< Name/ID for the LightSource to create
DataNameProperty p_cameraId; ///< if camera is supplied, light position will be relative to camera coordinate system
Vec3Property p_lightPosition; ///< Light position Vec3Property p_lightPosition; ///< Light position
ColorProperty p_ambientColor; ///< Ambient light color ColorProperty p_ambientColor; ///< Ambient light color
ColorProperty p_diffuseColor; ///< Diffuse light color ColorProperty p_diffuseColor; ///< Diffuse light color
......
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