View Single Post
  #1  
Old 11-14-2008, 06:45 AM
Joran Joran is offline
Member
 
Join Date: Jun 2006
Posts: 38
Send a message via Yahoo to Joran
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.
Reply With Quote