Creating fake shadow , in cocos2dxin 3D game

I am working on 3d game in which 4 basketball are placed on the screen I am creating fake shadow effect using the help of Sprite3DfakeShadow example given in cpp tests.But I am not able to create it all 4 balls.Only the last one ball is having shadow.Anyone give me suggestion

Thanx in advance.
:smile:

The sample in cpptests only supports one shadow. There are two solutions.

  1. Modify the fake shadow shader, the fragment shader should be something like this,
...
uniform vec3 u_target_pos;
uniform vec3 u_target_pos2;
uniform vec3 u_target_pos3;
uniform vec3 u_target_pos4;
uniform vec4 u_color;
void main(void)
{
	float Radius = 4.0;//project range
	vec3 UVector = vec3(1.0, 0.0, 0.0)/(2.0 * Radius);
	vec3 VVector = vec3(0.0, 0.0, -1.0)/(-2.0 * Radius);
	vec2 coord, coord2, coord3, coord4;
	coord.x = dot(v_position.xyz - u_target_pos, UVector) + 0.5;
	coord.y = dot(v_position.xyz - u_target_pos, VVector) + 0.5;
    
    coord2.x = dot(v_position.xyz - u_target_pos2, UVector) + 0.5;
    coord2.y = dot(v_position.xyz - u_target_pos2, VVector) + 0.5;
    
    coord3.x = dot(v_position.xyz - u_target_pos3, UVector) + 0.5;
    coord3.y = dot(v_position.xyz - u_target_pos3, VVector) + 0.5;
    
    coord4.x = dot(v_position.xyz - u_target_pos4, UVector) + 0.5;
    coord4.y = dot(v_position.xyz - u_target_pos4, VVector) + 0.5;
    
    vec4 blendcolor = texture2D(u_sampler1,coord) + texture2D(u_sampler1,coord2) + texture2D(u_sampler1,coord3) + texture2D(u_sampler1,coord4);

	gl_FragColor = u_color*texture2D(u_sampler0,v_texture_coord)*blendcolor;
}

You should have 4 shadow target, and blend them together.
2. You can create a 2d sprite from the shadow texture. Then create an empty Sprite3D, sprite3d->addChild(sprite); You can place the sprite3d on the ground. It serves as a 3D model.