Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Steward
VTK
Commits
1c7d1cd0
Commit
1c7d1cd0
authored
7 years ago
by
Sankhesh Jhaveri
Browse files
Options
Downloads
Patches
Plain Diff
Added test that demonstrates ability to set shader uniforms from python
parent
e1a4d5b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Rendering/OpenGL2/Testing/Python/CMakeLists.txt
+9
-0
9 additions, 0 deletions
Rendering/OpenGL2/Testing/Python/CMakeLists.txt
Rendering/OpenGL2/Testing/Python/TestUserShader2.py
+99
-0
99 additions, 0 deletions
Rendering/OpenGL2/Testing/Python/TestUserShader2.py
with
108 additions
and
0 deletions
Rendering/OpenGL2/Testing/Python/CMakeLists.txt
0 → 100644
+
9
−
0
View file @
1c7d1cd0
set
(
RenderingOpenGL2PythonTests
TestUserShader2.py
)
if
(
"
${
VTK_RENDERING_BACKEND
}
"
STREQUAL
"OpenGL2"
)
vtk_add_test_python
(
${
RenderingOpenGL2PythonTests
}
)
endif
()
This diff is collapsed.
Click to expand it.
Rendering/OpenGL2/Testing/Python/TestUserShader2.py
0 → 100755
+
99
−
0
View file @
1c7d1cd0
#!/usr/bin/env python
'''
=========================================================================
Program: Visualization Toolkit
Module: TestUserShader2.py
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http:#www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================
'''
import
sys
import
vtk
from
vtk.util.misc
import
vtkGetDataRoot
'''
Prevent .pyc files from being created.
Stops the vtk source being polluted
by .pyc files.
'''
sys
.
dont_write_bytecode
=
True
@vtk.calldata_type
(
vtk
.
VTK_OBJECT
)
def
vtkShaderCallback
(
caller
,
event
,
calldata
):
program
=
calldata
if
program
is
not
None
:
diffuseColor
=
[
0.4
,
0.7
,
0.6
]
program
.
SetUniform3f
(
"
diffuseColorUniform
"
,
diffuseColor
)
renWin
=
vtk
.
vtkRenderWindow
()
renWin
.
SetSize
(
400
,
400
)
iren
=
vtk
.
vtkRenderWindowInteractor
()
iren
.
SetRenderWindow
(
renWin
)
ren
=
vtk
.
vtkRenderer
()
ren
.
SetBackground
(
0.0
,
0.0
,
0.0
)
ren
.
GradientBackgroundOn
()
renWin
.
AddRenderer
(
ren
)
actor
=
vtk
.
vtkActor
()
ren
.
AddActor
(
actor
)
reader
=
vtk
.
vtkPLYReader
()
reader
.
SetFileName
(
""
+
str
(
vtkGetDataRoot
())
+
"
/Data/dragon.ply
"
)
norms
=
vtk
.
vtkTriangleMeshPointNormals
()
norms
.
SetInputConnection
(
reader
.
GetOutputPort
())
mapper
=
vtk
.
vtkOpenGLPolyDataMapper
()
mapper
.
SetInputConnection
(
norms
.
GetOutputPort
())
actor
.
SetMapper
(
mapper
)
actor
.
GetProperty
().
SetAmbientColor
(
0.2
,
0.2
,
1.0
)
actor
.
GetProperty
().
SetDiffuseColor
(
1.0
,
0.65
,
0.7
)
actor
.
GetProperty
().
SetSpecularColor
(
1.0
,
1.0
,
1.0
)
actor
.
GetProperty
().
SetSpecular
(
0.5
)
actor
.
GetProperty
().
SetDiffuse
(
0.7
)
actor
.
GetProperty
().
SetAmbient
(
0.5
)
actor
.
GetProperty
().
SetSpecularPower
(
20.0
)
actor
.
GetProperty
().
SetOpacity
(
1.0
)
mapper
.
SetVertexShaderCode
(
"
//VTK::System::Dec
\n
"
"
attribute vec4 vertexMC;
\n
"
"
//VTK::Normal::Dec
\n
"
"
uniform mat4 MCDCMatrix;
\n
"
"
void main () {
\n
"
"
normalVCVSOutput = normalMatrix * normalMC;
\n
"
"
vec4 tmpPos = MCDCMatrix * vertexMC;
\n
"
"
gl_Position = tmpPos*vec4(0.2+0.8*abs(tmpPos.x),0.2+0.8*abs(tmpPos.y),1.0,1.0);
\n
"
"
}
\n
"
)
mapper
.
SetFragmentShaderCode
(
"
//VTK::System::Dec
\n
"
"
//VTK::Output::Dec
\n
"
"
varying vec3 normalVCVSOutput;
\n
"
"
uniform vec3 diffuseColorUniform;
\n
"
"
void main () {
\n
"
"
float df = max(0.0, normalVCVSOutput.z);
\n
"
"
float sf = pow(df, 20.0);
\n
"
"
vec3 diffuse = df * diffuseColorUniform;
\n
"
"
vec3 specular = sf * vec3(0.4,0.4,0.4);
\n
"
"
gl_FragData[0] = vec4(0.3*abs(normalVCVSOutput) + 0.7*diffuse + specular, 1.0);
\n
"
"
}
\n
"
)
mapper
.
AddObserver
(
vtk
.
vtkCommand
.
UpdateShaderEvent
,
vtkShaderCallback
)
renWin
.
Render
()
ren
.
GetActiveCamera
().
SetPosition
(
-
0.2
,
0.4
,
1
)
ren
.
GetActiveCamera
().
SetFocalPoint
(
0
,
0
,
0
)
ren
.
GetActiveCamera
().
SetViewUp
(
0
,
1
,
0
)
ren
.
ResetCamera
()
ren
.
GetActiveCamera
().
Zoom
(
2.0
)
renWin
.
Render
()
iren
.
Start
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment