dynamic lighting

dynamic lighting
0.0 0



Does anyone have any information on how dynamic lighting can be done in this framework? I haven’t been able to find anything.



Can you explain what “dynamic lighting” is?


dynamic lighting in 2D?.. what exactly would you like to do?..


For example if the character walked past a fire I’d like the way he was lit to change as he went by it. It might be related to how shaders would work as I would assume there would be a normal texture needed.


like this?

or just lighting things differently, without shadows?

(lighting items with colours would be a lot easier than shadows)

In 2d you could change the colours of each of the vertices - ie the four corners of a sprite and make them different colours / therefore lights…
This is a shader thing, which is already built it - the colour actions in the sample just change all 4 at once and done gradient between them.

normal maps wouldn’t normally be used in 2d lighting, but would if you had a slight 3d effect, essentially if the light was slightly raised up.


I don’t have a specific visual target yet. I’m more looking at what is possible.

Sounds like shadows (not surprising) are difficult. I don’t see that colour actions sample you mentioned in the testcpp project. I would be interested in seeing that, can you name the test it is in?

I was looking to if we could get a slight 3d effect using bump maps. Are there examples of that?



it just uses setcolour function in sprite;

CCSprite has this function:

ccColor4B color4 = { m_sColor.r, m_sColor.g, m_sColor.b, m_nOpacity };

m_sQuad.bl.colors = color4;
m_sQuad.br.colors = color4;
m_sQuad.tl.colors = color4;
m_sQuad.tr.colors = color4;


which sets all four vertices of the (in truth-3d) square

The: “ccShader_PositionTextureColor_vert” vert shader makes a variable v_fragmentColor; which is set to the frag shader, It varies which means it interpolates between the colours (mixing them) relative to each frags proximity to the vert.

the “ccShader_PositionTextureColor_frag” frag shader takes the colour that this pixel should be and multiplies it by the texture colour.
v_fragmentColor * texture2D(CC_Texture0, v_texCoord);

essentially this is the same a the multiply filter in photoshop (which is often used for shadows) it appears as the texture when white and black when black - anywhere in between including colours looks like that amount of light is being shined on it.

This is what is called in the 3D world as “vertex lighting” - something which even modern games use in moderation when the lighting does not matter that much.
It makes more sense with very high detail models, since there is actually useful variation in the different positions and normals of the vertices, it might not be so useful when you only have 4 verticies per sprite object.