![]() |
|
#1
|
|||
|
|||
By default, Vizard will automatically compute the near/far clipping planes based on what geometry is in view. The clip planes in the matrix returned by viz.MainWindow.getProjectionMatrix() won't match the clip planes that will be used to perform the rendering. This is why the ground shows up on top of the box.
You can use the viz.MainWindow.clip command to specify static clip planes. This will ensure the projection matrix is the same as the one being used to render the scene. Here is an updated version of the script: Code:
import viz, vizcam, vizshape, vizfx.postprocess, vizact vizcam.PivotNavigate(center=[0, 0.1, 0], distance=5) viz.go() box = viz.addChild('box.wrl') ground = viz.addChild('ground.osgb') vertCode = """ uniform vec4 S1, S2, S3, S4; void main() { gl_Position = mat4(S1, S2, S3, S4) * gl_ModelViewMatrix * gl_Vertex; } """ fragCode = """ void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } """ shader = viz.addShader(vert=vertCode, frag=fragCode) box.apply(shader) # Use static clip plane so projection matrix doesn't change viz.MainWindow.clip(0.1,100) m = viz.MainWindow.getProjectionMatrix() S1 = viz.addUniformFloat('S1', m[0:4]) S2 = viz.addUniformFloat('S2', m[4:8]) S3 = viz.addUniformFloat('S3', m[8:12]) S4 = viz.addUniformFloat('S4', m[12:16]) box.apply(S1) box.apply(S2) box.apply(S3) box.apply(S4) |
#2
|
|||
|
|||
Thanks for the help!
Do you happen to know why viz.MainWindow.getMatrix() * box.getMatrix() is incorrect for the modelview matrix? The box shows up but is moving incorrectly when I rotate the viewpoint. |
#3
|
|||
|
|||
You need to pass the inverse of the view matrix:
Code:
m = viz.MainWindow.getMatrix().inverse() |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Vizard Headlight in Shader | shivanangel | Vizard | 1 | 06-27-2012 01:19 PM |
SSAO Shader Implementation | FranciscoPeters | Vizard | 2 | 10-08-2011 04:19 AM |
How to apply shader and render texture to an object | whj | Vizard | 0 | 04-23-2010 12:23 PM |
Multiple Textures for Diffuse and Specularity Shader Issue | shivanangel | Vizard | 1 | 05-11-2009 10:44 AM |
Specular Shader Issue | shivanangel | Vizard | 2 | 05-06-2009 11:08 AM |