   Advice about lighting technique
  Hello,I'm trying to develop an Obscure's / Fahrenheit's flavour game, in which you can switch between 1st & 3rd person cam, collect items, & follow a plot (no enemies or things like that yet). It's more like a graphic adventure.I'm not a pro in this area & shaders are still a hard subject to me.I am using XNA Animation Component Library (for skinned models) which brings a .fx file for GPU skinning.I managed to adapt it in order to work with a directional light I created in the shaders (with Ambient, Diffuse, Specular & Shinniness).It looks rather pretty to me, but the problem is that evrth is lit or dark & there's an only one omni light. (I'm not expecting to plot 20 lights all together, or Crysis' like things! Something like Obscure is more than good to me!)So i'd really like to implement point lights and/or spotlights.I've read that nowadays many people use deferred rendering. I get the theory but all i can do about practise is using some tutorial's code (& i don't really know how to mix it with the "Skinning" shader).I'm also aware of Antialising, Alpha Blending & SHADOWS problems...So the question is: for the kind of game I'm making & the problems I may face; do u advice me to go (however) into deferred rendering, or to try other techniques?Thank you very very much for your help :)Synth[Edited by - Synthesizer on March 23, 2010 6:23:42 PM]
  Cheat!Best looking lighing comes by using static lightmaps.Lightmaps are not something old and unusable, they are justsimple solution to complex problem. And no you don`t nead dynamicaly calculated lighting on static world :DLightmaps don`t care witch kind of rendering order you are using,it works with normal forward rendering and deferred rendering.Next problem for you is to try to find good lightmapbakeing software / renderer, and after that take sometime to learn basics of cinematography lighting.With lightmaps & basic skills in light usage you can go tolevel of Blade Runner movie./Tyrian   ;Quote:Next problem for you is to try to find good lightmap bakeing software / renderer.Blender can bake lightmaps (sort of).   ;  Hi!Thank u very much 4 ur answers!Well, i'll take a look at light maps, but I'm not sure this will be a real solution as as u say, it's static, & it would be cool for example to pick up a torch :)Though I don't discard your idea (i'll study it a bit) i'd like to know if there are any other options for dynamic lighting & if they really are very complex.What about multipass?Or is deferred rendering the only real path?Any other good technique?The atmosphere I wanna bring is kind like Alone in The Dark (the old one, but with better graphics of course) or the other games i named before.Torchs would be nice as well as street lamps & things like this!Thank you!!   ;  Well, the big secret is that you can mix lightmaps with dynamic lighting.So bake 99% of your city lights to lightmap, and calculate on top,light contribution from one small light that the player is carrying. :)If you have hard time with shaders and basic light models, then I would notrecomend building deferred renderer. (And normal foreward renderer is used indeferred rendering for transparent objects, so you are going to nead one anyway)/Tyrian   ;  Well, first off you have to distinguish between lighting and shadowing. In reality you can't really distinguish between them, but in games (and some movies) lighting and shadowing are really two different techniques. Most of the time it is easier to add some light than to add shadows. It is all about faking reality. The next thing to think about is global illumination and direct illumination. Direct illumination (i.e. a torch) is as important as global illumination. And at last you have to consider to use a certain rendering technique. Deferred vs. forward shading. Deferred shading has some advantages in lighting a scene, but on the other hand has some flaws in other aspects (i.e. transparency).Here are some techniques (still) used nowadays:direct lighting, shadow techniques: - shadowmapping (defacto standard, many different approaches)direct lighting, lighting techniques:- forward rendering vs deferred rendering: with deferred rendering it is easier and generally faster to render lot of dynamic (point) light sources.global illumination:- lightmaps: somewhat old technique, only for static lights/shadows- ambient occlusion: precalculated, "similar" to lightmaps, but could handle dynamic lights much better- ssao(screen space ambient occlusion): dynamic calculation of "faked" ambient occlusion. no need to save extra shadowing information in textures. best done with a deferred rendering engine.Take a look at the udk (unreal engine, take a look at licences), which will provide some of the best lighting/shadowing solutions currently available.For my project I use a deferred rendering engine with SSAO and lot of dynamic pointlights and only one "fake" shadowmap. I want to archieve a "good" lighting/shadowing solution for a very dark underground world.;  Hello,Thanks for the answers!Great info about lighting & shadowing & good point in showing the difference between them :)TyrianFin I like the idea of mixing shadow maps & dynamic lights; i guess I can fake many not-so-important lights while still having 1 or 2 dynamic lights, & that may reduce the GPU usage.From all ur info I get that I may try forward rendering first, & then, if it doesn't satisfy my needs (with forward rendering knowledge acquired) give a try to deferred rendering.Ashaman, ur info is gold! Now I have all the correct terminology & I have already found useful examples of direct lighting :)I've just tried a spotlight & it works very good; i'll put multiple lights & see the results ^^ By the way, ur game looks great!Well, thank you very very much all of u! Thanks for ur time & ur info; i'll try to post some screenshots so u see what i'm working on!Hope to see ya again!Cheers,Synth   ;  Hi guys,just posting to tell u that i managed to write a shader for multiple lights of multiple types in a single pass (forward rendering) :)Here is a pic showing 2 spots (green & white) & 1 point light (red, in the bottom).Feel free to check more pics of the project (from the very start till now) here.I'm very happy with the results!When the 3rd light was added, the frame rate seemed to decrease but I was already awared of this. I'll test the lights in the actual project where I have terrain, more models & real processing! I know that if speed results are terrible I may start thinking about deferred rendering, but I already have advanced a bit so it may be easier than before :)(In case u cannot see the pics -as they are in my Windows Live Space- just tell me, & i'll upload them in another place!)Thanks,Synth   ;  Nice to see that you are getting progress.Little tips:If you are makening renderings of outdoor enviroments,try adding some fog / haze it gives lots of depth to images.Try learning gamma corret working style. (it`s littlebit advanced topic, but ones you get it you are better light worker than 90% of GC industry artists)Basic light rig for outdoors: (not accurate values, mut give guidance)1. mainlight directlight (sun: color light yellow, power 0.9,moon color deep blue/cyan, power 1.7 (night time lighting is little hard))2. skylight directlight on reflection angle to main light.(color opposite color to main light, power half of main light)3. hemisphere ambient light (color light blue/cyan, power 0.3)General notice of light colors: only use light with saturation 0.0 - 0.75.no extreme saturations on lights!When you are testing lights on single model, add ground plane under the model and set backround color to something else than black/white (darkgray is good)/Tyrian   ;  Hello again!Thanks 4 the new advices. The fog sounds like a must now that u say it :) I'll make some research about it.Refering to the colors & their saturation; by saturation u mean intensity? Or better to say "pureness"?Well, i wanna ask u again for advice, but now, related to my current Shaders. They work & look nice (i think there's smth strange in the deferred component, but... well i can live with it).But the thing is I think I have a bottle neck in there. Maybe I'm doing things in the PS that should be done in the VS, but I don't know how to manage them otherwise. Well, maybe u can take a look & give me some hint :) Thank you!// These are required by the Animation library    float4x4 MatrixPalette[56];    float4x4 World;   // These are not    float4x4 View;    float4x4 Projection;    texture BasicTexture; struct Light{int type;float3 direction; // world space directionfloat3 position; // world space positionfloat4 ambientColor;float ambientIntensity;float4 diffuseColor;float diffuseIntensity;float4 specularColor;float specularIntensity;float spotInnerCone;  // spot light inner cone (theta) anglefloat spotOuterCone;  // spot light outer cone (phi) anglefloat radius;    // applies to point and spot lights only};int numberOfLights=1;Light lights[8];    float materialShininess; // Sharpness the specular highlights. Higher number = sharper highlight    float3 CameraPosition;   // Stores sampler state info for the texture    sampler TextureSampler = sampler_state {texture = <BasicTexture> ;    magfilter = LINEAR;    minfilter = LINEAR;    mipfilter= LINEAR;    AddressU = WRAP;    AddressV = WRAP;};   // This is passed into our vertex shader from Xna    struct VS_INPUT    {  // This is the position of the vertex in the model file    float4 position : POSITION;  // The vertex normal    float3 normal : NORMAL0;   // This is the texture coordinate for the vertex in the model file    float2 texcoord : TEXCOORD0;   // These are the indices (4 of them) that index the bones that affect   // this vertex.  The indices refer to the MatrixPalette.    half4 indices : BLENDINDICES0;   // These are the weights (4 of them) that determine how much each bone   // affects this vertex.    float4 weights : BLENDWEIGHT0;    };   // This is passed out from our vertex shader once we have processed the input    struct VS_OUTPUT    {  // The final position of the vertex in world space    float4 position : POSITION;   // The texture coordinate associated with the vertex    float3 normal: TEXCOORD0;    float3 cameraView : TEXCOORD1;    float2 texcoord : TEXCOORD2;    float4 position3d : TEXCOORD3;   //float3 lightDirection : TEXCOORD3;    //float3 spotDirection : TEXCOORD4;    };float4 getPointLightColor(Light light,float3 cameraView,float4 worldPosition, float3 normal){float attenuation;float2 cosAngles;float3 halfAngle;float3 lightDir;float specular;float4 ambient;float diffuse;lightDir = (light.position - worldPosition)/light.radius;attenuation = saturate(1.0f - dot(lightDir, lightDir));cosAngles = cos(float2(light.spotOuterCone, light.spotInnerCone) * 0.5f);halfAngle = normalize( normalize( light.direction ) + cameraView );specular = pow( saturate( dot( normal, halfAngle ) ), materialShininess ) * light.specularColor * light.specularIntensity * attenuation;diffuse = max(dot(normal, normalize(lightDir)), 0) * light.diffuseIntensity * light.diffuseColor * attenuation;ambient = light.ambientIntensity * light.ambientColor * attenuation;return(ambient+diffuse+specular);}    VS_OUTPUT MultipleLightsVS( VS_INPUT input )    {   VS_OUTPUT output; float4 worldPosition = mul( input.position, World );   float4 viewPosition = mul( worldPosition, View );   output.position = mul( viewPosition, Projection );output.position3d=input.position;output.normal = normalize(mul( input.normal,(float3x3)World));   output.cameraView = normalize( CameraPosition - worldPosition ); // Just pass the texture coordinates to the vertex shader output.   // When they transfer to the pixel shader, they will be interpolated per pixel.   output.texcoord = input.texcoord;   //output.lightDirection = output.cameraView;//output.spotDirection=light.direction;   return(output);    };   float4 MultipleLightsPS(VS_OUTPUT input ) : COLOR0    {   float4 worldPosition = mul( input.position3d, World );float4 totalColor=float4(0,0,0,1);for(int x=0;x<numberOfLights;x++){if(lights[x].type==1){totalColor+=getDirectionalLightColor(lights[x],input.cameraView,worldPosition,input.normal);}else{if(lights[x].type==2){totalColor+=getPointLightColor(lights[x],input.cameraView,worldPosition,input.normal);}else{totalColor+=getSpotLightColor(lights[x],input.cameraView,worldPosition,input.normal);}}    }return(totalColor* tex2D(TextureSampler, input.texcoord));    }    technique MultipleLightsTechnique    {pass P0{VertexShader = compile vs_3_0 MultipleLightsVS();    PixelShader  = compile ps_3_0 MultipleLightsPS();}    }There is another VS only used for animated models (with skin stuff) but does basically the same adding the skinning stuff.(I didn't include the getDirectionalLightColor & the one for spot as they are similar).Any idea? Thanks a lot! :)   