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

Multiple point lights, shaders.

1 post in this topic

Currently using a point light shader that fits my game perfect but It would be nice It I could have more than 1 point light on the scene at one time. I've tired to look at other examples at how they do it but none seem to look anything like my shader, so some advice would be appreciated!

Here is the shader I'm using now.

[CODE]
//////////////////////////////////////////////////////////////////////////////////////////////////
// File: ParallaxMapPointLight.fx
// Author: Chris Smith
// Date Created: 12/17/06
// Description: Renders a scene with parallax mapping from a point light
// Disclaimer: Use this however you want, but I am not responsible for anything
//////////////////////////////////////////////////////////////////////////////////////////////////
float4x4 WorldViewProj; //World * View * Projection Matrix
float4x4 World; //World matrix of object
float4 EyePos; //Position of eye in world space
float4 LightPos; //Light position in world space
float4 LightColor; //Color of the light
texture ColorMap; //Color texture
texture NormalMap; //Normal map texture
texture HeightMap; //Height map texture
float Falloff; // Distance until light begins to falloff
float Ambient; // Ambient amount of lighting
float DepthScale = 0.04f; //Depth of the parallax map
float Bias = 0.02f; //Bias of the parallax map
float scale;
sampler colorSampler = sampler_state
{
Texture = (ColorMap);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler normalSampler = sampler_state
{
Texture = (NormalMap);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler heightSampler = sampler_state
{
Texture = (HeightMap);
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
//////////////////////////////////////////////////////////////
//Structures
//////////////////////////////////////////////////////////////
//Application to vertex shader
struct A2V
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoord0 : TEXCOORD0;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
};
//Vertex shader to pixel shader
struct V2P
{
float4 Position : POSITION;
float2 TexCoord0 : TEXCOORD0;
float3 LightDir : TEXCOORD1;
float3 ViewDir : TEXCOORD2;
};
//////////////////////////////////////////////////////////////
//Vertex Shader
//////////////////////////////////////////////////////////////
void VS( in A2V IN, out V2P OUT )
{
IN.Position.xyz *= scale;
//Transform the position from view space to homogeneous projection space
OUT.Position = mul(IN.Position, WorldViewProj);
//Compute world space position
float4 WorldPos = mul(IN.Position, World);

//Calculate Binormal and set Tangent Binormal and Normal matrix
float3x3 TBNMatrix = mul(float3x3(IN.Binormal, IN.Tangent , IN.Normal), (float3x3)World);
//Compute light direction
OUT.LightDir = LightPos - WorldPos;
//Compute light direction * TBN Matrix
OUT.LightDir = mul(TBNMatrix, OUT.LightDir);

//Compute view direction * TBN Matrix
OUT.ViewDir = mul(TBNMatrix, EyePos - WorldPos);

//Copy the texture coordinate as is
OUT.TexCoord0 = IN.TexCoord0;
}
//////////////////////////////////////////////////////////////
//Pixel Shader
//////////////////////////////////////////////////////////////
float4 PS( in V2P IN ) : COLOR0
{
IN.ViewDir = normalize(IN.ViewDir);

//Determine the height of this pixel
float Height = DepthScale * tex2D(heightSampler, IN.TexCoord0) - Bias;

//Compute the new texture coorddinate to use
float2 TexCorrected = Height * IN.ViewDir + IN.TexCoord0;

//calculate the color and the normal
float4 Color = tex2D(colorSampler, TexCorrected);
//Uncompress the normal map
float3 Normal = 2.0f * tex2D(normalSampler, TexCorrected).rgb - 1.0f;
//Pixel to light vector
float LenSq = dot( IN.LightDir, IN.LightDir );
IN.LightDir = normalize( IN.LightDir );

//Compute the light's attenuation
float Attn = min(( Falloff * Falloff ) / LenSq, 1.0f);
//Compute the diffuse lighting amount
float Diffuse = Attn * saturate(dot(Normal, IN.LightDir));
//Lighting amount * Texture Color * Light Color
return Color = (Diffuse + Ambient) * Color * LightColor;
}
//////////////////////////////////////////////////////////////
//Technique
//////////////////////////////////////////////////////////////
technique ParallaxMapPointLight
{
pass p0
{
vertexshader = compile vs_2_0 VS();
pixelshader = compile ps_2_0 PS();
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites
This is an old problem that has many solutions. Some are:[list=1]
[*]Let’s say that you know the engine needs in several scenarios three point lights and one point light in others. You could implement a technique for three point lights and one for one point light and you switch to whatever you need.
[*]I think Unreal uses a multi pass shader. I suppose they use additive blending.
[*]Deferred renderers. My favorite!!! You can render the points lights you need. 100? Ok, you have it and with a very good performance. The problem is that you have to re implement all your pipeline [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
[/list]
If you only ask how to add the second point light to your shader, just calculate a second LightDir in your vertex shader (with the second point light position) and add the diffuse result of the second light to the diffuse result of the first.

And try to work in linear space: [url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html"]http://http.develope...gems3_ch24.html[/url]

Bye!!!
1

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