Presentation is loading. Please wait.

Presentation is loading. Please wait.

Wilf Comp 4501 95.4501 Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS.

Similar presentations


Presentation on theme: "Wilf Comp 4501 95.4501 Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS."— Presentation transcript:

1 Wilf LaLonde @2013 Comp 4501 95.4501 Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS

2 Wilf LaLonde @2013 Comp 4501 Forgetting to activate the shader when setting up uniforms (it tries to bind to the last activated shader) Many Opportunities For Bugs sampleShader->activate (); sampleShader->setUniformTextureUnit (“textureX", 1); Misspelling the uniform (it ignores you) sampleShader->activate (); sampleShader->setUniformTextureUnit (“ texureX ", 1);

3 Wilf LaLonde @2013 Comp 4501 Mixing up binding for attaching… Binding is for INPUTS Many Opportunities For Bugs At setup time shader->activate (); shader->setUniformTextureUnit (“textureX", 10); At draw time glActiveTexture (GL_TEXTURE10); glBindTexture (GL_TEXTURE_2D, textureID); In the pixel shader “shader.frag” uniform sampler2D textureX; … texture2D (textureX, uv1, 0) VERSUS texelFetch (textureX, uv2, 0)

4 Wilf LaLonde @2013 Comp 4501 Mixing up binding for attaching … Attaching is for OUTPUTS ( so don’t bind textures ) Many Opportunities For Bugs At setup time glBindFramebuffer (GL_FRAMEBUFFER, frameBufferID); attachColorTexture (GL_COLOR_ATTACHMENT10, GL_TEXTURE_2D, colorID); At draw time GLenum drawBuffers [1] = {GL_COLOR_ATTACHMENT10}; glDrawBuffers (1, drawBuffers); In the pixel shader “shader.frag” layout (location = 0) out vec4 X ; … X = vec4 (…); 0 means the first attachment

5 Wilf LaLonde @2013 Comp 4501 You can change the clear color (though there was no need)… Many Opportunities For Bugs glClearColor (0.0, 0.0, 0.0, 1.0); //Black glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT …); Clearing when you SHOULDN’T and not clearing when you should. The backbuffer is PRE-CLEARED before all drawing starts. So you don’t need to do it again. Most MRT textures need clearing since 1. Some parts may not be drawn on 2. If a magic blend causes addition to it, you want it to start at 0 multiplication with it, you want it to start with 1 THIS IS DICTATED BY THE CLEAR COLOR If you forget to clear and you turn left, subsequent draws show remnants of stuff on the right.

6 Wilf LaLonde @2013 Comp 4501 Did you have trouble with a bool uniform? Many Opportunities For Bugs From the OpenGL spec: Either the i, ui or f variants may be used to provide values for uniform variables of type bool. The uniform variable will be set to false if the input value is 0 or 0.0f, and it will be set to true otherwise. glUniform1i (…) glUniform1ui (…) glUniformf (…)

7 Wilf LaLonde @2013 Comp 4501 Did you have trouble with the default shader? It doesn’t exist until a world is loaded Many Opportunities For Bugs But you can do this after a world is loaded. Look up “case RunWorld” in main.cpp So you can’t activate it and set up the texture unit for the aoTexture at setup time

8 Wilf LaLonde @2013 Comp 4501 Did you have trouble with the default shader? It’s designed to load it’s uniforms AT LEAST once per tick (in case lights move) Many Opportunities For Bugs defaultShader->activate (); defaultShader->glUniform1f (“usingAO”, 1.0f); DISABLE_SHADERS; Game->world->draw (); ENABLE_SHADERS; In “world->draw () Shader::reset (); //Causes “setUniforms ();” in shader->activate (); defaultShader->activate (); defaultShader->glUniform1f (“usingAO”, 1.0f); //DISABLE_SHADERS; Game->world->draw (); //ENABLE_SHADERS; DOES NOT execute setUniforms DOES execute setUniforms WILL BREAK shadows (future topic) WILL NOT BREAK shadows (future topic)

9 Wilf LaLonde @2013 Comp 4501 Did you have trouble with the default shader? Not a good idea to have the following in the code where all other default shader uniforms are sets. because that will undo previous setting to 1.0f. Unless you use a global variable And it needs to be false for other switch cases. Many Opportunities For Bugs defaultShader->glUniform1f (“usingAO”, 0.0f); defaultShader->glUniform1f (“usingAO”, globalUsingAO); globalUsingAO = 1.0f; //DISABLE_SHADERS; Game->world->draw (); //ENABLE_SHADERS; In setUniforms

10 Wilf LaLonde @2013 Comp 4501 1.Problems with the z-buffer It draws even if behind a wall. 2.Problems with 0-1 transparency textures. Opaque parts become transparent. Problems With OIT I have an explanation and a solution I have an explanation and a PARTIAL solution

11 Wilf LaLonde @2013 Comp 4501 95.4501 Handling Transparent Objects Drawing Behind Walls

12 Wilf LaLonde @2013 Comp 4501 Why the problem. Transparent Objects Drawing Behind Walls The world is drawn on the back buffer The transparent objects are drawn on the oit frame buffer Hint 1

13 Wilf LaLonde @2013 Comp 4501 Why the problem. Transparent Objects Drawing Behind Walls The world is drawn on the back buffer The transparent objects are drawn on the oit frame buffer Solution: They need to use the same depth buffer

14 Wilf LaLonde @2013 Comp 4501 1.You need to create a “virtualBackBuffer” frame buffer which you use for “prepass” drawing. Use real back buffer at the very end. 2.You need to create a “globalDepthTexture” 3.You need to attach the globalDepthTexture to both 1.virtualBackBuffer 2.ambientOcclusionFrameBuffer How Do We Share Depth Buffers If openGL complains, detach from one and attach to the other… at draw time attachDepthTexture (0); //Should detach

15 Wilf LaLonde @2013 Comp 4501 95.4501 Handling Opaque Parts Properly

16 Wilf LaLonde @2013 Comp 4501 Why the problem? Given C 1 is behind C 2 and C 1 with  1 = 0.8 and C 2 with  2 = 1.0, The combined result is 0.8C 1 + 1.0C 2 0.8+1.0 Drawing Opaque parts makes them transparent. =0.4C 1 + 0.5C 2 You can STILL see some C 1 behind C 2.

17 Wilf LaLonde @2013 Comp 4501 1.Access to the OLD z-depth. You need to have created a texture version of the z- buffer and use it as a zBuffer uniform. Then read it with 2.Access to the NEW z-depth. 3.The ability to change the z-buffer Solution Requirements gl_FragDepth = (newAlpha == 1 && newZ < oldZ ? newZ : oldZ; oldZ = texelFetch (zBuffer, ivec2 (gl_FragCoord.xy), 0).r newZ = gl_FragCoord.z (see next slide) close is 0, far is 1 closeropaque

18 Wilf LaLonde @2013 Comp 4501 Creating a Readable Texture For A Depth Buffer void buildRawDepthTextures (long howMany, GLuint *depthBufferIDs, long width, long height, long filter = GL_LINEAR); void buildRawDepthTextures (long howMany, GLuint *depthBufferIDs, long width, long height, long filter) { //Like buildRawDepthBuffers but creates 2D textures (like buildRawTextures) //instead of render buffers. Filter defaults to GL_LINEAR. glGenTextures (howMany, depthBufferIDs); //Instead of glGenRenderbuffers for (long index = 0; index < howMany; index++) { GLuint depthBufferID = depthBufferIDs [index]; glBindTexture (GL_TEXTURE_2D, depthBufferID); //Instead of glBindRenderbuffer (GL_RENDERBUFFER...) glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); //Instead of glRenderbufferStorage... //The next 4 entries are identical to buildRawTextures... glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); //GL_NEAREST or GL_LINEAR glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); / //GL_NEAREST or GL_LINEAR} detectOpenGLError ("After building rawShadowDepthTexture"); ::log ("\nBuild raw depth texture %dx%d.", width, height); } Portions Are Offscreen

19 Wilf LaLonde @2013 Comp 4501 Wilf note. There is still a problem… If a transparent object behind the wall was PREVIOUSLY drawn and we now encounter an opaque one, how do we UNDRAW IT… OOPs C 0 (transparent) C 1 (opaque) C 2 (transparent) camera If we process in the order C 0, C 1, C 2, we find that C 0 is visible through C 1.

20 Wilf LaLonde @2013 Comp 4501 0-1 transparency textures are considered opaque and should be drawn in the opaque phase. THIS CAN BE DONE PROVIDED WE CAN RECOGNIZE SUCH TEXTURES. Better Solution For example, by placing a funny character as the first character of the texture name. $treeBranch.tga smoke.tga 0-1 transparency normal transparency Another way: associate a “0-transparency default shader” with such objects

21 Wilf LaLonde @2013 Comp 4501 95.4501 End


Download ppt "Wilf Comp 4501 95.4501 Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS."

Similar presentations


Ads by Google