src/org/lwjgl/demo/opengl/raytracing/Demo33Ubo.java
private void trace() {
		glUseProgram(rayTracingProgram);

		if (mouseDown) {
			/*
			 * If mouse is down, compute the camera rotation based on mouse
			 * cursor location.
			 */
			currRotationAboutY = rotationAboutY + (mouseX - mouseDownX) * 0.01f;
		} else {
			currRotationAboutY = rotationAboutY;
		}

		/* Rotate camera about Y axis. */
        cameraPosition.set((float) sin(-currRotationAboutY) * 3.0f, 2.0f, (float) cos(-currRotationAboutY) * 3.0f);
        viewMatrix.setLookAt(cameraPosition, cameraLookAt, cameraUp);

        if (resetFramebuffer) {
            projMatrix.setPerspective((float) Math.toRadians(60.0f), (float) width / height, 1f, 2f);
            resizeFramebufferTexture();
            resetFramebuffer = false;
        }
        projMatrix.invertPerspectiveView(viewMatrix, invViewProjMatrix);

		/* Update cameraSettings UBO */
		updateCameraSettingsUbo();

		long thisTime = System.nanoTime();
		float elapsedSeconds = (thisTime - firstTime) / 1E9f;
		glUniform1f(timeUniform, elapsedSeconds);

		/*
		 * We are going to average multiple successive frames, so here we
		 * compute the blend factor between old frame and new frame. 0.0 - use
		 * only the new frame > 0.0 - blend between old frame and new frame
		 */
		float blendFactor = frameNumber / (frameNumber + 1.0f);
		glUniform1f(blendFactorUniform, blendFactor);
		glUniform1i(bounceCountUniform, bounceCount);

		glUniform1f(widthUniform, width);
		glUniform1f(heightUniform, height);
		
		/* Bind UBO for rendering */
		glBindBufferBase(GL_UNIFORM_BUFFER, this.cameraSettingsUboBinding, this.cameraSettingsUbo);

		/*
		 * Draw full-screen quad to generate frame with our tracing shader
		 * program.
		 */
		glBindFramebuffer(GL_FRAMEBUFFER, fbo);
		glBindVertexArray(vao);
		glBindTexture(GL_TEXTURE_2D, tex);
		glBindSampler(0, this.sampler);
		glDrawArrays(GL_TRIANGLES, 0, 6);
		glBindSampler(0, 0);
		glBindTexture(GL_TEXTURE_2D, 0);
		glBindVertexArray(0);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glUseProgram(0);

		/* Unbind UBO */
		glBindBufferBase(GL_UNIFORM_BUFFER, this.cameraSettingsUboBinding, 0);

		frameNumber++;
	}
/**
	 * Compute one frame by tracing the scene using our ray tracing shader and
	 * presenting that image on the screen.
	 */
Compute one frame by tracing the scene using our ray tracing shader and
presenting that image on the screen.
Compute one frame by tracing the scene using our ray tracing shader and presenting that image on the screen .
private void trace() {
		glUseProgram(rayTracingProgram);
		if (mouseDown) {
			/*
			 * If mouse is down, compute the camera rotation based on mouse
			 * cursor location.
			 */
			currRotationAboutY = rotationAboutY + (mouseX - mouseDownX) * 0.01f;
		} else {
			currRotationAboutY = rotationAboutY;
		}
		/* Rotate camera about Y axis. */
        cameraPosition.set((float) sin(-currRotationAboutY) * 3.0f, 2.0f, (float) cos(-currRotationAboutY) * 3.0f);
        viewMatrix.setLookAt(cameraPosition, cameraLookAt, cameraUp);
        if (resetFramebuffer) {
            projMatrix.setPerspective((float) Math.toRadians(60.0f), (float) width / height, 1f, 2f);
            resizeFramebufferTexture();
            resetFramebuffer = false;
        }
        projMatrix.invertPerspectiveView(viewMatrix, invViewProjMatrix);
		/* Update cameraSettings UBO */
		updateCameraSettingsUbo();
		long thisTime = System.nanoTime();
		float elapsedSeconds = (thisTime - firstTime) / 1E9f;
		glUniform1f(timeUniform, elapsedSeconds);
		/*
		 * We are going to average multiple successive frames, so here we
		 * compute the blend factor between old frame and new frame. 0.0 - use
		 * only the new frame > 0.0 - blend between old frame and new frame
		 */
		float blendFactor = frameNumber / (frameNumber + 1.0f);
		glUniform1f(blendFactorUniform, blendFactor);
		glUniform1i(bounceCountUniform, bounceCount);
		glUniform1f(widthUniform, width);
		glUniform1f(heightUniform, height);
		/* Bind UBO for rendering */
		glBindBufferBase(GL_UNIFORM_BUFFER, this.cameraSettingsUboBinding, this.cameraSettingsUbo);
		/*
		 * Draw full-screen quad to generate frame with our tracing shader
		 * program.
		 */
		glBindFramebuffer(GL_FRAMEBUFFER, fbo);
		glBindVertexArray(vao);
		glBindTexture(GL_TEXTURE_2D, tex);
		glBindSampler(0, this.sampler);
		glDrawArrays(GL_TRIANGLES, 0, 6);
		glBindSampler(0, 0);
		glBindTexture(GL_TEXTURE_2D, 0);
		glBindVertexArray(0);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glUseProgram(0);
		/* Unbind UBO */
		glBindBufferBase(GL_UNIFORM_BUFFER, this.cameraSettingsUboBinding, 0);
		frameNumber++;
	}
private void trace ( ) { glUseProgram ( rayTracingProgram ) ; if ( mouseDown ) { /*
			 * If mouse is down, compute the camera rotation based on mouse
			 * cursor location.
			 */ currRotationAboutY = rotationAboutY + ( mouseX - mouseDownX ) * 0.01f ; } else { currRotationAboutY = rotationAboutY ; } /* Rotate camera about Y axis. */ cameraPosition . set ( ( float ) sin ( - currRotationAboutY ) * 3.0f , 2.0f , ( float ) cos ( - currRotationAboutY ) * 3.0f ) ; viewMatrix . setLookAt ( cameraPosition , cameraLookAt , cameraUp ) ; if ( resetFramebuffer ) { projMatrix . setPerspective ( ( float ) Math . toRadians ( 60.0f ) , ( float ) width / height , 1f , 2f ) ; resizeFramebufferTexture ( ) ; resetFramebuffer = false ; } projMatrix . invertPerspectiveView ( viewMatrix , invViewProjMatrix ) ; /* Update cameraSettings UBO */ updateCameraSettingsUbo ( ) ; long thisTime = System . nanoTime ( ) ; float elapsedSeconds = ( thisTime - firstTime ) / 1E9f ; glUniform1f ( timeUniform , elapsedSeconds ) ; /*
		 * We are going to average multiple successive frames, so here we
		 * compute the blend factor between old frame and new frame. 0.0 - use
		 * only the new frame > 0.0 - blend between old frame and new frame
		 */ float blendFactor = frameNumber / ( frameNumber + 1.0f ) ; glUniform1f ( blendFactorUniform , blendFactor ) ; glUniform1i ( bounceCountUniform , bounceCount ) ; glUniform1f ( widthUniform , width ) ; glUniform1f ( heightUniform , height ) ; /* Bind UBO for rendering */ glBindBufferBase ( GL_UNIFORM_BUFFER , this . cameraSettingsUboBinding , this . cameraSettingsUbo ) ; /*
		 * Draw full-screen quad to generate frame with our tracing shader
		 * program.
		 */ glBindFramebuffer ( GL_FRAMEBUFFER , fbo ) ; glBindVertexArray ( vao ) ; glBindTexture ( GL_TEXTURE_2D , tex ) ; glBindSampler ( 0 , this . sampler ) ; glDrawArrays ( GL_TRIANGLES , 0 , 6 ) ; glBindSampler ( 0 , 0 ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glBindVertexArray ( 0 ) ; glBindFramebuffer ( GL_FRAMEBUFFER , 0 ) ; glUseProgram ( 0 ) ; /* Unbind UBO */ glBindBufferBase ( GL_UNIFORM_BUFFER , this . cameraSettingsUboBinding , 0 ) ; frameNumber ++ ; }
Compute one frame by tracing the scene using our ray tracing shader and
 presenting that image on the screen.
Compute one frame by tracing the scene using our ray tracing shader and presenting that image on the screen .