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

		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);

		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);

        /* Set viewing frustum corner rays in shader */
        glUniform3f(eyeUniform, cameraPosition.x, cameraPosition.y, cameraPosition.z);
        invViewProjMatrix.transformProject(tmpVector.set(-1, -1, 0)).sub(cameraPosition);
        glUniform3f(ray00Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set(-1,  1, 0)).sub(cameraPosition);
        glUniform3f(ray01Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set( 1, -1, 0)).sub(cameraPosition);
        glUniform3f(ray10Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set( 1,  1, 0)).sub(cameraPosition);
        glUniform3f(ray11Uniform, tmpVector.x, tmpVector.y, tmpVector.z);

		/* Bind level 0 of framebuffer texture as writable image in the shader. */
		glBindImageTexture(framebufferImageBinding, tex, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);

		/* Compute appropriate invocation dimension. */
		int worksizeX = mathRoundPoT(width);
		int worksizeY = mathRoundPoT(height);

		/* Invoke the compute shader. */
		glDispatchCompute(worksizeX / workGroupSizeX, worksizeY / workGroupSizeY, 1);
		/*
		 * Synchronize all writes to the framebuffer image before we let OpenGL
		 * source texels from it afterwards when rendering the final image with
		 * the full-screen quad.
		 */
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);

		/* Reset bindings. */
		glBindImageTexture(framebufferImageBinding, 0, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
		glUseProgram(0);

		frameNumber++;
	}
/**
	 * Compute one frame by tracing the scene using our compute shader and
	 * presenting that image on the screen.
	 */
Compute one frame by tracing the scene using our compute shader and
presenting that image on the screen.
Compute one frame by tracing the scene using our compute shader and presenting that image on the screen .
private void trace() {
		glUseProgram(computeProgram);
		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);
		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);
        /* Set viewing frustum corner rays in shader */
        glUniform3f(eyeUniform, cameraPosition.x, cameraPosition.y, cameraPosition.z);
        invViewProjMatrix.transformProject(tmpVector.set(-1, -1, 0)).sub(cameraPosition);
        glUniform3f(ray00Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set(-1,  1, 0)).sub(cameraPosition);
        glUniform3f(ray01Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set( 1, -1, 0)).sub(cameraPosition);
        glUniform3f(ray10Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
        invViewProjMatrix.transformProject(tmpVector.set( 1,  1, 0)).sub(cameraPosition);
        glUniform3f(ray11Uniform, tmpVector.x, tmpVector.y, tmpVector.z);
		/* Bind level 0 of framebuffer texture as writable image in the shader. */
		glBindImageTexture(framebufferImageBinding, tex, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
		/* Compute appropriate invocation dimension. */
		int worksizeX = mathRoundPoT(width);
		int worksizeY = mathRoundPoT(height);
		/* Invoke the compute shader. */
		glDispatchCompute(worksizeX / workGroupSizeX, worksizeY / workGroupSizeY, 1);
		/*
		 * Synchronize all writes to the framebuffer image before we let OpenGL
		 * source texels from it afterwards when rendering the final image with
		 * the full-screen quad.
		 */
		glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
		/* Reset bindings. */
		glBindImageTexture(framebufferImageBinding, 0, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
		glUseProgram(0);
		frameNumber++;
	}
private void trace ( ) { glUseProgram ( computeProgram ) ; 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 ) ; 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 ) ; /* Set viewing frustum corner rays in shader */ glUniform3f ( eyeUniform , cameraPosition . x , cameraPosition . y , cameraPosition . z ) ; invViewProjMatrix . transformProject ( tmpVector . set ( - 1 , - 1 , 0 ) ) . sub ( cameraPosition ) ; glUniform3f ( ray00Uniform , tmpVector . x , tmpVector . y , tmpVector . z ) ; invViewProjMatrix . transformProject ( tmpVector . set ( - 1 , 1 , 0 ) ) . sub ( cameraPosition ) ; glUniform3f ( ray01Uniform , tmpVector . x , tmpVector . y , tmpVector . z ) ; invViewProjMatrix . transformProject ( tmpVector . set ( 1 , - 1 , 0 ) ) . sub ( cameraPosition ) ; glUniform3f ( ray10Uniform , tmpVector . x , tmpVector . y , tmpVector . z ) ; invViewProjMatrix . transformProject ( tmpVector . set ( 1 , 1 , 0 ) ) . sub ( cameraPosition ) ; glUniform3f ( ray11Uniform , tmpVector . x , tmpVector . y , tmpVector . z ) ; /* Bind level 0 of framebuffer texture as writable image in the shader. */ glBindImageTexture ( framebufferImageBinding , tex , 0 , false , 0 , GL_READ_WRITE , GL_RGBA32F ) ; /* Compute appropriate invocation dimension. */ int worksizeX = mathRoundPoT ( width ) ; int worksizeY = mathRoundPoT ( height ) ; /* Invoke the compute shader. */ glDispatchCompute ( worksizeX / workGroupSizeX , worksizeY / workGroupSizeY , 1 ) ; /*
		 * Synchronize all writes to the framebuffer image before we let OpenGL
		 * source texels from it afterwards when rendering the final image with
		 * the full-screen quad.
		 */ glMemoryBarrier ( GL_SHADER_IMAGE_ACCESS_BARRIER_BIT ) ; /* Reset bindings. */ glBindImageTexture ( framebufferImageBinding , 0 , 0 , false , 0 , GL_READ_WRITE , GL_RGBA32F ) ; glUseProgram ( 0 ) ; frameNumber ++ ; }
Compute one frame by tracing the scene using our compute shader and
 presenting that image on the screen.
Compute one frame by tracing the scene using our compute shader and presenting that image on the screen .