SHARE
TWEET
Untitled
a guest
Dec 21st, 2014
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public void initFramebuffers() {
- // Depth buffer
- glBindFramebuffer(GL_FRAMEBUFFER, depthShader.fbo);
- depthShader.initTexture(width, height, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthShader.tex, 0);
- glDrawBuffer(GL_NONE);
- glReadBuffer(GL_NONE);
- }
- //INSIDE DEPTHSHADER CONTAINER CLASS
- public void initTexture(int width, int height, int format, int internalFormat) {
- tex = glGenTextures();
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_FLOAT, (ByteBuffer)null);
- }
- //INSIDE BLURDEPTH CONTAINER CLASS
- public void blurDepthVAO() {
- float[] vertices = new float[] {
- -1.0f, 1.0f,
- -1.0f, -1.0f,
- 1.0f, 1.0f,
- 1.0f, -1.0f
- };
- FloatBuffer verts = BufferUtils.createFloatBuffer(vertices.length);
- verts.put(vertices);
- verts.flip();
- vao = glGenVertexArrays();
- glBindVertexArray(vao);
- int vbo = glGenBuffers();
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
- glVertexAttribPointer(position, 2, GL_FLOAT, false, 0, 0);
- glEnableVertexAttribArray(position);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- //INSIDE RUN METHOD
- //--------------------Particle Depth-----------------------
- {
- glUseProgram(depthShader.program);
- glBindFramebuffer(GL_FRAMEBUFFER, depthShader.fbo);
- depthShader.particleDepthVAO(points);
- RenderUtility.addMatrix(depthShader, mView, "mView");
- RenderUtility.addMatrix(depthShader, projection, "projection");
- RenderUtility.addVector2(depthShader, screenSize, "screenSize");
- RenderUtility.addVector3(depthShader, lightPosition, "lightPos");
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Draw VAO
- glBindVertexArray(depthShader.vao);
- glDrawArrays(GL_POINTS, 0, points.size());
- }
- //--------------------Particle Blur-----------------------
- {
- glUseProgram(blurShader.program);
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- blurShader.blurDepthVAO();
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, depthShader.tex);
- glUniform1i(blurShader.depthMap, 0);
- RenderUtility.addMatrix(blurShader, mView, "mView");
- RenderUtility.addMatrix(blurShader, projection, "projection");
- RenderUtility.addVector2(blurShader, screenSize, "screenSize");
- glEnable(GL_DEPTH_TEST);
- glBindVertexArray(blurShader.vao);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glViewport(0, 0, width, height);
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

