I am using bsp file for my game's level and want to animate a brush (using an animator / manual setPosition)
I centered the brush to force its origin at its AABB center instead of 0,0,0
(by first changing the mesh vertices positions and then relocate it at its original location with setPosition(), see code below)
(I do this to use a my brushEntity in a physics library, but that is not in the scope of this thread because this part works pretty well )
For example one of those entities is a door on which I applied a glsl shader (for custom special effects)
the shader compute also the lights, but the light doesn't work correctly. it seems that the shader is not aware of the new brush location
the lights / special FX behaves as if the brush is still located at (0,0,0)
Can you tell me what I'm doing wrong / missing?
Here is how I change the origin:
Code: Select all
/** @var irr::scene::IQ3LevelMesh* level */
/** @var irr::s32 brush_id */
// Set brush origin at its own origin instead of (0,0,0)
irr::scene::IMesh* mesh = level->getBrushEntityMesh(brush_id);
irr::core::vector3df origin = mesh->getBoundingBox().getCenter();
irr::scene::IMeshManipulator* myManip = scene_manager->getMeshManipulator();
irr::core::matrix4 matrix;
matrix.setTranslation(-origin);
myManip ->transform(mesh, matrix);
// Update mesh because of vertices edit
for (irr::u32 j=0; j<mesh->getMeshBufferCount(); j++)
{
irr::scene::IMeshBuffer* meshBuffer = mesh->getMeshBuffer(j);
meshBuffer->setDirty();
meshBuffer->recalculateBoundingBox();
}
mesh->setDirty();
// ...
// Other unrelated treatments (mainly adding the node to scene manager + game specific code)
// ...
// Put the the node back to its original position
node->setPosition(origin);
Code: Select all
varying vec3 vFragPos;
varying vec3 vNormal;
void main(void)
{
vFragPos = gl_Vertex.xyz;
vNormal = gl_Normal;
gl_Position = ftransform();
}
Code: Select all
vec3 computePointLight(PointLight light, vec3 materialDiffuse, float shininess, vec3 normal)
{
vec3 viewDir = normalize(uEyePos - vFragPos);
vec3 lightDir = normalize(light.position - vFragPos);
// diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
// attenuation
float distance = length(light.position - vFragPos);
float attenuation = clamp(1.0 - distance*distance/(light.radius*light.radius), 0.0, 1.0);
// combine results
vec3 ambient = light.ambient * materialDiffuse;
vec3 diffuse = light.diffuse * diff * materialDiffuse;
vec3 specular = shininess > 0 ? light.diffuse * light.specular * spec : vec3(0.0);
return attenuation * (ambient + diffuse + specular);
}