Skip to content
Snippets Groups Projects
Commit 0fe2a123 authored by Tansel Halic's avatar Tansel Halic Committed by Alexis Girault
Browse files

The vertex buffer is added for tangents.

The tangents transfer to the shaders need to be checked.
parent 181316fc
No related branches found
No related tags found
No related merge requests found
......@@ -151,6 +151,7 @@ void SurfaceMesh::computeTriangleTangents()
// Calculate the vertex tangents
if(this->useThreeDSTexureCoordinates || this->useOBJDSTexureCoordinates)
{
this->vertexTangents.resize(this->vertices.size(), core::Vec3d::Zero());
for(size_t v = 0, end = this->vertices.size(); v < end; ++v)
{
this->vertexTangents[v][0] = this->vertexTangents[v][1] = this->vertexTangents[v][2] = 0;
......
......@@ -50,9 +50,13 @@
#include <vtkTexture.h>
#include <vtkOpenGLPolyDataMapper.h>
#include <vtkProperty.h>
#include "vtkShaderProgram.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkOpenGLVertexBufferObject.h"
vtkStandardNewMacro(CustomGLPolyDataMapper)
class MeshRenderDelegate : public VTKRenderDelegate
{
public:
......@@ -201,6 +205,12 @@ void MeshRenderDelegate::initDraw()
mapper = CustomGLPolyDataMapper::New();
mapper->SetInputConnection(normals->GetOutputPort());
auto mapperCustom = CustomGLPolyDataMapper::SafeDownCast(mapper);
mesh->computeVertexNeighbors();
mesh->setUseOBJTexture(true);
mesh->computeTriangleTangents();
mapperCustom->tangents = mesh->getVertexTangents();
if(renderDetail->hasShaders())
{
......@@ -249,12 +259,46 @@ void MeshRenderDelegate::modified()
dataSet->Modified();
}
void CustomGLPolyDataMapper::initDraw(){
cout << "init" << endl;
}
void CustomGLPolyDataMapper::BuildBufferObjects(vtkRenderer *ren, vtkActor *act){
tangentsBuffer = vtkOpenGLBufferObject::New();
tangentsBuffer->Bind();
if (tangentsBuffer->Upload(this->tangents, vtkOpenGLBufferObject::ArrayBuffer)){
cout << "Completed Tangents Binding"<<endl;
}
tangentsBuffer->Release();
vtkOpenGLPolyDataMapper::BuildBufferObjects(ren,act);
}
void CustomGLPolyDataMapper::SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act)
{
double testColor1 = 0.01;
double testColor2 = 0.01;
static double testColor3 = 0.01;
vtkShaderProgram *program = cellBO.Program;
testColor3 += 0.01;
program->SetUniformf("TestColor1", testColor1);
program->SetUniformf("TestColor2", testColor2);
program->SetUniformf("TestColor3", testColor3);
cellBO.VAO->Bind();
if (!cellBO.VAO->AddAttributeArray(cellBO.Program, this->tangentsBuffer,
"vertTangents", 0,
0, VTK_DOUBLE, 3, false))
{
vtkErrorMacro(<< "Error setting 'vertTangents' in shader VAO.");
}
vtkOpenGLPolyDataMapper::SetMapperShaderParameters(cellBO, ren, act);
}
RegisterFactoryClass(RenderDelegate,
......
......@@ -8,11 +8,14 @@ class vtkActor;
class CustomGLPolyDataMapper :public vtkOpenGLPolyDataMapper{
public:
static CustomGLPolyDataMapper* New();
vtkOpenGLBufferObject * tangentsBuffer;
std::vector<core::Vec3d>tangents;
vtkTypeMacro(CustomGLPolyDataMapper, vtkOpenGLPolyDataMapper)
virtual void initDraw() {}
virtual void initDraw();
virtual void modified() {}
virtual void draw() const { }
virtual void SetMapperShaderParameters(vtkOpenGLHelper &cellBO, vtkRenderer *ren, vtkActor *act) override;
void BuildBufferObjects(vtkRenderer *ren, vtkActor *act);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment