WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Vertex shader performance problem (https://forum.worldviz.com/showthread.php?t=1713)

Joran 11-14-2008 06:45 AM

Vertex shader performance problem
 
Hello,

I have just started experimenting with vertex shaders and I have a performance problem. Below is an example program that shows my problem:

Code:

import viz
import vizshape

viz.go()
vizshape.addGrid()
viz.MainView.setPosition(0, 1, -5)

vert = """
uniform float elapsedTime;

void main() { 
  if( gl_MultiTexCoord0.y > 0.0) {
    gl_Vertex.x += sin(gl_Vertex.x * 0.2 + elapsedTime * 1.0) * gl_MultiTexCoord0.y * 0.2;
    gl_Vertex.z += sin(gl_Vertex.y * 0.2 + elapsedTime * 1.0) * gl_MultiTexCoord0.y * 0.2;   
  }
 
  gl_FrontColor = gl_Color;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
"""

shape = vizshape.addQuad()
elapsedTime = viz.addUniformFloat('elapsedTime', viz.tick())
shader = viz.addShader(vert = vert, uniforms = [elapsedTime])
shape.apply(shader)

def onUpdate(e):
        elapsedTime.set(viz.tick())

viz.callback(viz.UPDATE_EVENT,onUpdate)

My problem is that when you check the statistics the Draw time is 15.00 (On my system), while it should be something like 0.02. If I do not update the elapsedTime uniform every frame, the performance is fine (but I have no animation). What am I doing wrong?

Greetings, Joran.

farshizzo 11-14-2008 01:22 PM

I don't think you are doing anything wrong. I tried your sample code and my draw time is 0.04 using a GeForce 8800 GTS. This might be an issue with your OpenGL drivers.

FYI, you don't have to create your own elapsed time uniform. OpenSceneGraph supplies the following global uniforms that you can use in any shader:
Code:

int osg_FrameNumber;
float osg_FrameTime;
float osg_DeltaFrameTime;

So you can modify your example to use this global uniform instead:
Code:

import viz
import vizshape

viz.go()
vizshape.addGrid()
viz.MainView.setPosition(0, 1, -5)

vert = """
uniform float osg_FrameTime;

void main() { 
  if( gl_MultiTexCoord0.y > 0.0) {
    gl_Vertex.x += sin(gl_Vertex.x * 0.2 + osg_FrameTime * 1.0) * gl_MultiTexCoord0.y * 0.2;
    gl_Vertex.z += sin(gl_Vertex.y * 0.2 + osg_FrameTime * 1.0) * gl_MultiTexCoord0.y * 0.2;   
  }
 
  gl_FrontColor = gl_Color;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
"""

shape = vizshape.addQuad()
shader = viz.addShader(vert = vert)
shape.apply(shader)


Joran 11-17-2008 01:29 AM

I updated my driver and now it works as expected. And I now also use the osg global uniforms. Thanx.

Greetings, Joran.


All times are GMT -7. The time now is 10:47 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC