tag:blogger.com,1999:blog-65682171515964708772024-03-04T21:09:26.518-08:00GPU Programming Final Project -ShadowsThis blog contains the latest info on my project for GPU programmingslstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-6568217151596470877.post-5520720166044357562011-04-23T20:32:00.000-07:002011-04-23T20:33:20.698-07:00April 23, Project EndHi guys,<br />
It's been a fun and fruitful semester. The submission for this project includes a paper, video, poster, and source code. All of these should appear below:<br />
<br />
Paper: <a href="http://www.stuartsummerfield.com/shadowspaper.pdf">http://www.stuartsummerfield.com/shadowspaper.pdf</a><br />
Poster: <a href="http://www.stuartsummerfield.com/shadowsposter.pptx">http://www.stuartsummerfield.com/shadowsposter.pptx</a><br />
Video: <a href="http://www.stuartsummerfield.com/shadowsvideo.wmv">http://www.stuartsummerfield.com/shadowsvideo.wmv</a><br />
Source: <a href="http://www.stuartsummerfield.com/shadowsproj.zip">http://www.stuartsummerfield.com/shadowsproj.zip</a>slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com1tag:blogger.com,1999:blog-6568217151596470877.post-32505560822983196762011-04-20T19:16:00.000-07:002011-04-20T19:19:51.760-07:00Final Stretch Update April 20Hi guys,<br />
So I made an attempt to do shadow volumes this week. At first I wanted the shadow volumes to be simple like extending some triangles to infinity to form cylinders to implement a kind of "drop shadow" which is sometimes implemented in multiplayer games as the "lowest" quality dynamic shadow rendering technique where FPS and performance is extremely important and gamers won't sacrifice quality if it drops their fps below say... 50 fps. Here's a pic of my cylinders to be used as shadow volumes, which change depending on the direction of the light.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgFYDeUKu_iIa0owpxvZw5yq5avhF7sYySPAVy6xnM7MGxfWjPQciMwbIPqM5-HhZnCEKX9qp_mClUXRZgRkHiNI1GL29-zF1O-jA8ma7YCyRU6t6BZVGZNm4ABDvM8FfThJ8l28Zfezk/s1600/April20.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgFYDeUKu_iIa0owpxvZw5yq5avhF7sYySPAVy6xnM7MGxfWjPQciMwbIPqM5-HhZnCEKX9qp_mClUXRZgRkHiNI1GL29-zF1O-jA8ma7YCyRU6t6BZVGZNm4ABDvM8FfThJ8l28Zfezk/s320/April20.jpg" width="320" /></a></div>After getting the volumes, I found a project that implemented shadow volumes and attempted to integrate the code to make it work. The code I scrapped together to draw the shadow volumes looked something like this...<br />
<br />
void Terrain::DrawVolumes()<br />
{<br />
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);<br />
glClearColor(sky_color[0], sky_color[1], sky_color[2], sky_color[3]);<br />
<br />
//Draw ambient<br />
glPushAttrib(GL_ENABLE_BIT);<br />
glEnable(GL_COLOR_MATERIAL);<br />
glLightfv(GL_LIGHT1, GL_POSITION, light_pos); <br />
glLightfv(GL_LIGHT1, GL_AMBIENT, sky_color_div);<br />
glLightfv(GL_LIGHT1, GL_DIFFUSE, sky_color_div);<br />
glLightfv(GL_LIGHT1, GL_SPECULAR, black);<br />
glEnable(GL_LIGHT1);<br />
glEnable(GL_LIGHTING);<br />
<br />
drawObjects() // terrain, static, and animateable<br />
<br />
//Draw shadow volumes<br />
glPushAttrib(GL_ALL_ATTRIB_BITS);<br />
glColorMask(0, 0, 0, 0);<br />
glShadeModel(GL_FLAT);<br />
glDepthMask(0);<br />
glDepthFunc(GL_LESS);<br />
glEnable(GL_STENCIL_TEST);<br />
<br />
glPushMatrix();<br />
glTranslatef(-half_width, 0, -half_height);<br />
<br />
// Shadow Volumes<br />
for(unsigned int i=0; i<1; i++)<br />
{<br />
//using zpass<br />
//Increment stencil buffer for front face depth pass<br />
glStencilFunc(GL_ALWAYS, 0, ~0);<br />
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);<br />
glCullFace(GL_BACK);<br />
<br />
// Draw Shadow Volume Objects<br />
DrawCylinders();<br />
<br />
//Decrement stencil buffer for back face depth pass<br />
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);<br />
glCullFace(GL_FRONT);<br />
<br />
// Draw Shadow Volume Objects<br />
DrawCylinders();<br />
} <br />
glPopMatrix();<br />
glPopAttrib();<br />
<br />
//Now draw lit where stencil == 0<br />
glPushAttrib(GL_ENABLE_BIT);<br />
glEnable(GL_COLOR_MATERIAL);<br />
glLightfv(GL_LIGHT1, GL_POSITION, light_pos); <br />
glLightfv(GL_LIGHT1, GL_AMBIENT, sky_color_div);<br />
glLightfv(GL_LIGHT1, GL_DIFFUSE, sky_color);<br />
glLightfv(GL_LIGHT1, GL_SPECULAR, white);<br />
glEnable(GL_LIGHT1);<br />
glEnable(GL_LIGHTING);<br />
glStencilFunc(GL_EQUAL, 0, ~0);<br />
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);<br />
glEnable(GL_STENCIL_TEST);<br />
<br />
drawObjects();<br />
}<br />
<br />
Unfortunately I wasn't getting any shadows, even after initializing openGL differently. I then thought, maybe drawing cylinders using gluQuadricObjects wasn't valid, so I drew a single triangle and extended its 3 edges to infinity by drawing 3 quads. I was able to see the 3 faces of this triangle without endcaps, but wasn't able to get a triangle of shadow.<br />
I'm giving up on rendering shadow volumes for now, as I'd like to explore more shadow mapping techniques before the deadline for this project, which is next week. Although it's somewhat demoralizing to spend about 15 hours attempting to get shadow volumes working without much to show for the effort, I've learned that one of the biggest disadvantages to shadow volume rendering is implementation difficulty. Even had I been able to get the single triangle working, there's still several cases I hadn't handled like the viewport being inside a shadow volume, for example. Also the fps wasn't looking very promising even with drawing the cylinders, let alone extending silhouette edges for somewhat complicated 3d models. Stay tuned for the final!slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com1tag:blogger.com,1999:blog-6568217151596470877.post-14354876120926908452011-04-11T12:53:00.000-07:002011-04-11T12:53:53.002-07:00Checkpoint April 11Things Accomplished Thus Far...<br />
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Find a base project, which has a few static objects, cascade shadow mapping, and PCF implemented already</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Added more objects 400, 265 triangle birds</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Animated the birds</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Added FPS counter</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Added a way to toggle on and off, cascade shadow mapping.</span></span></div><div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.4in; margin-top: 3pt; text-align: left; text-indent: -0.28in; unicode-bidi: embed; vertical-align: baseline;"><span style="font-size: x-small;"><span><span style="color: #a04da3; font-family: Georgia;">•</span></span><span style="color: black; font-family: Georgia;">Made some FPS comparisons</span></span></div><br />
High Priority Items:<br />
Variance Shadow Mapping<br />
Perspective Shadow Mapping<br />
Most efficient algorithm possible for the scene<br />
-Baking shadows in for static objects via light maps<br />
-Simple shadow volumes with cylinder for each animate-able object<br />
-Very low resolution single shadow map<br />
<br />
Pic of Demo thus far...<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://www.stuartsummerfield.com/Checkpoint.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://www.stuartsummerfield.com/Checkpoint.jpg" width="320" /></a></div><br />
<br />
<br />
<br />
Video of Demo thus far:<br />
<a href="http://www.stuartsummerfield.com/Checkpoint.mp4">http://www.stuartsummerfield.com/Checkpoint.mp4</a><br />
Checkpoint Presentation:<br />
<a href="http://www.stuartsummerfield.com/Checkpoint.ppt">http://www.stuartsummerfield.com/Checkpoint.ppt</a>slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com1tag:blogger.com,1999:blog-6568217151596470877.post-62153782256352032852011-04-06T21:05:00.000-07:002011-04-07T21:15:48.946-07:00Update April 6After doing my presentation on shadows, I discovered it is probably best to use the NVIDIA SDK for Cascade Shadow Mapping as my project base. I just need to add a bunch of animate-able objects, then I will implement other shadow rendering techniques, like drop shadows which look worse but perform much better than the current shadow map implementation. Pic of the Demo:<br />
<br />
<a href="http://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps_large.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps_large.png" width="320" /></a><br />
<br />
My presentation on various rendering techniques can be downloaded here<br />
<a href="http://www.stuartsummerfield.com/Shadows.mp4">http://www.stuartsummerfield.com/Shadows.mp4</a><br />
Alternatively you can get just the slides<br />
<a href="http://www.stuartsummerfield.com/Shadows.ppt">http://www.stuartsummerfield.com/Shadows.ppt</a><br />
<br />
A short video of the Nvidia Cascade Shadow Mapping demo is included near the end of the presentation.slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com1tag:blogger.com,1999:blog-6568217151596470877.post-16716718599279182612011-03-30T19:59:00.000-07:002011-03-30T19:59:43.873-07:00Seeking good base project(s)<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div>The search continues for a decent project to serve as the base for my various shadow implementations. Ideally I would not like to have to do all the work to make a scene graph instantiating 100+ 3d models that move around in a non-trivial static environment. I have emailed the creator of the iterinix engine for crowd simulation, hoping to get a basic version sent to me as source code, if not I'll have to do some more searching or make my own scenegraph. This YouTube video shows the IterInix engine, which is something similar to what I'm lookng for.<br />
<div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/Q8ujm8Sw5l8?feature=player_embedded' frameborder='0'></iframe></div>I will begin to do most of the research for my Shadows presentation on Monday in the next few days. The search process might end or be expedited by the time I finish the research and presentation on Monday. That is all for this week, stay tuned!slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com1tag:blogger.com,1999:blog-6568217151596470877.post-91667634211615087962011-03-23T11:01:00.000-07:002011-03-25T08:34:58.295-07:00Project ProposalThe project proposal on shadows was submitted and approved! The next step must be to acquire one or more visual studio projects with 100ish moving characters with a shadow map and/or shadow volume implementation.<br />
<br />
Proposal-<br />
<br />
<div class="MsoNormalCxSpFirst" style="line-height: 150%;"> The goal of this project is to reduce performance implications for shadow rendering. The need arises from the fact that many games’ shadow rendering methods result in too large of an FPS decrease for users to even bother using. Most conventional shadow rendering is done by a technique known as shadow volumes. Volumes are constructed using silhouette edges and rendered into a stencil buffer. This is repeated for each light source and the resulting images are combined to form a final frame, a process called multi-pass rendering. This idea is by no means novel and has been used for decades with various optimizations and tweaks increasing performance over the years. This technique is slow because it requires many passes and shadow volume construction which consists of quickly finding silhouette edges, usually stored as additional information in the vertex buffer, and must be transformed to infinity.</div><div class="MsoNormalCxSpMiddle" style="line-height: 150%;"><br />
The first step of the project will be to attain a visual studio C++ project that consists of a scene with several moving objects illuminated by one or more point light sources. This project will have the option of turning shadows on which will use a conventional shadow rendering technique. Turning shadows on will reduce FPS from say 60 to 40. The goal of the project will be to be able to turn on an additional, perhaps less physically accurate shadow rendering mode which results in a non noticeable drop in FPS. One idea that might attain the goal of this project is to render shadows as a post processing effect. Inspired by screen space ambient occlusion, I propose gathering randomly distributed occlusion samples that lie within a cone from the sample point to each light source. Determining the number of points in the cone that occlude the sample point and weighting them in different ways might be a way to estimate whether the point should be in shadow. An additional technique that I have seen in some games is to render shadows quickly on a large number of objects is to use drop shadows. I have still noticed a significant performance impact in using simple drop shadows, although much less worse so than using regular shadows. Since drop shadows are simple dark circles underneath each object, it should be a simple matter of doing drop shadows as a post processing effect on the GPU. Regardless of the method, I firmly believe there should be a way to render shadows or at last an approximation with absolutely no performance hit. This project will attempt to discover and implement that method in a scene with many dynamically moving objects.</div>slstuarthttp://www.blogger.com/profile/18411770579446599314noreply@blogger.com0