Jump to content
  • Advertisement

nattfoedd

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

266 Neutral

About nattfoedd

  • Rank
    Newbie
  1. Hi everybody, I'm having difficulties trying to prove my idea that the projection area of a surface on a view rendered from a light source correlates to its received total radiant power. Maybe you guys can give me some feedback on the validity of my thesis. So the total received radiant power of a surface equals [attachment=24482:Tex2Img_1415190829.jpg] (V is meant as visibility and E is irradiance) When only considering directional lights first, E is constant over the scene. My thesis now is that (again for directional lights) the integral over the image plane gives you the total radiant power emitted by the light. So each point on the image plane equals a point of emission with the same radiant exitance of [attachment=24483:Tex2Img_1415190921.jpg] Due to the invariance of radiance along a path irradiance E on a surface equals M. So the integral over the visible projected area should directly relate to the total received radiance by this directional light [attachment=24484:Tex2Img_1415190986.jpg] and therefore also [attachment=24485:Tex2Img_1415191079.jpg] What I'm not sure about is, if it is possible to translate this to point lights. My approach here would be to go over intensity, which is assumed constant in all directions. Here irradiance on a surface is reduced by distance squared, because the solid angle that the surface covers from the light's view is reduced with growing distance. [attachment=24486:Tex2Img_1415191119.jpg] and [attachment=24487:Tex2Img_1415191196.jpg] However with perspective projection not all areas on the image plane cover a solid angle of the same size. This varies also with cos theta from the viewing direction. According to Krivanek & Gautron ("Practical Global Illumination with Irradiance Caching") the solid angle of a texel of a perspective projection equals to: [attachment=24488:Tex2Img_1415191352.jpg] So is it valid to say that we can simply weight the assumed radiance exitance on a point on the image plane by its covered solid angle for perspective projections? And so in that case received radiant power is dependant on both area of projection and the angle theta to the viewing direction. Hope that at least some of it made some sense - if not I'm looking forward to your corrections     BTW: Unforuntately adding latex equation using the forum's editor or external linkage from sciweavers.org didn't work...
  2. nattfoedd

    Shader variables (uniform)

    Another way would be to use subroutines for this behaviour:   http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/glsl-core-tutorial-subroutines/
  3. Not necessarily, as long as you don't run out of texture units (meaning you would have to rebind textures a lot) it's probably even faster than bindless, resident textures.
  4. Hi everyone,   currently I'm working on a project that uses a 3D texture as voxel storage. Everything's working fine so far, but I'd love to optimze my memory usage and since I'm working with GL4.4 anyway I thought I'd give the GL_TEXTURE_SPARSE_ARB extension a try. The extension has been promoted by Cass Everitt (p.34) and Graham Sellers (p.43) multiple times lately, so I hoped I could get it to work too.   Unfortunately I get no result when querying for the virtual page sizes as described in the presentations.   While glGetIntegerv(GL_MAX_SPARSE_3D_TEXTURE_SIZE_ARB, &maxSize) returns the expected 2048.   I don't get any number of indices from these.. glGetInternalformativ(GL_TEXTURE_3D, GL_NUM_VIRTUAL_PAGE_SIZES_ARB, GL_RGBA8, sizeof(GLint), &numSizes); glGetInternalformativ(GL_TEXTURE_3D, GL_VIRTUAL_PAGE_SIZE_X_ARB, GL_RGBA8, numSizes*sizeof(GLint), pageSizesX); I also tried GL_TEXTURE_2D instead, as used in the slides - the result is no different.   Cass Everitt writes   so, question is...what to do? This sounds like the extension could still work on my HW and drivers, but I'd need to guess the proper virtual page size index I'd want to use.    Has anybody worked with this yet and knows the page sizes (for Nvidia)? I hope it's just a driver issue on windows...   Thanks in advance on any input on this issue   PS: GPU is a GTX780, driver is the latest 335.23, OS win8.1
  5. nattfoedd

    Rendering to texture/FBO issue

    Of course :facepalm: I cleared before binding the buffer. Just had to swap these in the code and now everything works fine. Thanks again
  6. nattfoedd

    Rendering to texture/FBO issue

    Hey agentd, first of all, thank you a lot for your reply! I suspected something like that, but didn't know I had to explicitely create a depth buffer FBO for it. So I tried to do my homework and checked several (very similar) tutorials about it, but after implementing the following code my texture just stays black (rest of the code didn't change) void CreateRawShadowFBO() { GLenum rawShadowsFBOstatus; // generate and bind the rawShadowTexture glGenTextures(1, &rawShadowTexture); glBindTexture(GL_TEXTURE_2D, rawShadowTexture); // set the parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); // texture size = viewport size glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, (int) observerWidth, (int) observerHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); // unbind texture glBindTexture(GL_TEXTURE_2D, 0); // generate and bind depth buffer glGenRenderbuffers(1, &rawShadowsDepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, rawShadowsDepthBuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, (int) observerWidth, (int) observerHeight); //unbind depth buffer glBindRenderbuffer(GL_RENDERBUFFER, 0); // generate and bind the rawShadowsFBO glGenFramebuffers(1, &rawShadowsFBO); glBindFramebuffer(GL_FRAMEBUFFER, rawShadowsFBO); // attach the color texture to the frame buffer glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rawShadowTexture, 0); // attach depth buffer glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rawShadowsDepthBuffer); // check rawShadowsFBO status rawShadowsFBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(rawShadowsFBOstatus != GL_FRAMEBUFFER_COMPLETE) printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use rawShadowsFBO\n"); // switch back to window-system-provided framebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } If I don't attach the depth buffer FBO ([size=2][font=courier new,courier,monospace]glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rawShadowsDepthBuffer[/font]); ) I get the same result as before. So I'm afraid my depth buffer FBO is setup in a wrong way, though I'm unable to see what's the issue, as I can't see any difference to the 3 tutorials I checked on that matter. That's the thing I which makes it sometimes hard to enjoy OpenGL coding for a beginner like me, as it's really hard to debug. Feels like a big blackbox. Your assumption was right. I'm trying to achieve something along that matter, though I don't plan to apply a uniform blur. Had an idea to compensate the viewing angle dependent issue you mentioned. However I've no idea if this will work out as I've planned, but that doesn't really matter, as I'm having fun playing around with stuff like that. I did implement both PCF and PCSS shadow mapping a while ago (2nd with rotated poisson disc): So as I mentioned before, my goal here is not really about just implementing a shadow algorithm, but more playing around with my own ideas (as bad as they might turn out ;) ). I also looked into VSM when I did the other shadow mapping techniques a while back, but felt like it had too many limitations.
  7. Hi everybody, just registered here after beeing stuck for hours. I'm fairly new to OpenGL programming, though I wrote some simple programs and shaders before. I'm sure somebody around here can tell me, what's going wrong here. What I'm trying to achieve here is a simple multi-pass shadowmapping rendering: #1 Render the z-buffer of the light to a texture #2 Render the shadows to another texture (viewport resolution) (#3 Do something with this texture, that's not implemented at the moment) #4 Render the scene and apply the shadows from the previously rendered texture in step #2 For reference, that's what the scene looks like without shadows: When I display the result of step #2 in the viewport I get, what I expect - the calculated shadows, which are correctly occluded by the geometry: Now when I simply display the texture rendered in step #2 in the fragment shader of step #4 I get this: As you can see, this is basically the identical image, but the first and the third cylinder are suddenly missing, eventhough I didn't change anything. So obviously there is something different rendered to the texture then, when I render the same thing to the viewport (maybe some depth/drawing order issue?). So I guess there must be either something wrong how I setup the FBO or the texture or some settings I set before drawing the scene. Here I generate the texture used in step #2 and bind it to the FBO: void CreateRawShadowFBO() { GLenum rawShadowsFBOstatus; // generate and bind the rawShadowTexture glGenTextures(1, &rawShadowTexture); glBindTexture(GL_TEXTURE_2D, rawShadowTexture); // set the parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); // texture size = viewport size glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, (int) observerWidth, (int) observerHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); glBindTexture(GL_TEXTURE_2D, 0); // generate and bind the rawShadowsFBO glGenFramebuffers(1, &rawShadowsFBO); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, rawShadowsFBO); // set the rawShadowTexture as render target glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rawShadowTexture, 0); // check rawShadowsFBO status rawShadowsFBOstatus = glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER); if(rawShadowsFBOstatus != GL_FRAMEBUFFER_COMPLETE_EXT) printf("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use rawShadowsFBO\n"); // switch back to window-system-provided framebuffer glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0); } Here's the shadow calculating part (step #2): void ProcessShadowMap() { //set the viewport glViewport(0, 0, (int) observerWidth, (int)observerHeight); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //set the matrices M3DMatrix44f shadowMat; M3DMatrix44f viewMat; M3DMatrix44f eyeToLightView; UpdateMatrices(shadowMat, viewMat, eyeToLightView); glColorMask(GL_TRUE,GL_TRUE, GL_TRUE, GL_FALSE); glDepthMask(GL_TRUE); glClear(GL_DEPTH_BUFFER_BIT); // render the 'raw' shadows to the rawShadowsFBO glBindFramebuffer(GL_DRAW_FRAMEBUFFER, rawShadowsFBO); // set the process shadows shader glUseProgram(procShadowsShader); // bind the previously rendered depthmap glBindTexture(GL_TEXTURE_2D, shadowMap); // set the Model View Projection Matrix for the shader glUniformMatrix4fv(glGetUniformLocation(procShadowsShader, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); //Projektionsmatrix glUniformMatrix4fv(glGetUniformLocation(procShadowsShader, "projMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // set the ShadowMatrix for the shader glUniformMatrix4fv(glGetUniformLocation(procShadowsShader, "eyeToLightViewTexMatrix"), 1, GL_FALSE, shadowMat); glUniformMatrix4fv(glGetUniformLocation(procShadowsShader, "eyeToLightViewMatrix"), 1, GL_FALSE, eyeToLightView); //calc the light's position, at the origin of the light-view matrix M3DMatrix44f invLight; m3dInvertMatrix44(invLight,lightView); M3DVector4f lp; m3dLoadVector4(lp,0,0,0,0); m3dTransformVector4(lightPos, lp, invLight); // set the light's parameters glUniform4fv(glGetUniformLocation(procShadowsShader,"lightPos"),1,lightPos); glUniform1f(glGetUniformLocation(procShadowsShader,"lightNear"),lightNearClip); glUniform1f(glGetUniformLocation(procShadowsShader,"lightFar"),lightFarClip); float lightSizeX = (lightSize/lightFrustumWidth)/(float)shadowMapSize; float lightSizeY = (lightSize/lightFrustumHeight)/(float)shadowMapSize; glUniform2f(glGetUniformLocation(procShadowsShader,"wLight"),lightSizeX,lightSizeY); glUniform1i(glGetUniformLocation(procShadowsShader,"shadowMap"),0); //draw the model modelBatch.Draw(); //(de)activate stuff glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); modelViewMatrix.PopMatrix(); glColorMask(GL_TRUE,GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); gltCheckErrors(procShadowsShader); } And here's the final step #4, at the moment the shader used here just displays the rendered texture in step #2: void RenderShadows() { //set the viewport glViewport(0, 0, (int) observerWidth, (int)observerHeight); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //set the projection matrix viewFrustum.SetPerspective(45.0f,aspect,0.1f,100); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); //switch cameras if(!toggleView) modelViewMatrix.PushMatrix(observerFrame); else modelViewMatrix.PushMatrix(lightFrame); //set the shader program glUseProgram(displayShadows); //bind the shadowtexture glBindTexture(GL_TEXTURE_2D, rawShadowTexture); // set the Model View Matrix glUniformMatrix4fv(glGetUniformLocation(displayShadows, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); //set the Projectionsmatrix glUniformMatrix4fv(glGetUniformLocation(displayShadows, "projMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); //set the Normalmatrix glUniformMatrix3fv(glGetUniformLocation(displayShadows, "normalMatrix"), 1, GL_FALSE, transformPipeline.GetNormalMatrix()); //light position M3DMatrix44f invLight; m3dInvertMatrix44(invLight,lightView); M3DVector4f lp; m3dLoadVector4(lp,0,0,0,0); m3dTransformVector4(lightPos, lp, invLight); //light parameters glUniform4fv(glGetUniformLocation(displayShadows,"lightPos"),1,lightPos); glUniform4f(glGetUniformLocation(displayShadows,"lightAmbient"),1,1,1,1); glUniform4f(glGetUniformLocation(displayShadows,"lightDiffuse"),1,1,1,1); glUniform1f(glGetUniformLocation(displayShadows,"lightNear"),lightNearClip); glUniform1f(glGetUniformLocation(displayShadows,"lightFar"),lightFarClip); float lightSizeX = (lightSize/lightFrustumWidth)/(float)shadowMapSize; float lightSizeY = (lightSize/lightFrustumHeight)/(float)shadowMapSize; glUniform2f(glGetUniformLocation(displayShadows,"wLight"),lightSizeX,lightSizeY); glUniform1i(glGetUniformLocation(displayShadows,"shadowMap"),0); //draw the model modelBatch.Draw(); glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); modelViewMatrix.PopMatrix(); gltCheckErrors(displayShadows); } Anybode an idea what goes wrong, when rendering to the texture? I'd be really grateful for any hints
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!