Thank you for the example, that was very helpful!
I have created an xml file (see attachment) with the same code to use in
mitk and it works, but only for points.
When I try to render a sphere (or generally vtkPolydata with polygons)
in mitk or in your example, I get the GL error code 1282 (Invalid
operation).
As I have no clue about geometry-shaders I'm surely just using it wrong.
But the code in my branch seems to be correct.
Could you please try to use the attached shader file and report if you
still get the access violation error?
regards
Christoph
On 09.09.2014 15:28, Nil Goyette wrote:
I created a "small" example in vtk so you can test. As small as vtk
can get, anyway. I create a small shape in a polydata and activate a
geometry sahder which keeps only the vertex in a specific region. I
also tested using the pass-through geometry shader and it works
perfectly. It might be useful if you want to test without using
uniform variable.
#include <vtkActor.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkShader2.h>
#include <vtkShaderProgram2.h>
#include <vtkShader2Collection.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkUniformVariables.h>
int main(int argc, char *argv[])
{
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(-2.0, 0.0, 0.0); // Shape is
for (unsigned int i = 0; i < 11; ++i) { // __
points->InsertNextPoint(0.0, i, 0.0); // |
} // |
points->InsertNextPoint(2.0, 10.0, 0.0); // _|
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell(13);
for (vtkIdType i = 0; i < 13; ++i) {
lines->InsertCellPoint(i);
}
vtkSmartPointer<vtkPolyData> polyData =
vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->SetLines(lines);
vtkSmartPointer<vtkPolyDataMapper> polyDataMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
polyDataMapper->SetInputData(polyData);
vtkSmartPointer<vtkActor> polyDataActor =
vtkSmartPointer<vtkActor>::New();
polyDataActor->SetMapper(polyDataMapper);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(polyDataActor);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->Render();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
= vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
if (!vtkShaderProgram2::IsSupported(renderWindow)) {
std::cout << "GLSL is not supported on this system.";
return -1;
}
vtkSmartPointer<vtkShaderProgram2> shader_program =
vtkSmartPointer<vtkShaderProgram2>::New();
shader_program->SetContext(renderWindow);
vtkShader2 *shader = vtkShader2::New();
shader->SetType(VTK_SHADER_TYPE_VERTEX);
shader->SetSourceCode(R"VertexShader(
#version 120
void main()
{
gl_Position = gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
)VertexShader");
shader->SetContext(shader_program->GetContext());
shader_program->GetShaders()->AddItem(shader);
shader->Delete();
shader = vtkShader2::New();
shader->SetType(VTK_SHADER_TYPE_GEOMETRY);
shader->SetSourceCode(R"GeometrytShader(
#version 120
#extension GL_EXT_geometry_shader4 : enable
uniform float xMin, xMax, yMin, yMax;
void main()
{
for (int i = 0; i < gl_VerticesIn; ++i) {
gl_FrontColor = gl_FrontColorIn[i];
gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
if (gl_PositionIn[i].x >= xMin && gl_PositionIn[i].x <= xMax
&& gl_PositionIn[i].y >= yMin && gl_PositionIn[i].y <=
yMax) {
EmitVertex();
}
}
}
)GeometrytShader");
shader->SetContext(shader_program->GetContext());
shader_program->GetShaders()->AddItem(shader);
shader->Delete();
float xMin = -5.0, xMax = 5.0, yMin = -1.0, yMax = 1.0;
vtkUniformVariables *var = shader_program->GetUniformVariables();
var->SetUniformf("xMin", 1, &xMin);
var->SetUniformf("xMax", 1, &xMax);
var->SetUniformf("yMin", 1, &yMin);
var->SetUniformf("yMax", 1, &yMax);
shader_program->Build();
if (shader_program->GetLastBuildStatus() !=
VTK_SHADER_PROGRAM2_LINK_SUCCEEDED) {
std::cout << "Couldn't build the shader program. It could be
an error in a shader, or a driver bug.";
return -1;
}
shader_program->Use();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
Le 2014-09-08 13:26, Christoph Kolb a écrit :
Hi Nil,
Sorry for the delayed answer. I have tried the simple pass-through
shader and a few other examples of geometry shaders. I does not work
for me either, but I get a different error.
In my branch, I only implemented the possibility to read the geometry
shaders additionally to the vertex and fragment shaders,
assuming that the geometry shader is added just like the fragment
shader and no other configuration is necessary.
Have you ever succeeded to use a geometry shader in VTK, or do you
know if there is an example that shows their usage?
Regards
Christoph
On 08.09.2014 16:07, Nil Goyette wrote:
Hi Christoph and all,
Did you have any news on this? Is the simple pass-through geometry
shader supposed to work using your branch?
/2014-08-20/ Christoph Kolb
<http://mitk.org/git/?p=MITK.git;a=search;h=refs/heads/bug-18026-AddGeometryShaderSupport;s=Christoph+Kolb;st=author>
Geometry shader support in mitkVtkShaderRepository
<http://mitk.org/git/?p=MITK.git;a=commit;h=75ca21bd3684267d65544f94441b7e843787bee3>bug-18026-AddGeometryShaderSupport
<http://mitk.org/git/?p=MITK.git;a=shortlog;h=refs/heads/bug-18026-AddGeometryShaderSupport>
http://mitk.org/git/?p=MITK.git;a=commit;h=75ca21bd3684267d65544f94441b7e843787bee3
Le 2014-08-21 09:49, Nil Goyette a écrit :
This being said, I never succeeded in running a geometry shader.
The program starts without error, so the shaders are built and
added in the repository, but when I add a FiberBundleX in the data
manager, I always get the same Visual Studio error
"Unhandled exception at 0x6916B759 (atioglxx.dll) in MI-Brain.exe:
0xC0000005: Access violation reading location 0x00000010."
File vtkOpenGLDisplayListPainter.cxx
Line 181 glCallList(iter->second);
I tried with 3 versions to be sure, but none of them works. I'm
pretty sure 2) should work.
1) The shader I actually want to use, which keeps vertices only in
a specific zone
2) Simple pass-through
#version 120
#extension GL_EXT_geometry_shader4 : enable
void main(void) {
for (int i = 0; i < gl_VerticesIn; ++i) {
gl_Position = gl_PositionIn[i];
EmitVertex();
}
}
3) Empty main() (not sure it's valid though)
<?xml version='1.0' encoding='UTF-8'?>
<Material name='GenericAttributes1'>
<Shader
scope='Vertex'
name='VertexShader'
location='Inline'
language='GLSL'
entry='main'>
#version 120
void main()
{
gl_Position = gl_Vertex;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
</Shader>
<Shader
scope='Geometry'
name='GeometryShader'
location='Inline'
language='GLSL'
entry='main'>
<Uniform name="xMin" type="float" number_of_elements="1" value="1"></Uniform>
<Uniform name="xMax" type="float" number_of_elements="1" value="1"></Uniform>
<Uniform name="yMin" type="float" number_of_elements="1" value="1"></Uniform>
<Uniform name="yMax" type="float" number_of_elements="1" value="1"></Uniform>
#version 120
#extension GL_EXT_geometry_shader4 : enable
uniform float xMin, xMax, yMin, yMax;
void main()
{
for (int i = 0; i < gl_VerticesIn; ++i) {
gl_FrontColor = gl_FrontColorIn[i];
gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[i];
if (gl_PositionIn[i].x >= xMin && gl_PositionIn[i].x >= xMax
&& gl_PositionIn[i].y >= yMin && gl_PositionIn[i].y >= yMax) {
EmitVertex();
}
}
}
</Shader>
</Material>
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce.
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users