• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
LevyDee

Multiple light sources

9 posts in this topic

Using shadow mapping, it is easy enough to get a depth map for each light source you may have, but I am seeing difficulty in figuring out, for example, 5 different light sources, and using there associated depth maps to draw the scene. It seems google is falling short on this subject. Everything about shadow mapping is on theory, or creating a single light source! any ideas guys?
0

Share this post


Link to post
Share on other sites
Could you give an "in a nutshell" explanation? In the mean time I will look into that.
0

Share this post


Link to post
Share on other sites
Well, you basically need to find the color that it would be for each single light and add them together.
0

Share this post


Link to post
Share on other sites
Well, you basically need to find the color that it would be for each single light and add them together.
0

Share this post


Link to post
So I did a some research into deferred lighting, and I have some questions(obviously!). So the first step is to create a G-Buffer. So the term "G-Buffer" is simply a term that was coined to describe a geometry buffer with no lighting applied correct? Its not some sort of render target I am unaware of? So anyways, the g buffer is supposed to hold the vert position, color, normal ect... But here lies my first problem. The only semantics that are supported by pixel shaders are COLORn and DEPTHn. COLORn is float4, so I guess you could hold most of your information in that, but is this the correct way to accomplish this? Am I thinking about the process correctly?

Step 1: draw scene like normal with no lighting applied(easy), but instead of only putting out color(like normal), include vector position and normal(what????!?!?!?).
There is no support for this as far as I am aware.

Please and thank you for any help!
0

Share this post


Link to post
Share on other sites
The G-Buffer is just a name for a collection of regular render targets/FBOs. You store normals and positions in color buffers, although for best results you usually want to bump the bpp of the buffers. (for instance, use GL_RGB32F) for position. To do deferred rendering youll pretty much need to use shaders. Then, you'd create color, normal, position, and depth buffers and bind them to the framebuffer, and render your scene to them (fragment shader):
[CODE]
out vec4 outputColor[8];
void main()
{
outputColor[0]=texture2D(textures[0],uv[0]);
if(outputColor[0].a<.01)
discard;
outputColor[1]=vec4(Normal,1);
outputColor[2]=vec4(Position,1);
}
[/CODE]
This would save the texture (diffuse/albedo) to the first FBO in the framebuffer, the normal to the second, etc.
Then you can easily do multipass algorithims by just drawing a fullscreen quad (processing each pixel in your buffers once) to do lighting, etc
0

Share this post


Link to post
Share on other sites
So after doing some more research and getting a better understanding of the process, here is what I have thus far.

Here is my new main render loop(updating to deferred renderer)
[code]
_d3dDevice->SetRenderTarget(0, colorSurf);
_d3dDevice->SetRenderTarget(1, normSurf);
_d3dDevice->SetRenderTarget(2, depthSurf);

_gBufferFill->SetTechnique("Fill");

_d3dDevice->BeginScene();

//Loop through and draw everything in the world
for(int n = 0; n < _worlds[_views[view].world].Size(); n++)
{
//Set view and projection matrices
if(_gBufferFill>SetMatrix("cView", &_camera->GetViewViewMatrix(view)) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to set View Matrix!", __FILE__, __LINE__);

if(_gBufferFill->SetMatrix("cProj", &_camera->GetViewProjectionMatrix(view)) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to set Projection Matrix!", __FILE__, __LINE__);

//Draw the item
_worlds[_views[view].world][n]->GBufferDraw(_d3dDevice, &_gBufferFill);

//Kill object if requested to
if(_worlds[_views[view].world][n]->GetKill())
_worlds[_views[view].world].Free(n);
}

_d3dDevice->EndScene();
[/code]

This is my effect to fill a gbuffer
[code]
//GBuffer MRT order-
//1 - Color
//2 - Normal
//3 - Depth
//Bit depth - 32

//Object world
float4x4 oWorld : WORLD;

//Camera view and projection
float4x4 cView : VIEW;
float4x4 cProjection : PROJECTION;

texture objectTexture;

//Object texture sampler
sampler ObjectTexture =
sampler_state
{
Texture = <objectTexture>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};

void vsFill(float4 iPos : POSITION0,
float4 iNorm : NORMAL0,
float2 iUV : TEXCOORD0,
out float4 oPos : POSITION0,
out float4 oNorm : TEXCOORD0,
out float2 oUV : TEXCOORD1,
out float4 oDepth : TEXCOORD2)
{
//Transform vertex position
float4 vWorldPos = mul(iPos, oWorld);
float4 vViewPos = mul(vWorldPos, cView);
oPos = mul(vViewPos, cProjection);

//Get depth
oDepth = oPos.z / oPos.w;

//Get normal into world space
oNorm = mul(iNorm, oWorld);

//Pass uv through to pixel shader
oUV = iUV;
}

void psFill(float4 iNorm : TEXCOORD0,
float2 iUV : TEXCOORD1,
float4 iDepth : TEXCOORD2,
out float4 colorOut : COLOR0,
out float4 normOut : COLOR1,
out float4 depthOut : COLOR2)
{
//Color map
colorOut = tex2D(ObjectTexture, iUV);

//Normal map
//TODO understand what is happening here. Taken from (http://www.catalinzima.com/tutorials/deferred-rendering-in-xna/creating-the-g-buffer/)
normOut.xyz = 0.5f * (normalize(iNorm) + 1.0f);
normOut.w = 1.0f;

//Depth map
depthOut = iDepth;
}

technique Fill
{
pass p0
{
VertexShader = compile vs_2_0 vsFill();
PixelShader = compile ps_2_0 psFill();
}
}
[/code]

And how I use the shader for each object I am drawing(GBufferDraw()):
[code]
//Set texture, translate object and set world matrix
if(gBufferFill->SetTexture("objectTexture", GetActiveTexture()) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to set texture", __FILE__, __LINE__);

//Translate the objects position
D3DXMatrixTranslation(&GetObjectIndependents()->matTranslate, GetDrawLocation()->x, GetDrawLocation()->y, GetDrawLocation()->z);

//Set the world
if(gBufferFill->SetMatrix("oWorld", &(MultiplyIndependents())) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to set World View Matrix!", __FILE__, __LINE__);

UINT numPass;
gBufferFill->Begin(&numPass, 0);

for(unsigned short i = 0; i < numPass; i++)
{
gBufferFill->BeginPass(i);

device->SetStreamSource(0, p_vertexBuffer, 0, sizeof(LWVERTEX));
device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, p_verticeCount / 3);

gBufferFill->EndPass();
}

gBufferFill->End();
[/code]

I cannot seem to get good results to my color, normal, or depth map. I only get all black
0

Share this post


Link to post
Share on other sites
Ok, first, you want to start with just drawing some solid and unique color from the first phase to the color buffer, and then just reading that out and displaying it on your second phase to make sure your rendering to texture is correct. Second, I cant really tell what youre drawing in your second phase. The /3 in the draw call makes me assume youre drawing your model again, however you shouldnt need to. You just need to draw a flat polygon over the entire screen. Drawing your model again *may* work, although its pointless processing. If youre doing that way for a test or something, remember to disable the depth buffer, or add a depth offset so your models arent failing the depth test the second time
0

Share this post


Link to post
Share on other sites
Thank you for sticking around for this long zacaj =). So I solved my last problem in my last post. I wasn't clearing my 3 render targets(doh!).

[quote name='zacaj' timestamp='1330984383' post='4919587']
The /3 in the draw call makes me assume youre drawing your model again, however you shouldnt need to.
[/quote]

The draw method there is being called for individual objects only once.

So anyways, I am getting good gbuffer content now.

Color
[IMG]http://i.imgur.com/JOBk5.jpg[/IMG]

Normal
[IMG]http://i.imgur.com/t82c2.jpg[/IMG]

and Depth
[IMG]http://i.imgur.com/NCWwM.jpg[/IMG]

It is at this point I am kind of lost. Not sure, maybe I haven't gotten to that point in the tutorials yet. I will continue on, and check back here regularly for any words of wisdom you may have for me =)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0