XNA Creators Club Online
Page 1 of 1 (18 items)
Sort Posts: Previous Next

Lighting

Last post 09/07/2009 12:52 by Gooni. 17 replies.
  • 22/10/2008 15:08

    Lighting

    My game is really coming along now with all the help I've gotten! However, now I want to change the way the game looks. I don't like the way the BasicEffect.EnableDefaultLighting lights my stuff. It looks too washed out, and even when I assign colors via Effect.Diffusive/EmissiveColor, there's still this bright spot on all my models. Is there a way I can light it so it looks more even? Maybe use shaders to accomplish this? Also, I'd like some transparency in some models, though effect.Alpha doesn't work the way I thought it would. I couldn't find any tutorials on lighting, either.

    Thanks!

  • 22/10/2008 16:30 In reply to

    Re: Lighting

    i'd be interested in the answer to this. quite a few beginners, myself included, are running into the BasicEffect Effect with bright hot white shading at certain angles of the model. as you say, you can tweak the diffuse/spec stuff but it is a hack. us mere mortals don't really get shaders and want the BasicEffect to work harder for us right? ;) i also found that applying a texture to the model with appropriate brightness can help the problem. i'd love to see a NotSoBasicButNotRockHardEffect class to be honest to prolong me having to learn shaders. as for transparency you need to set a rendertarget flag first to enable Alpha.
  • 22/10/2008 16:34 In reply to

    Re: Lighting

    The directional lighting model used by BasicEffect is pretty flexible - you can get many different visual styles by adjusting the light directions, colors, specular, ambient, etc. See here. You get even more flexibility by implementing your own lighting model in a custom shader, though - it all really depends on what you are trying to achieve.
    XNA Framework Developer - blog - homepage
  • 22/10/2008 16:36 In reply to

    Re: Lighting

    adcworks:
    as you say, you can tweak the diffuse/spec stuff but it is a hack.

    That's not a hack - it's a totally sensible way of adjusting the lighting! BasicEffect provides a lot of knobs, and it does so for a reason. This is the standard blinn/phong lighting model used by pretty much every game ever made, and you can get a huge range of lighting styles by tweaking it differently.

    adcworks:
    i'd love to see a NotSoBasicButNotRockHardEffect class to be honest to prolong me having to learn shaders

    I'm curious what kind of things you would want this shader to do?

    XNA Framework Developer - blog - homepage
  • 22/10/2008 17:34 In reply to

    Re: Lighting

    Note that Emissive will generally cause lighting to be washed out, because it just adds to each of the color channels, without any concern for object shape or light location. Similarly, a high Ambient setting will also just add a lot to the color channels, which will push it towards gray/white.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 23/10/2008 13:17 In reply to

    Re: Lighting

    Shawn Hargreaves:
    adcworks:
    as you say, you can tweak the diffuse/spec stuff but it is a hack.

    That's not a hack - it's a totally sensible way of adjusting the lighting! BasicEffect provides a lot of knobs, and it does so for a reason. This is the standard blinn/phong lighting model used by pretty much every game ever made, and you can get a huge range of lighting styles by tweaking it differently.

    adcworks:
    i'd love to see a NotSoBasicButNotRockHardEffect class to be honest to prolong me having to learn shaders

    I'm curious what kind of things you would want this shader to do?

    alright it's not a hack, but i tweaked those lights quite a lot and never quite got rid of the bright white from certain angles but then again i never tried changing the directions or positions of the lights. as for the shader i'd like to see lots more of what the fbx format exports, such as lights modeled in the 3d software and bump mapping and other texture channels being automatically applied by basiceffect. i'm no expert which is why i am suggesting it would be useful (for me). all this custom model loader, normal compution, bump shader stuff seems unnecessarily repetitive when its all right there in FBX. is there a reason this is not in the basiceffect or built-in fbx importer?
  • 23/10/2008 13:23 In reply to

    Re: Lighting

    That would be really cool, however that would be overkill for the game I'm working on. Right now I just want to evenly light the objects in my game, and add transparency to some of them. How can I do this??? Maybe setting it so that there's only ambient lighting for most/all of the objects would achieve the look I'm going for. If so, how can I do that?
  • 23/10/2008 15:55 In reply to

    Re: Lighting

    adcworks:
    i tweaked those lights quite a lot and never quite got rid of the bright white from certain angles

    My guess is you are getting more specular than you want, but I'd need to see a screenshot to tell for sure.

    The best way to figure out what is going on with a lighting model is to set all the colors to zero, so you get a solid black object. Then experiment with each setting in isolation (ambient, emissive, diffuse, specular, specular power) to get an idea of what it is that they do. Once you've seen the effect of each setting in isolation, you will have a better chance of understanding how to combine them to achieve whatever visual effect you are looking for.

    It is also important to understand which settings work in combinations. For instance specular color and specular power both affect the specular highlight, while diffuse lighting colors are affected both by the material diffuse color and the colors of the light(s).

    adcworks:
    as for the shader i'd like to see lots more of what the fbx format exports, such as lights modeled in the 3d software and bump mapping and other texture channels being automatically applied by basiceffect. [... snip ...] is there a reason this is not in the basiceffect or built-in fbx importer?


    There are a LOT of different ways to do lighting in computer graphics. It would not be feasible for us to implement them all - we would need literally thousands of different shaders, and tens of thousands of adjustable settings. If you are having a hard time learning how to configure the BasicEffect lighting today, imagine how much worse this could get :-)

    For a while, graphics APIs did use a fixed function model where they tried to build lighting in as a direct API primitive. But over time as new features were added, the number of adjustable knobs got out of control. It actually turned out to be much simpler to use a programming language like HLSL to express what kind of lighting you want (which is why programmable shaders were created in the first place). Shaders give you the flexibility to implement exactly whatever combination of features and knobs you need for your particular visual style.

    XNA Framework Developer - blog - homepage
  • 23/10/2008 15:58 In reply to

    Re: Lighting

    ubergeek:
    Right now I just want to evenly light the objects in my game, and add transparency to some of them. How can I do this??? Maybe setting it so that there's only ambient lighting for most/all of the objects would achieve the look I'm going for. If so, how can I do that?

    Define "evenly"?

    I would be very surprised if BasicEffect cannot do what you are looking for, but you will have to articulate what you want in more detail before I can advise on how to get that result.

    Is your problem with the specular highlights? If so, decrease the specular color, or adjust the specular power.

    Is it the contrast between light and shadow too great? If so, decrease the light colors, and increase the ambient.

    Is the problem where the lights are positioned? If so, move them.

    Is the problem the tint colors EnableDefaultLighting uses to differentiate the key/rim/back lights? If so, change those colors, or make the lighting monochrome.

    You have many options - the first step is to define what your problem is and what end result you are looking for.

    XNA Framework Developer - blog - homepage
  • 24/10/2008 13:05 In reply to

    Re: Lighting

    I've got the models looking how I want. I set the lights to enabled = false. Now they're lit evenly, like I wanted!

    I'm still stuck at how to change the Alpha value, to make them semitransparent. I read earlier that it involves setting a RenderTarget. How do I do that??

    Thanks!

  • 24/10/2008 14:31 In reply to

    Re: Lighting

    Wierdness...

    I've recently added a healthbar system, using a tutorial posted on the Health Bar thread. Now the models render properly, with effect.Alpha actually doing something!! I'm not sure why this is happening, since the only thing that could have affected it is a call to SpriteBatch above the 3D rendering block. Either way, now everything works the way I wanted it to. Finally, a bug that does something positive! :-)

  • 24/10/2008 14:41 In reply to

    Re: Lighting

    Though it seems to have  helped you at the moment, spritebatch will mucky up your scene if you're unaware.. it is the most common XNA pitfall.

    See http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx for clarification, and it will help you understand "renderstates" and how to set them to get the alphablending you want, when you want it.

     

    http://blogs.msdn.com/etayrien/archive/2006/12/07/alpha-blending-part-1.aspx  Is also a must-read.

    Best,

    Byron

    ..shaders make you feel... powerful, or very very stupid.
    http://drjbn.spaces.live.com/
  • 24/10/2008 14:48 In reply to

    Re: Lighting

    Ummm.... that introduced another bug, and the fix broke the bug that fixed the original problem. :-( Let me explain:

    If I leave the call to spriteBatch and the drawing method for the healthbar at the beginning of Draw(), then the healthbar appears behind the level geometry in some situations (bad), but the geometry renders with alpha transparency (good). If I move the spriteBatch draws to the bottom of the Draw() method (after rendering geometry), then the healthbar appears on top (good), but the geometry has no alpha (bad). :-( If I try to fake it out by placing two calls to spriteBatch at the beginning and end of Draw(), then the healthbar draws, but the geometry still has no alpha.

    What can I do to fix this?

    Thanks!

    [edit]

    Whoops, I took a bit long writing that!! Thanks, that should help!

  • 24/10/2008 14:58 In reply to

    Re: Lighting

    Okay, I read those. That cleared a few things up! :-)

    But it left out a few things.

    1) Should I render the 2D elements (HUD, etc) BEFORE the 3D models, or AFTER the 3D stuff?

    2) Should I reset the RenderState before drawing 3D stuff, or after drawing 2D stuff, or does that matter?

  • 24/10/2008 15:03 In reply to

    Re: Lighting

    Never mind! After toying with the settings and placement for a while, I finally got everything working correctly!!! :-)

    In the Draw() method, I reset the RenderState, rendered the 3D objects, and then drew the HUD, in that order. That fixed everything! 

    Thanks for all your help!!!

  • 08/07/2009 9:55 In reply to

    Re: Lighting

    Shawn Hargreaves:
    Is your problem with the specular highlights? If so, decrease the specular color, or adjust the specular power.

    Is it the contrast between light and shadow too great? If so, decrease the light colors, and increase the ambient.

    Is the problem where the lights are positioned? If so, move them.

    Is the problem the tint colors EnableDefaultLighting uses to differentiate the key/rim/back lights? If so, change those colors, or make the lighting monochrome.

    More of that!!!!!

    Seriously: Is there any resource on the net that provides you with a better idea about lighting with BasicEffect?

    I read the lighting part of your blog, Mr. Hargreaves, but it only covers directional lights and specular colors.

    I also had a look at the basicEffect how-to which provides a good starting point for playing around with some values.

    But: I can't find an exhaustive explanation of all the material and lighting parameters of basicEffect.

    E.g.

    - what is the difference between emissiveColor and diffuseColor?

    - Why is there - besides the material parameter "SpecularColor" - a SpecularColor value for each single directional light?

  • 09/07/2009 1:38 In reply to

    Re: Lighting

    Seriously, at some point you have to know the area you're working with. The XNA documentation can't be a full tutorial on linear algebra, and I think it also cannot be a full tutorial on 3D graphics. (Although your questions are actually answered in the Direct3D documentation on MSDN...)

    In brief: Diffuse color is affected by the light. Emissive color is added to the output color after all other calculations are done. Specular colors per light mean that different lights can have differently-colored highlights (you can use this to tone down the highlights from a particular light).

    And go read up on 3D graphics basics in general if you want to actually do 3D graphics work! Seriously. The MSDN documentation for BasicEffect might be a good starting place (not the "see also" section). I typed in "BasicEffect DiffuseColor" into the MSDN search bar, and that was the first hit...



    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 09/07/2009 12:52 In reply to

    Re: Lighting

    jwatte:
    Although your questions are actually answered in the Direct3D documentation on MSDN...

    Thanks! That's exactly what I was looking for.
Page 1 of 1 (18 items) Previous Next