Sign in to follow this  

getting specular on wrong side of tree trunks

This topic is 824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

dx9 fixed function lighting system

 

i just noticed i'm getting specular reflection on the wrong side of tree trunks.

 

its most noticeable during night scenes, lit only by moonlight, a single directional white diffuse light of low intensity.  due to the complexity of the lighting equation used, i opted to use almost no overall ambient, and use a single diffuse directional light for sunlight or moonlight. then i use materials to control the lighting of various things (plants, ground, rocks, etc). so a fair amount of time was spent tweaking the specular for the plant material, so moonlight would reflect off of leaves just right. but for some reason, it also does a specular reflection on the back side of tree trunks (which use the same material). this makes no sense. the triangles are backfacing to the directional light. or does the lighting not take backfacing into account? and it does specular whenever the angles are right, irregardless? and i have to create and use a non-specular tree trunk material to get rid of it?

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

Are you sure your vertex normals are correct?

 

BTW: Have you considered using shaders instead? The FF lighting is per vertex only, and you get much more flexibility with shaders smile.png

 

EDIT: Can you post your material properties? :)

Edited by vinterberg

Share this post


Link to post
Share on other sites


Are you sure your vertex normals are correct?

 

yes. gourard and aniso are correct, its only phong that behaves strangely.

 


BTW: Have you considered using shaders instead?

 

don't really need them. all i need is aniso, gourard, phong, mipmaps, alpha test, alpha blend, and a single two stage texture blend op (for snow on the ground). so fixed function is all that's needed.   instancing is about the only thing that would drive me to use shaders at this point, as you can't get true instancing without using shaders. but i'm getting draw distances of 1000 feet at highest LOD and 15K draw calls worth of stuff, so i'm not really pressed to go for true instancing yet.

 


Can you post your material properties?

 

 

 

 
void Zinit_materials()
{
ZeroMemory(Zmaterial,sizeof(D3DMATERIAL9)*ZMAXMATERIALS);
 
// default material
Zmaterial[0].Diffuse.r=1.0f;  
Zmaterial[0].Diffuse.g=1.0f;
Zmaterial[0].Diffuse.b=1.0f;
Zmaterial[0].Diffuse.a=1.0f;
 
Zmaterial[0].Ambient.r=0.02f;        
Zmaterial[0].Ambient.g=0.02f;
Zmaterial[0].Ambient.b=0.02f;
Zmaterial[0].Ambient.a=1.0f;
 
Zmaterial[0].Specular.r=0.0f;
Zmaterial[0].Specular.g=0.0f;
Zmaterial[0].Specular.b=0.0f;
Zmaterial[0].Specular.a=0.0f;
 
Zmaterial[0].Power=50.0f;
 
 
// ground material   
Zmaterial[1].Diffuse.r=0.29f;  // direct light brightness
Zmaterial[1].Diffuse.g=0.29f;
Zmaterial[1].Diffuse.b=0.29f;
Zmaterial[1].Diffuse.a=1.0f;
 
Zmaterial[1].Ambient.r=0.03f;     // no light brightness
Zmaterial[1].Ambient.g=0.03f;
Zmaterial[1].Ambient.b=0.03f;
Zmaterial[1].Ambient.a=1.0f;
 
Zmaterial[1].Specular.r=0.018f;    // shineyness
Zmaterial[1].Specular.g=0.018f;
Zmaterial[1].Specular.b=0.018f;
Zmaterial[1].Specular.a=1.0f;
 
Zmaterial[1].Power=2500.0f;      // tightness of shiney spot
 
 
 
 
 // plants material 
Zmaterial[2].Diffuse.r=0.2f;        
Zmaterial[2].Diffuse.g=0.2f;
Zmaterial[2].Diffuse.b=0.2f;
Zmaterial[2].Diffuse.a=1.0f;
 
Zmaterial[2].Ambient.r=0.02f;
Zmaterial[2].Ambient.g=0.02f;
Zmaterial[2].Ambient.b=0.02f;
Zmaterial[2].Ambient.a=1.0f;
 
Zmaterial[2].Specular.r=0.1f;
Zmaterial[2].Specular.g=0.1f;
Zmaterial[2].Specular.b=0.1f;
Zmaterial[2].Specular.a=1.0f;
 
Zmaterial[2].Power=400.0f;
 
 
 
// rocks material
Zmaterial[3].Diffuse.r=0.25f;    // brightness from direct light    
Zmaterial[3].Diffuse.g=0.25f;
Zmaterial[3].Diffuse.b=0.25f;
Zmaterial[3].Diffuse.a=1.0f;
 
Zmaterial[3].Ambient.r=0.1f;     // brightness with no light   
Zmaterial[3].Ambient.g=0.1f;
Zmaterial[3].Ambient.b=0.1f;
Zmaterial[3].Ambient.a=1.0f;
 
Zmaterial[3].Specular.r=0.035f;     // shineyness
Zmaterial[3].Specular.g=0.035f;
Zmaterial[3].Specular.b=0.035f;
Zmaterial[3].Specular.a=1.0f;
 
Zmaterial[3].Power=22.0f;              // tightness of shiney spot
 
 
 
 
 
// beacon material
Zmaterial[4].Diffuse.r=0.0f;    // brightness from direct light    
Zmaterial[4].Diffuse.g=0.0f;
Zmaterial[4].Diffuse.b=0.0f;
Zmaterial[4].Diffuse.a=0.0f;
 
Zmaterial[4].Ambient.r=10.0f;     // brightness with no light   
Zmaterial[4].Ambient.g=10.0f;
Zmaterial[4].Ambient.b=10.0f;
Zmaterial[4].Ambient.a=10.0f;
 
Zmaterial[4].Specular.r=0.0f;     // shineyness
Zmaterial[4].Specular.g=0.0f;
Zmaterial[4].Specular.b=0.0f;
Zmaterial[4].Specular.a=0.0f;
 
Zmaterial[4].Power=0.0f;              // tightness of shiney spot
 
Zmaterial[4].Emissive.r=10.0f;
Zmaterial[4].Emissive.g=10.0f;
Zmaterial[4].Emissive.b=10.0f;
Zmaterial[4].Emissive.a=1.0f;
 
 
// scrub ground material   
Zmaterial[5].Diffuse.r=0.4f;  // direct light brightness           .29
Zmaterial[5].Diffuse.g=0.4f;
Zmaterial[5].Diffuse.b=0.4f;
Zmaterial[5].Diffuse.a=1.0f;
 
Zmaterial[5].Ambient.r=0.03f;     // no light brightness
Zmaterial[5].Ambient.g=0.03f;
Zmaterial[5].Ambient.b=0.03f;
Zmaterial[5].Ambient.a=1.0f;
 
Zmaterial[5].Specular.r=0.018f;    // shineyness
Zmaterial[5].Specular.g=0.018f;
Zmaterial[5].Specular.b=0.018f;
Zmaterial[5].Specular.a=1.0f;
 
Zmaterial[5].Power=2500.0f;      // tightness of shiney spot
 
 
// cloud material
Zmaterial[6].Diffuse.r=0.1f;  
Zmaterial[6].Diffuse.g=0.1f;
Zmaterial[6].Diffuse.b=0.1f;
Zmaterial[6].Diffuse.a=1.0f;
 
// ambient is set when clouds are drawn
 
Zmaterial[6].Specular.r=0.0f;
Zmaterial[6].Specular.g=0.0f;
Zmaterial[6].Specular.b=0.0f;
Zmaterial[6].Specular.a=0.0f;
 
Zmaterial[6].Power=0.0f;
 
 
 
 // prairie material 
Zmaterial[7].Diffuse.r=0.5f;        
Zmaterial[7].Diffuse.g=0.5f;
Zmaterial[7].Diffuse.b=0.5f;
Zmaterial[7].Diffuse.a=1.0f;
 
Zmaterial[7].Ambient.r=0.5f;
Zmaterial[7].Ambient.g=0.5f;
Zmaterial[7].Ambient.b=0.5f;
Zmaterial[7].Ambient.a=1.0f;
 
Zmaterial[7].Specular.r=0.1f;
Zmaterial[7].Specular.g=0.1f;
Zmaterial[7].Specular.b=0.1f;
Zmaterial[7].Specular.a=1.0f;
 
Zmaterial[7].Power=400.0f;
}
 

Share this post


Link to post
Share on other sites

tree trunks use Zmaterial[2]

 

void generate_terrain_woods(int a)              // a is chunk #
{
int x,z,x1,z1,x2,z2,b;
get_plantmaps_in_chunk(a,&x1,&z1,&x2,&z2);
ZeroMemory(&ABa,sizeof(Zdrawinfo));
ABa.materialID=2;
ABa.rad=30;
ABa.cliprng=tree_cliprng;
for (x=x1; x<=x2; x++)              // for each plant map in the chunk...
    for (z=z1; z<=z2; z++)
        for (b=0; b<maxplants; b++) 
            generate_CB2(a,x,z,b);           // draw tree
generate_terrain_woods_plants(a);
}

Share this post


Link to post
Share on other sites

Wanted to see if your emissive wasn't set to 0.0, but they are biggrin.png

 

I tried to look through D3D9 docs to see if there's any "doublesided lighting" states or something, but cannot locate any!

 

Maybe some screenshots could help on the matter?

 

It's been many years since I messed with FF pipeline :/

 

EDIT: Have you read this? https://msdn.microsoft.com/en-us/library/windows/desktop/bb147399%28v=vs.85%29.aspx .. Especially the section "The Halfway Vector", have you set D3DRS_LOCALVIEWER to TRUE or FALSE?

Edited by vinterberg

Share this post


Link to post
Share on other sites

have you set D3DRS_LOCALVIEWER to TRUE or FALSE?

 

its TRUE by default, and i don''t change it. so that's not it.

 

interesting that the online docs don't mention the default value. but the offline docs in the june 2010 SDK do. 

 

i took a screenshot when i noticed it, i'll post it.   nothing much to look at, 3rd person view of a player character in a FPSRPG, with a tree in front of her, and the moon in the background behind the tree, and specular on the near side of the tree trunk, more or less backfacing where it ought to be on the far side of the tree trunk, IE the side facing the moon, and facing away from the camera.

 

i find it kind of odd, because if dx9 fixed function specular does that by default, then libraries and engines based on FF dx9 would as well, things such as older versions of Ogre3D, SharpDX, SlimDX, etc.  and i'd think somebody would notice that and take exception to it.

 

i'd have to look at the vector equations to figure out if it would get the same result with front or back facing triangles.

 

might be easier to just change the material. <g>.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

well, i thought i had a screenshot, but you can't see it, she's standing in the frickin' way! <g>.

 

the moon is off to the right a little bit and you can see the specular on that side of the tree trunk, but the girl is blocking the view of the back of the tree trunk.  : (

 

i'll have to wait until i get into similar lighting conditions during testing to try to get another screenshot. time of day and the weather engine both affect the lighting.

 

 

 

 

 

update: dec 12th 2015

 

after further observation of the phenomena, i've come to the conclusion that its the insanely high power value used for phong in the plant material, which is used both for leaves and trunks. works great for moonlight reflecting off wet grass or small foliage, but tends to fall apart when looking up at large trees. the fix is a lower power material for leaves, and a separate duller looking material for trunks.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

This topic is 824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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