Question

I have a scene and a character in Cocos3D, but the background image of the scene appears much brighter than the character. There is a CC3Light in the scene in front of the character, here's how it looks with different settings:

enter image description here

  • The light in the first screenshot (isDirectionalOnly = YES): The character lighting is very dark but the background image is normal.

  • The second screenshot (isDirectionalOnly = NO): The character is visible and looks like it has shadow behind, but the background of the scene is too bright.

Questions:

How can I control the objects lighting? The properties ambientColor and shininess don't have much influence. I would like both the character and the background image to have, more or less, the same brightness, to give a realistic impression that the character is in the forest.

Why is the character so dark when the light is "directional only"? This darkness doesn't exist in character's texture alone.

Was it helpful?

Solution

Based on the example project you sent, the main issue is that your light was located at the origin of the scene (global location 0,0,0). A directional light uses the global position vector of the light to determine the direction the light is coming from. That caused the light to basically have a zero vector for its direction, and the default shaders don't like that.

The reason your forest was being washed out is that it's material has ambient, diffuse, and specular colors that, when combined with the corresponding light colors, add up to more than 1.0 in each component. For future reference, you can see this in the logs during POD loading:

[rez] Creating CC3PODMaterial at index 0 from: SPODMaterial named ForestMat
    ambient: (0.80, 0.80, 0.80), diffuse: (0.80, 0.80, 0.80), specular: (1.00, 1.00, 1.00), opacity: 1.00, shininess: 0.10
    src RGB blend: ePODBlendFunc_ONE, src alpha blend: ePODBlendFunc_ONE
    dest RGB blend: ePODBlendFunc_ZERO, dest alpha blend: ePODBlendFunc_ZERO
    operation RGB blend: ePODBlendOp_ADD, operation alpha blend: ePODBlendOp_ADD
    blend color: (0.00, 0.00, 0.00, 0.00), blend factor: (0.00, 0.00, 0.00, 0.00)
    texture indices: (diffuse: 0, ambient: -1, specular color: -1, specular level: -1, bump: -1, emissive: -1, gloss: -1, opacity: -1, reflection: -1, refraction: -1)
    flags: 0, effect none in file none

There are a couple of ways to handle this. The first option is to remove the specular color from the material, so that only ambient and diffuse lighting are used (which in your model, add up to 1.0 in each component...again see log listing above).

The other option, which can be good for backgrounds if you don't want them to be affected by lighting, is to set the shouldUseLighting property to NO. This causes the material to use only its emissionColor as its color. If you set the value of that to white, then the material will display the texture in its normal state, regardless of lighting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top