• 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
gboxentertainment

[Solved] Deferred Rendered Spotlight Problem

4 posts in this topic

Hello,

I've been trying to implement a simple deferred shader with a spotlight.

The original forward rendered image looks like this:

[url="http://img35.imageshack.us/i/gbdlight0.jpg/"][img]http://img35.imageshack.us/img35/1221/gbdlight0.th.jpg[/img][/url]

But in my deferred shader, when I transfer the lighting code into the deferred shader, it looks like this:

[url="http://img818.imageshack.us/i/gbdlight1.jpg/"][img]http://img818.imageshack.us/img818/6056/gbdlight1.th.jpg[/img][/url]

Here is the normal and position buffers I use - both normalized:

[url="http://img833.imageshack.us/i/gbdlight2.jpg/"][img]http://img833.imageshack.us/img833/4922/gbdlight2.th.jpg[/img][/url]
[url="http://img411.imageshack.us/i/gbdlight3.jpg/"][img]http://img411.imageshack.us/img411/4745/gbdlight3.th.jpg[/img][/url]

The code for GBuffer.hlsl:

[CODE]
#pragma pack_matrix(row_major)
Texture2D Map : register(t0);

cbuffer Matrix : register(b0)
{
matrix world;
matrix view;
matrix proj;
};

SamplerState TextureSampler
{
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Wrap;
AddressV = Wrap;
};

struct VS_IN
{
float4 pos : POSITION;
float3 normal : NORMAL;
float2 tex0 : TEXCOORD;
};

struct PS_IN
{
float4 pos : SV_POSITION;
float2 tex0 : TEXCOORD0;
float3 normal : TEXCOORD1;
float4 worldPos : TEXCOORD2;
};

PS_IN VS_Effect(VS_IN vertex)
{
PS_IN vsOut = ( PS_IN )0;
float4 posWorld = mul(vertex.pos, world);
float4 viewPos = mul(posWorld, view );
vsOut.pos = mul(viewPos, proj );
vsOut.tex0 = vertex.tex0;
vsOut.normal = normalize(mul(vertex.normal, (float3x3)world));
vsOut.worldPos = posWorld;
return vsOut;
}

float4 PS_Color(PS_IN input) : SV_TARGET
{
float4 color = float4(0,0,0,0);
float4 texMap = Map.Sample(TextureSampler, input.tex0);
color = texMap;
return color;
}

float4 PS_Normal(PS_IN input) : SV_TARGET
{
float4 normal = float4(input.normal, 1);
return normal;
}

float4 PS_WorldPos(PS_IN input) : SV_TARGET
{
float4 color = normalize(input.worldPos);
return color;
}
[/CODE]

The code for Combined.hlsl:

[CODE]
#pragma pack_matrix(row_major)

Texture2D ColorMap : register(t0);
Texture2D NormalMap : register(t1);
Texture2D WorldPosMap : register(t2);

cbuffer Light : register(b0)
{
float4 lightPos;
float4 lightDir;
float4 lightColor;
float lightRad;
float lightInt;
};

cbuffer Param : register(b1)
{
float4 camPos;
float4 diffColor;
};

SamplerState TextureSampler
{
Filter = MIN_MAG_MIP_POINT;
AddressU = Wrap;
AddressV = Wrap;
};

struct VS_IN
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD;
};

struct PS_IN
{
float4 pos : SV_POSITION;
float2 tex0 : TEXCOORD;
};

PS_IN VS_Effect(uint id: SV_VertexID)
{
// form a full-screen triangle
float2 pos = float2(id == 1 ? 2 : 0, id == 2 ? 2 : 0);
PS_IN output;
output.pos = float4(pos.x * 2 - 1, 1 - pos.y * 2, 0, 1);
output.tex0 = pos.xy;
return output;
}

float4 PS_Effect(PS_IN input) : SV_TARGET
{
float4 color = {0,0,0,0};
float4 colorMap = ColorMap.Sample(TextureSampler, input.tex0);
float4 normal = normalize(NormalMap.Sample(TextureSampler, input.tex0));
float4 worldPos = WorldPosMap.Sample(TextureSampler, input.tex0);

float4 L = normalize(lightPos - worldPos);
float4 D = normalize(lightDir);
if(dot(-L, D) > 0.9f)
{
float4 N = normal;
float lambertTerm = max(dot(N,L), 0);

if(lambertTerm > 0)
{
color += colorMap*lightColor*diffColor*lambertTerm;
}
}
return color;
}
[/CODE]

What am I doing wrong? Edited by gboxentertainment
0

Share this post


Link to post
Share on other sites
Okay, I've figured out what the problem was.

I used my quad texture format for the textures that I rendered for normals and world position:

DXGI_FORMAT_R8G8B8A8_UNORM

This format clamped my values to [0,1].

I have changed the format to:

DXGI_FORMAT_R16G16B16A16_FLOAT

Which doesn't clamp my values. It uses twice the amount of memory (about 14mb additional for 1280x720 image), but I guess its a sacrifice I'll have to make. Unless someone can suggest a more efficient format? Or more efficient way of getting my normal and position buffers?
0

Share this post


Link to post
Share on other sites
Just map your normal components so they fit in (0,1) ... add 1, multiply by 0.5.

Then reverse the mapping when your reading the data.
1

Share this post


Link to post
Share on other sites
[quote name='phil_t' timestamp='1345406791' post='4971197']
Just map your normal components so they fit in (0,1) ... add 1, multiply by 0.5.

Then reverse the mapping when your reading the data.
[/quote]

Thank you - now I understand why my normals look different to a lot of other developer's normals.

Is it a similar thing for mapping my world coordinates? Except does it involve taking the maximum scene boundaries?
0

Share this post


Link to post
Share on other sites
Storing normals as XYZ in an 8-bit texture will give you pretty poor results, unless you do [url="http://sebh-blog.blogspot.com/2010/08/cryteks-best-fit-normals.html"]some magic[/url] to remap the normals. Even 10-bit formats generally won't give you enough precision for specular lighting. However there are various methods for [url="http://aras-p.info/texts/CompactNormalStorage.html"]packing normals[/url] that can give better results.

As for position...don't bother storing position in a texture. Just [url="http://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/"]reconstruct it from your depth buffer[/url]. It will give you better precision, and you won't have to waste another G-Buffer texture on it.
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