Commit bc8bb622 authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

Merge branch 'VtkShaders' into 'master'

Vtk shaders

Starting merge request for vtk shaders, pulled from ricardo branch, implemented mostly by tansel, rebased on master, with cleaning and corrections made by me.

This is a Work in Progress. do not merge. We need to review this altogether with @ricardo-ortiz 

This deprecates an old texture handling, but we need to work on integrating the new implementation, for example if there are no shaders. Also maybe look into getting rid of the use of static objects.

@tanselhalic could you maybe give a description of your work on the shaders and the textures? Also please wait until this is merged to contribute your new changes, so we can start from a clean base again.

Thank you all. Let's get this merged!

See merge request !61
parents d14aebb8 1026cc60
......@@ -2,8 +2,9 @@
# Copyright 2015 by Kitware and RPI. See toplevel LICENSE.txt for details.
###########################################################################
set(VTK_VERSION_NUM 6.2)
set(VTK_TAG v${VTK_VERSION_NUM}.0)
set(VTK_VERSION_NUM 6.3)
# set(VTK_TAG v${VTK_VERSION_NUM}.0)
set(VTK_TAG 47425ee694df750be696b0f6ade9a8dc4fe0b652)
set(VTK_REPOSITORY https://gitlab.kitware.com/vtk/vtk.git)
# Make sure this file is included only once
......@@ -83,5 +84,5 @@ else()
SimMedTKEmptyExternalProject(${proj} "${${proj}_DEPENDENCIES}")
endif()
set(SimMedTK_CMAKE_INCLUDE_PATH ${CMAKE_BINARY_DIR}/SuperBuild/${proj}/include/${sep}${SimMedTK_CMAKE_INCLUDE_PATH})
set(SimMedTK_CMAKE_INCLUDE_PATH ${CMAKE_BINARY_DIR}/SimMedTK-build/include/vtk-${VTK_VERSION_NUM}/${sep}${SimMedTK_CMAKE_INCLUDE_PATH})
list(APPEND SimMedTK_SUPERBUILD_EP_ARGS -DVTK_DIR:PATH=${${proj}_DIR})
......@@ -281,7 +281,6 @@ set(SimMedTK_exports
Geometry
IO
Mesh
RenderDelegates
Rendering
Simulators
VirtualTools
......@@ -300,7 +299,6 @@ add_subdirectory(External)
add_subdirectory(Geometry)
add_subdirectory(IO)
add_subdirectory(Mesh)
add_subdirectory(RenderDelegates)
add_subdirectory(Rendering)
add_subdirectory(VTKRendering)
add_subdirectory(Simulators)
......
......@@ -28,7 +28,6 @@
#include <numeric> // for iota
// SimMedTK includes
#include "Rendering/OpenGLViewer.h"
#include "Collision/SurfaceTreeIterator.h"
#include "Event/KeyboardEvent.h"
#include "Core/Factory.h"
......
......@@ -157,6 +157,13 @@ std::array<core::Vec3d,3> BaseMesh::getTriangleVertices(size_t i) const
};
return std::move(triangleVertices);
}
int BaseMesh::getMeshType()
{
return this->meshType;
}
void BaseMesh::setMeshType(int meshType)
{
this->meshType = meshType;
}
}
......@@ -162,6 +162,9 @@ public:
///
std::array<core::Vec3d,3> getTriangleVertices(size_t i) const;
int getMeshType();
void setMeshType(int);
protected:
// Data arrays - Vertices only
// vertices co-ordinate data at time t
......@@ -181,6 +184,9 @@ protected:
// Render identification, only used in \StylusRenderDelegate.
// TODO: Remove this
size_t renderingID;
///mesh type set by the loader
int meshType;
};
}// namespace Core
......
include(${VTK_USE_FILE})
simmedtk_add_library(Core
SOURCES
BaseMesh.cpp
......@@ -31,6 +32,7 @@ simmedtk_add_library(Core
BaseMesh.h
CollisionConfig.h
CollisionDetection.h
CollisionManager.h
CollisionModelIterator.h
CollisionPair.h
Color.h
......@@ -41,7 +43,9 @@ simmedtk_add_library(Core
DataStructures.h
DataStructures.hpp
Dispatcher.h
DisplayText.h
ErrorLog.h
EventData.h
Event.h
EventHandler.h
Factory.h
......@@ -51,6 +55,7 @@ simmedtk_add_library(Core
Light.h
MakeUnique.h
Matrix.h
MemoryBlock.h
Model.h
Module.h
ObjectSimulator.h
......@@ -74,7 +79,6 @@ simmedtk_add_library(Core
)
target_link_libraries(Core
PUBLIC
${OPENGL_LIBRARY}
sfml::graphics
......
......@@ -30,7 +30,6 @@
#include "Core/Matrix.h"
#include "Core/Factory.h"
#include "Rendering/OpenGLRenderer.h"
#include "RenderDelegate.h"
//forward declaration
......
......@@ -23,7 +23,6 @@
#include "Core/ObjectSimulator.h"
#include "Core/SDK.h"
#include "Rendering/OpenGLViewer.h"
ObjectSimulator::ObjectSimulator(std::shared_ptr<ErrorLog> p_log)
{
......
This diff is collapsed.
......@@ -14,67 +14,130 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
//---------------------------------------------------------------------------
//
// Authors:
//
// Contact:
//---------------------------------------------------------------------------
#ifndef SMRENDERDETAIL_H
#define SMRENDERDETAIL_H
#include "Core/Config.h"
#include "Core/Color.h"
#include "Core/ConfigRendering.h"
#include <GL/glew.h>
#include <memory>
#include <vector>
#include <string>
#include <map>
#include <array>
class VisualArtifact;
class CoreClass;
class Model;
struct UnifiedId;
///\brief Hold a pointer to a source of geometry that render details can use for drawing.
struct GeometrySource {
CoreClass* sceneObject;
VisualArtifact* analyticObject;
Model *model;
class vtkOpenGLTexture;
///
/// \brief Hold a pointer to a source of geometry that render details can use for drawing.
///
struct GeometrySource
{
CoreClass* sceneObject;
VisualArtifact* analyticObject;
Model *model;
GeometrySource()
: sceneObject(nullptr), analyticObject(nullptr)
GeometrySource()
: sceneObject(nullptr), analyticObject(nullptr)
{ }
void setSource(CoreClass* src)
void setSource(CoreClass* src)
{
this->sceneObject = src;
this->analyticObject = nullptr;
this->model = nullptr;
this->sceneObject = src;
this->analyticObject = nullptr;
this->model = nullptr;
}
void setSource(VisualArtifact* src)
void setSource(VisualArtifact* src)
{
this->sceneObject = nullptr;
this->model = nullptr;
this->analyticObject = src;
this->sceneObject = nullptr;
this->model = nullptr;
this->analyticObject = src;
}
void setSource(Model* src)
void setSource(Model* src)
{
this->sceneObject = nullptr;
this->model = src;
this->analyticObject = nullptr;
this->sceneObject = nullptr;
this->model = src;
this->analyticObject = nullptr;
}
template<typename T>
T* sourceAs() const
template<typename T>
T* sourceAs() const
{
T* result;
if ((result = dynamic_cast<T*>(sceneObject)))
{
return result;
}
if ((result = dynamic_cast<T*>(analyticObject)))
{
return result;
T* result;
if((result = dynamic_cast<T*>(sceneObject)))
{
return result;
}
if((result = dynamic_cast<T*>(analyticObject)))
{
return result;
}
if((result = dynamic_cast<T*>(model)))
{
return result;
}
return nullptr;
}
if ((result = dynamic_cast<T*>(model)))
};
struct TextureDetail
{
std::string textureName;
std::string fileName;
std::string shaderBinding;
std::string shaderProgramName;
GLint shaderUniformGL;
vtkOpenGLTexture* vtexture;
static std::map<std::string, vtkOpenGLTexture*> textures;
};
struct ShaderDetail
{
ShaderDetail()
{
return result;
}
return nullptr;
initialized = false;
geometryShaderExists = false;
}
std::string vertexShaderFileName;
std::string vertexShaderSource;
std::string fragmentShaderFileName;
std::string fragmentShaderSource;
bool geometryShaderExists;
std::string geometryShaderFileName;
std::string geometryShaderSource;
std::string shaderProgramName;
bool initialized;
//std::string tessellationShaderFileName;
//std::string tessellationShaderSource;
//std::string computeShaderFileName;
//std::string computeShaderSource;
};
class Shaders
{
public:
Shaders();
static bool createShader(std::string shaderProgramName, std::string vertexShaderFileName, std::string fragmentShaderFileName, std::string geometryShaderFileName);
static std::map<std::string, ShaderDetail> &getShaderPrograms();
static bool getShaderProgram(std::string shaderProgramName, ShaderDetail &shaderDetail);
static bool shaderExists(std::string shaderProgramName);
protected:
static std::map<std::string, ShaderDetail> shaderPrograms;
};
/// \brief RenderDetail has rendering options and features.
......@@ -84,137 +147,245 @@ struct RenderDetail
public:
typedef std::shared_ptr<RenderDetail> Ptr;
///
/// \brief Constructors/Destructor
///
RenderDetail();
~RenderDetail();
RenderDetail(unsigned int type);
void reset();
/// \brief attachment of shader
void addShader(std::shared_ptr<UnifiedId> p_shaderID);
/// \brief attachment of VAO
void addVAO(std::shared_ptr<UnifiedId> p_shaderID);
///
/// @brief Color setters
///
const Color &getAmbientColor() const;
const Color &getDiffuseColor() const;
const Color &getSpecularColor() const;
const Color &getHighLightColor() const;
const Color &getNormalColor() const;
const Color &getShadowColor() const;
const Color &getVertexColor() const;
const Color &getWireFrameColor() const;
const Color &getColorDiffuse() const;
///
/// @brief Color getters
///
void setAmbientColor(const Color &color);
void setDiffuseColor(const Color &color);
void setHighlightColor(const Color &color);
void setNormalColor(const Color &color);
void setShadowColor(const Color &color);
void setSpecularColor(const Color &color);
void setVertexColor(const Color &color);
void setWireframeColor(const Color &color);
///
/// \brief Get/Set background color
///
const Color &getBackground() const;
void setBackground(const Color &value);
const Color &getBackgroundTop() const
{
return this->faceBackgroundTop;
}
const Color &getColorAmbient() const;
const Color &getBackgroundBottom() const
{
return this->faceBackgroundBottom;
}
const Color &getColorSpecular() const;
///
/// \brief Get/Set opacity value
///
const float &getOpacity() const;
void setOpacity(const float &value);
///
/// \brief Get/Set specular power
///
const float &getShininess() const;
void setShininess(const float &value);
const unsigned int &getRenderType() const;
///
/// \brief Get/Set the length of the normal vector to draw
///
const float &getNormalLength() const;
void setNormalLength(const float &value);
///
/// \brief Get/Set size of point to draw
///
const float &getPointSize() const;
void setPointSize(const float &value);
///
/// \brief Get/Set size of line to draw
///
const float &getLineSize() const;
void setLineSize(const float &value);
const Color &getNormalColor() const;
const Color &getHighLightColor() const;
const Color &getVertexColor() const;
const Color &getShadowColor() const;
const bool &getCastShadow() const;
///
/// \brief Can the object get the shadow
///
const bool &getCanGetShadow() const;
const Color &getWireFrameColor() const;
///
/// \brief Can the object cast a shadow
///
const bool &getCastShadow() const;
///
/// \brief Debug mode
///
const bool &getDebugDraw() const;
const std::vector<std::shared_ptr<UnifiedId>> &getShaders() const;
///
/// \brief Render type
///
const unsigned int &getRenderType() const;
///
/// \brief Get enabled/disabled shaders array
///
const std::vector<bool> &getShaderEnable() const;
///
/// \brief Get VAO's array
///
const std::vector<std::shared_ptr<UnifiedId>> &getVAOs() const;
///
/// \brief Get enabled/disabled VAO array
///
const std::vector<bool> &getVAOEnable() const;
void setPointSize(const float size);
void setLineSize(const float size);
void setVertexColor(const Color vertColor);
void setHighlightColor(const Color highlightColor);
void setNormalColor(const Color highlightColor);
void setShininess(const float s);
void setNormalLength(const float len);
void setDiffuseColor(const Color diffColor);
void setAmbientColor(const Color ambColor);
void setSpecularColor(const Color specColor);
void setShadowColor(const Color shadColor);
void setWireframeColor(const Color wireColor);
void setTextureFilename(const std::string &filename);
const std::string &getTextureFilename() const;
///
/// \brief Set/Get the binding texture filename for a shader. shaderBinding is for texture name in the shader name
///
void addTexture(const std::string &textureName, const std::string &filename,
const std::string &shaderBinding, const std::string &shaderProgramName);
std::map<std::string, TextureDetail>& getTextures();
int getNumberOfTextures();
///
/// \brief Returns true if you want to draw texture map
///
void setRenderTexture(bool value);
bool renderTexture() const;
///
/// \brief Returns true if you want to draw normalsmap
///
void setRenderNormals(bool value);
bool renderNormals() const;
///
/// \brief Returns true if you want to draw wireframe
///
void setRenderWireframe(bool value);
bool renderWireframe() const;
///
/// \brief Returns true if you want to draw faces
///
void setRenderFaces(bool value);
bool renderFaces() const;
const float &getOpacity() const;
void setOpacity(const float &value);
///
/// @brief Add a shader program to the the list (vtk)
///
void addShaderProgram(int shaderType, const std::string &programFilename, const std::string & programName);
void addShaderProgram(const std::string &shaderProgramName);
std::string getShaderProgram();
///
/// \brief Return list of shader programs
///
std::map<std::string, bool> &getShaderPrograms();
///
/// @brief Add a shader program for partial replacement of vtk default shaders.
/// @param type 0 = vertex, 1 = Fragment, 2 = Geometry
/// @param program String containing the actual program
///
void addShaderProgramReplacement(int type, const std::string &from,
const std::string &to);
///
/// \brief Return list of shader program replacements
///
std::map<int, std::vector<std::array<std::string, 2>>>
&getShaderProgramReplacements();
///
/// \brief Retrurns true if there is vtk shader in the list
///
bool hasShaders();
///
/// \brief attachment of shader
///
void addShader(std::shared_ptr<UnifiedId> p_shaderID);
const Color &getBackground() const
{
return this->background;
}
///
/// \brief Get shaders array
///
const std::vector<std::shared_ptr<UnifiedId>> &getShaders() const;
const Color &getBackgroundTop() const
{
return this->faceBackgroundTop;
}
///
/// \brief attachment of VAO
///
void addVAO(std::shared_ptr<UnifiedId> p_shaderID);
const Color &getBackgroundBottom() const
{
return this->faceBackgroundBottom;
}
///
/// \brief Reset variables and containers
///
void reset();
void setBackground(const Color &value)
{
this->background = value;
}
public:
unsigned int renderType; // render type
Color colorDiffuse; // diffuse color
Color colorAmbient; // ambient color
Color colorSpecular; // specular color
Color highLightColor; // highlight color
Color vertexRenderColor; // vertex color
Color shadowColor; // shadow color
bool castShadow; // object can generate a shadow or not
///
/// \brief Set render type
///
void setRenderType(unsigned int p_renderType);
///
/// @brief Add an attribute to a program to the the list (vtk)
///
void addShaderAttribute(int shaderType, const std::string &attributeName);
private:
bool canGetShadow; // object can get the shadow or not
bool castShadow; // object can generate a shadow or not
bool debugDraw; // debug draw enabled or not
Color background; // backgroung color
Color faceBackgroundBottom;
Color faceBackgroundTop;
Color ambientColor; // ambient color
Color diffuseColor; // diffuse color
Color specularColor; // specular color
Color highLightColor; // highlight color
Color normalColor; // normal color
Color shadowColor; // shadow color
Color vertexRenderColor; // vertex color
Color wireFrameColor; // wire frame color
float pointSize; // point size if rendering of vertices are enabled
float lineSize; // line width size
float shininess; // specular shinness
bool debugDraw; // debug draw enabled or not
float normalLength; // length of rendered normals
float opacity; // opacity
float pointSize; // point size if rendering of vertices are enabled
float shininess; // specular shinness
std::string textureFilename; // file name for the texture attached]
Color background;
unsigned int renderType; // render type