Sign in to follow this  
greenpig83

[FFP] Lighting for terrain so dull (dark)

Recommended Posts

greenpig83    330

Hi,

    I'm working with an tile based terrain. The terrain is display in an isometric view. I try to limit myself to FFP because I want to target low system computers. The problem is that I tried so many light direction, the world light is so dull. The maximum bright (the surface face the light ? ) is the current texture color. Every other surface look darker. I think the surface that direct the light should get brighter than it's normal texture color! How can I achieve it with old FFP ?
I want to achieve the flat terrain surface should get lit 100% (normal texture color). the slope face the light should get brighter, the other slopes should get darker!

sc3_zps386ada13.png

(same normal for 1 Triangle)

 

sc4_zps228f11e0.png

(Each vertex have its own Normal -  the edge look smooth, but the lighting even darker!)

 

Original Texture : 

15030_zps7e49cc20.png

Edited by greenpig83

Share this post


Link to post
Share on other sites
Tom KQT    1704

I haven't worked with the FFP for a while, so I did a quick test now and it seems that the FFP lighting will never (*) produce enough light for the surface to get brighter than its normal texture color at 100 % intensity. It's quite weird, but even if you combine full while (0xFFFFFFFF) ambient color with as many directional lights shining at the surface from the same direction as you want, you will never get anything brighter than the original texture color. Also emissive color of the material doesn't help.

Maybe there are some combinations in SetTextureStageState that would change it, but I honestly don't know.

 

If you don't manage to get the desired look by playing with ambient and diffuse colors, you will probably have to use shaders. I don't think that would be such a problem with low-end computers. Well, yea, you would increase your HW requirements to GCs supporting shaders.

 

 

(*) The only exception seems to be specular colors, those (of course) get added "on top" of the diffuse and ambient lighting. But I don't think specular would work in your case (ortho view, directional lights, flat terrain).

Edited by Tom KQT

Share this post


Link to post
Share on other sites
Steve_Segreto    2080

It's quite weird, but even if you combine full while (0xFFFFFFFF) ambient color with as many directional lights shining at the surface from the same direction as you want, you will never get anything brighter than the original texture color.

 

That's because the operation is a modulation, which is just a multiply. So multiply original color by 1 and you get the original color, anything less and you get a darker color. if you use an additive operation instead, you can exceed the original color, but not exceed 1.0f.

 

If you want to go beyond that you can look at high dynamic range lighting and/or SRGB correction.

Share this post


Link to post
Share on other sites
C0lumbo    4411

Your problem is that you can never achieve an output colour brighter than the original texture with your current setup.

 

The solution is colour doubling/quadrupling. Look into using D3DTOP_MODULATE2X and D3DTOP_MODULATE4X and halfing/quartering the light brightness to compensate.

Share this post


Link to post
Share on other sites
greenpig83    330

Yeah I tried to mess with the Lighting setting, Material setting... ambient,emission,specular... It does make it lighter, but never supass the texture real color.
It seem the only solution is to use Multi Texture, using ColorOp = Modulate2x or 4x. It does make thing brighter, how ever it require a lightMap.

This guy seem to solve my problem in his way. Not perfect but I think acceptable : http://age.hys.cz/viewtopic.php?f=5&t=2

15_2D_elevation_small.png

 

In his post, it seems he does use a lightMap, then modulate the slope surface with it : 

elevation_matrix.png

I tries to use his but it not very easy. Cause I'm not sure this is his real lightMap or just a demo, the gray value is not the same in all edge. because we only apply the lightMap to the sloped surface, flat surface surround it is intact. so that the Border must have the same gray value! Although this look quite right, the black region mean the surface need darkening, the white region mean it should be brighter. The gray mean we keep it as normal texture color! Still very headache.

 

The reason I want to use FFP, because this is just a 2D project using DirectX3D. Also I does use vertex,lighting, multiTexture. Still wonder if 5 year old laptop with integrated card support multi texture 3 stage :(

Edited by greenpig83

Share this post


Link to post
Share on other sites
C0lumbo    4411

Use D3DTOP_MODULATE2X/D3DTOP_MODULATE4X on the texture stage state that combines your dynamic lighting result with your texture result to get the overbrightening effect that you want.

 

The feature does not require your lighting to come from a texture (light map) like you state in your last post.
 

Share this post


Link to post
Share on other sites
Tom KQT    1704

It's quite weird, but even if you combine full while (0xFFFFFFFF) ambient color with as many directional lights shining at the surface from the same direction as you want, you will never get anything brighter than the original texture color.

 

That's because the operation is a modulation, which is just a multiply. So multiply original color by 1 and you get the original color, anything less and you get a darker color. if you use an additive operation instead, you can exceed the original color, but not exceed 1.0f.

 

If you want to go beyond that you can look at high dynamic range lighting and/or SRGB correction.

Modulation between diffuse color of the light and diffuse color of the material, similarly for ambient etc. Yes, that will never go above 1.

But then the lights are summed together (Ambient Light + Diffuse Light + Specular Light + Emissive Light) and there really must be addition, because with modulation you would get complete black look for any material without emissive color, which is not how it really works. And also - what about multiple lights? Their results also cannot be modulated, they must be added together.

It just seems that FFP is adding the lights together, while never going above 1 (clipping the result to 1). So if one light was enough to get to 1, then all other light sources have no effect.

Edited by Tom KQT

Share this post


Link to post
Share on other sites
kauna    2922

Just a little reality check when you say that you want to limit yourself to FFP because you want to target "low-end" machines. 

 

Direct3D 9.0 was released year 2002 ... that's over 10 years now. It supports shader model 3.0 already.

Direct3D 8.1 was released year 2001 and it supports some shader level already and it doesn't work on anything older than Windows XP.

 

http://store.steampowered.com/hwsurvey/

 

Above is the Steam hardware survey. People using hardware with DX8 level GPU (some or none shader support) and below presents 0.41% of the Steam gamers. On the other hand 98.54% of the people using Steam have access to SM3.0 level hardware. 

 

Cheers!

Share this post


Link to post
Share on other sites
VladR    722

You seem to want to get a high-contrast lighting. It is entirely possible to achieve using just FFP.

 

This is one of the best attempts of mine from the old days of DX 8 to achieve this goal:

I had:

- Shadows (prebaked in lightmap)

- Regular Diffuse + Ambient light

- High-intensity highlights for triangles under certain angle

- Material map blended with procedurally generated texture map

ScreenShotJune003.jpg

 

ScreenShotJune004.jpg

 

Obviously, I don't remember the exact combination of the TSS after all these years, but I remember very clearly that I had to use MULTIPLY_2X AND MULTIPLY_4X to achieve this, in combination with one of those states that let you specify if you want to saturate the result or clamp it.

 

Of course, if you already have a lot of (1.0f,1.0f,1.0f) colors in your base texture map, that is not going to get you anywhere, since no matter how you mulitply the 1.0f, you will still get 1.0f at most.
 

 

Thus, the trick is to make the majority of the scene darker, so that only certain parts get brighter - in my case, I wanted to achieve the dynamic light with the time-of-day feature, thus the terrain was dynamically lighted throughout whole day with varied direction of the light.

 

It is a lot of tweaking, though. You need to be able to dynamically, at run-time, change the intensity of Directional and Ambient RGB, either through key shortcuts or some UI.

 

It does take few hrs to come with the final look, but it is totally worth it.

 

 

To summarize, you need:

- A profile system where you keep good combinations in a code so that you don't have to spend half an hour to figure the best combination you had working 5 minutes ago. Copy/paste the combination into a separate codepath as soon as it looks good enough ( so that later you can choose between the best ones).

- Screenshot system, where you grab screens and compare different combinations of all parameters (texture, diff, ambient, TSS ColorOp)

- Base terrain texture in at least 6 different levels of Brightness / Contrast : Texture_10, Texture_30, Texture_50, Texture_65, Texture_80, Texture_100 (that you can switch between at runtime upon a keypress). I can change the texture by pressing 'T' at runtime and can see right away which brightness is best this way right away

- TSS ColorOp change upon a keypress (from ALL possible ones - see DX Docs)

 

When you have the system above, then all it takes is just few keypresses and you can come up with some pretty nice combinations.

 

Share this post


Link to post
Share on other sites
greenpig83    330

Yeah, I think I found the way for my problem. Generate a prebake LightMap (need a tesselation and generate light intensity at each point in the surface), because there are no changing in light direction, so the lightmap is used for all the game render time. Use modulate2x for the LightMap make it look brighter as expected.

 

About the Shader limit issue. I havent made a wide investigation, but I remember some game require: Pixel Shader 2.0 .  And it seems a lot of Computer/Laptop with integrated cards fail to start it. Example "League of Legend" (There are more like this, I saw some ). Though I'm not a master (more like a newbie) with Shader, so I'm not quite sure a normal lighting like my game may need what kind of Pixel shader :  1.0 ? what about Vertex Shader. In a ps file, there always, go throught VS then PS. Of couse if shader work for my case, I will try it because it seem alot more simple than prepare a prebake light. because there need to be quite a lot of it (slopes above have different light than one at base level). 

Share this post


Link to post
Share on other sites
C0lumbo    4411

Yeah, I think I found the way for my problem. Generate a prebake LightMap (need a tesselation and generate light intensity at each point in the surface), because there are no changing in light direction, so the lightmap is used for all the game render time. Use modulate2x for the LightMap make it look brighter as expected.

 

If you actually want to use a lightmap, then that's obviously fine, but there is absolutely no need to switch from using dynamic vertex lighting to light maps just in order to enable the modulate2x brightening effect. You can enable the modulate2x (or 4x) on the texture stage state which combines the lighting output with the diffuse texture.

 

Sorry to keep repeating myself in this thread, but for some reason you've concluded that modulate2x only works when combining textures, but that's wrong. You can achieve the effect you want with your existing dynamic lighting. Of course, there's plenty of good reasons for using light maps, but it sounds like you're making the choice for the wrong reasons in this particular situation.

Share this post


Link to post
Share on other sites
apatriarca    2365

About the Shader limit issue. I havent made a wide investigation, but I remember some game require: Pixel Shader 2.0 .  And it seems a lot of Computer/Laptop with integrated cards fail to start it. Example "League of Legend" (There are more like this, I saw some ). Though I'm not a master (more like a newbie) with Shader, so I'm not quite sure a normal lighting like my game may need what kind of Pixel shader :  1.0 ? what about Vertex Shader. In a ps file, there always, go throught VS then PS. Of couse if shader work for my case, I will try it because it seem alot more simple than prepare a prebake light. because there need to be quite a lot of it (slopes above have different light than one at base level). 

 

There always be someone which will not be able to play your game. Integrated cards used to suck, but they all support shaders now. My two years old netbook has support for the DirectX 11 API for example. OpenGL ES 2 is now the standard API used in the mobile world and supports shaders. WebGL have similar requirements. Unity* and other engines do not support the fixed pipeline anymore. If you really want to play something new, you should now probably buy a computer with shader support. Learning to write shaders is also a lot more useful than learning to work with the fixed pipeline.

 

* The current version still support it actually, but they recently decided to drop it in the next version.

Share this post


Link to post
Share on other sites
VladR    722

It used to be - about 7-10 yrs ago - that you could say that if your computer cannot run the game, you are probably not a target market.

 

These days, when even cheapest of laptops ship with SM 2.0 cards, the only PCs you can find that can't run SM 2.0 are the ones that are kept as second/third computer at home - which means that in that household is still at least 1 computer able to run it.

 

 

I do, however, understand, your unwillingness to learn the shaders. They are not really that straightforward and debugging them is, by default, PITA - especially compared to FFP.

 

Long-term, you can't avoid shaders, really.

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