2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_Light.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2012-10-15 02:15:07 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable:4786)
|
2002-10-12 11:37:38 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-29 17:49:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-06-09 13:51:32 +00:00
|
|
|
#include "GL/glew.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_Light.h"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "KX_Camera.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "RAS_IRenderTools.h"
|
|
|
|
|
2004-05-30 11:09:46 +00:00
|
|
|
#include "KX_PyMath.h"
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
#include "DNA_object_types.h"
|
2009-06-09 13:51:32 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2012-05-01 02:50:17 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
2008-07-10 12:47:20 +00:00
|
|
|
#include "GPU_material.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
|
2012-10-15 02:15:07 +00:00
|
|
|
class RAS_IRenderTools* rendertools,
|
|
|
|
const RAS_LightObject& lightobj,
|
|
|
|
bool glsl)
|
2009-06-28 11:22:26 +00:00
|
|
|
: KX_GameObject(sgReplicationInfo,callbacks),
|
|
|
|
m_rendertools(rendertools)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
m_lightobj = lightobj;
|
2009-03-24 15:45:08 +00:00
|
|
|
m_lightobj.m_scene = sgReplicationInfo;
|
2009-06-09 13:51:32 +00:00
|
|
|
m_lightobj.m_light = this;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->AddLight(&m_lightobj);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
m_glsl = glsl;
|
|
|
|
m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
KX_LightObject::~KX_LightObject()
|
|
|
|
{
|
2008-09-10 09:51:06 +00:00
|
|
|
GPULamp *lamp;
|
2012-07-23 20:24:35 +00:00
|
|
|
Lamp *la = (Lamp*)GetBlenderObject()->data;
|
2008-09-10 09:51:06 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((lamp = GetGPULamp())) {
|
2008-09-10 09:51:06 +00:00
|
|
|
float obmat[4][4] = {{0}};
|
2010-07-27 11:10:34 +00:00
|
|
|
GPU_lamp_update(lamp, 0, 0, obmat);
|
2012-07-23 20:24:35 +00:00
|
|
|
GPU_lamp_update_distance(lamp, la->dist, la->att1, la->att2);
|
|
|
|
GPU_lamp_update_spot(lamp, la->spotsize, la->spotblend);
|
2008-09-10 09:51:06 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->RemoveLight(&m_lightobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CValue* KX_LightObject::GetReplica()
|
|
|
|
{
|
|
|
|
|
|
|
|
KX_LightObject* replica = new KX_LightObject(*this);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2009-04-22 12:16:41 +00:00
|
|
|
replica->ProcessReplica();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-09 13:51:32 +00:00
|
|
|
replica->m_lightobj.m_light = replica;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_rendertools->AddLight(&replica->m_lightobj);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return replica;
|
|
|
|
}
|
2004-05-30 11:09:46 +00:00
|
|
|
|
2009-06-09 13:51:32 +00:00
|
|
|
bool KX_LightObject::ApplyLight(KX_Scene *kxscene, int oblayer, int slot)
|
|
|
|
{
|
|
|
|
KX_Scene* lightscene = (KX_Scene*)m_lightobj.m_scene;
|
|
|
|
float vec[4];
|
|
|
|
int scenelayer = ~0;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (kxscene && kxscene->GetBlenderScene())
|
2009-06-09 13:51:32 +00:00
|
|
|
scenelayer = kxscene->GetBlenderScene()->lay;
|
|
|
|
|
|
|
|
/* only use lights in the same layer as the object */
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!(m_lightobj.m_layer & oblayer))
|
2009-06-09 13:51:32 +00:00
|
|
|
return false;
|
|
|
|
/* only use lights in the same scene, and in a visible layer */
|
2012-03-24 07:52:14 +00:00
|
|
|
if (kxscene != lightscene || !(m_lightobj.m_layer & scenelayer))
|
2009-06-09 13:51:32 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// lights don't get their openGL matrix updated, do it now
|
2012-03-24 07:52:14 +00:00
|
|
|
if (GetSGNode()->IsDirty())
|
2009-06-09 13:51:32 +00:00
|
|
|
GetOpenGLMatrix();
|
|
|
|
|
|
|
|
MT_CmMatrix4x4& worldmatrix= *GetOpenGLMatrixPtr();
|
|
|
|
|
|
|
|
vec[0] = worldmatrix(0,3);
|
|
|
|
vec[1] = worldmatrix(1,3);
|
|
|
|
vec[2] = worldmatrix(2,3);
|
|
|
|
vec[3] = 1.0f;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_lightobj.m_type==RAS_LightObject::LIGHT_SUN) {
|
2009-06-09 13:51:32 +00:00
|
|
|
|
|
|
|
vec[0] = worldmatrix(0,2);
|
|
|
|
vec[1] = worldmatrix(1,2);
|
|
|
|
vec[2] = worldmatrix(2,2);
|
2012-10-22 08:15:51 +00:00
|
|
|
//vec[0] = base->object->obmat[2][0];
|
|
|
|
//vec[1] = base->object->obmat[2][1];
|
|
|
|
//vec[2] = base->object->obmat[2][2];
|
|
|
|
vec[3] = 0.0;
|
2009-06-09 13:51:32 +00:00
|
|
|
glLightfv((GLenum)(GL_LIGHT0+slot), GL_POSITION, vec);
|
|
|
|
}
|
|
|
|
else {
|
2012-10-22 08:15:51 +00:00
|
|
|
//vec[3] = 1.0;
|
2009-06-09 13:51:32 +00:00
|
|
|
glLightfv((GLenum)(GL_LIGHT0+slot), GL_POSITION, vec);
|
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_CONSTANT_ATTENUATION, 1.0);
|
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_LINEAR_ATTENUATION, m_lightobj.m_att1/m_lightobj.m_distance);
|
|
|
|
// without this next line it looks backward compatible.
|
|
|
|
//attennuation still is acceptable
|
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_QUADRATIC_ATTENUATION, m_lightobj.m_att2/(m_lightobj.m_distance*m_lightobj.m_distance));
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_lightobj.m_type==RAS_LightObject::LIGHT_SPOT) {
|
2009-06-09 13:51:32 +00:00
|
|
|
vec[0] = -worldmatrix(0,2);
|
|
|
|
vec[1] = -worldmatrix(1,2);
|
|
|
|
vec[2] = -worldmatrix(2,2);
|
2012-10-22 08:15:51 +00:00
|
|
|
//vec[0] = -base->object->obmat[2][0];
|
|
|
|
//vec[1] = -base->object->obmat[2][1];
|
|
|
|
//vec[2] = -base->object->obmat[2][2];
|
2009-06-09 13:51:32 +00:00
|
|
|
glLightfv((GLenum)(GL_LIGHT0+slot), GL_SPOT_DIRECTION, vec);
|
2012-07-29 17:49:14 +00:00
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, m_lightobj.m_spotsize / 2.0f);
|
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_EXPONENT, 128.0f * m_lightobj.m_spotblend);
|
2009-06-09 13:51:32 +00:00
|
|
|
}
|
2012-07-29 17:49:14 +00:00
|
|
|
else {
|
2009-06-09 13:51:32 +00:00
|
|
|
glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, 180.0);
|
2012-07-29 17:49:14 +00:00
|
|
|
}
|
2009-06-09 13:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_lightobj.m_nodiffuse) {
|
|
|
|
vec[0] = vec[1] = vec[2] = vec[3] = 0.0;
|
|
|
|
}
|
|
|
|
else {
|
2012-10-22 08:15:51 +00:00
|
|
|
vec[0] = m_lightobj.m_energy*m_lightobj.m_red;
|
|
|
|
vec[1] = m_lightobj.m_energy*m_lightobj.m_green;
|
|
|
|
vec[2] = m_lightobj.m_energy*m_lightobj.m_blue;
|
|
|
|
vec[3] = 1.0;
|
2009-06-09 13:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glLightfv((GLenum)(GL_LIGHT0+slot), GL_DIFFUSE, vec);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_lightobj.m_nospecular)
|
2009-06-09 13:51:32 +00:00
|
|
|
{
|
|
|
|
vec[0] = vec[1] = vec[2] = vec[3] = 0.0;
|
|
|
|
}
|
|
|
|
else if (m_lightobj.m_nodiffuse) {
|
2012-10-22 08:15:51 +00:00
|
|
|
vec[0] = m_lightobj.m_energy*m_lightobj.m_red;
|
|
|
|
vec[1] = m_lightobj.m_energy*m_lightobj.m_green;
|
|
|
|
vec[2] = m_lightobj.m_energy*m_lightobj.m_blue;
|
|
|
|
vec[3] = 1.0;
|
2009-06-09 13:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glLightfv((GLenum)(GL_LIGHT0+slot), GL_SPECULAR, vec);
|
|
|
|
glEnable((GLenum)(GL_LIGHT0+slot));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *KX_LightObject::GetGPULamp()
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_glsl)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return GPU_lamp_from_blender(m_blenderscene, GetBlenderObject(), GetBlenderGroupObject());
|
|
|
|
else
|
2010-10-10 07:01:56 +00:00
|
|
|
return NULL;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2008-07-10 12:47:20 +00:00
|
|
|
void KX_LightObject::Update()
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *lamp;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((lamp = GetGPULamp()) != NULL && GetSGNode()) {
|
2008-07-10 12:47:20 +00:00
|
|
|
float obmat[4][4];
|
BGE performance, 3rd round: culling and rasterizer.
This commit extend the technique of dynamic linked list to the mesh
slots so as to eliminate dumb scan or map lookup. It provides massive
performance improvement in the culling and in the rasterizer when
the majority of objects are static.
Other improvements:
- Compute the opengl matrix only for objects that are visible.
- Simplify hash function for GEN_HasedPtr
- Scan light list instead of general object list to render shadows
- Remove redundant opengl calls to set specularity, shinyness and diffuse
between each mesh slots.
- Cache GPU material to avoid frequent call to GPU_material_from_blender
- Only set once the fixed elements of mesh slot
- Use more inline function
The following table shows the performance increase between 2.48, 1st round
and this round of improvement. The test was done with a scene containing
40000 objects, of which 1000 are in the view frustrum approximately. The
object are simple textured cube to make sure the GPU is not the bottleneck.
As some of the rasterizer processing time has moved under culling, I present
the sum of scenegraph(includes culling)+rasterizer time
Scenegraph+rasterizer(ms) 2.48 1st round 3rd round
All objects static, 323.0 86.0 7.2
all visible, 1000 in
the view frustrum
All objects static, 219.0 49.7 N/A(*)
all invisible.
All objects moving, 323.0 105.6 34.7
all visible, 1000 in
the view frustrum
Scene destruction 40min 40min 4s
(*) : this time is not representative because the frame rate was at 60fps.
In that case, the GPU holds down the GE by frame sync. By design, the
overhead of the rasterizer is 0 when the the objects are invisible.
This table shows a global speed up between 9x and 45x compared to 2.48a
for scenegraph, culling and rasterizer overhead. The speed up goes much
higher when objects are invisible.
An additional 2-4x speed up is possible in the scenegraph by upgrading
the Moto library to use Eigen2 BLAS library instead of C++ classes but
the scenegraph is already so fast that it is not a priority right now.
Next speed up in logic: many things to do there...
2009-05-07 09:13:01 +00:00
|
|
|
// lights don't get their openGL matrix updated, do it now
|
|
|
|
if (GetSGNode()->IsDirty())
|
|
|
|
GetOpenGLMatrix();
|
2008-07-10 12:47:20 +00:00
|
|
|
double *dobmat = GetOpenGLMatrixPtr()->getPointer();
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<4; i++)
|
|
|
|
for (int j=0; j<4; j++, dobmat++)
|
2008-07-10 12:47:20 +00:00
|
|
|
obmat[i][j] = (float)*dobmat;
|
|
|
|
|
2010-07-27 11:10:34 +00:00
|
|
|
GPU_lamp_update(lamp, m_lightobj.m_layer, 0, obmat);
|
2009-05-13 06:42:15 +00:00
|
|
|
GPU_lamp_update_colors(lamp, m_lightobj.m_red, m_lightobj.m_green,
|
|
|
|
m_lightobj.m_blue, m_lightobj.m_energy);
|
2012-07-23 20:24:35 +00:00
|
|
|
GPU_lamp_update_distance(lamp, m_lightobj.m_distance, m_lightobj.m_att1, m_lightobj.m_att2);
|
|
|
|
GPU_lamp_update_spot(lamp, m_lightobj.m_spotsize, m_lightobj.m_spotblend);
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_LightObject::HasShadowBuffer()
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *lamp;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((lamp = GetGPULamp()))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return GPU_lamp_has_shadow_buffer(lamp);
|
|
|
|
else
|
|
|
|
return false;
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::GetShadowLayer()
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *lamp;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((lamp = GetGPULamp()))
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
return GPU_lamp_shadow_layer(lamp);
|
2008-07-10 12:47:20 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_Transform& camtrans)
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *lamp;
|
2008-07-10 12:47:20 +00:00
|
|
|
float viewmat[4][4], winmat[4][4];
|
|
|
|
int winsize;
|
|
|
|
|
|
|
|
/* bind framebuffer */
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
lamp = GetGPULamp();
|
|
|
|
GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);
|
2008-07-10 12:47:20 +00:00
|
|
|
|
|
|
|
/* setup camera transformation */
|
|
|
|
MT_Matrix4x4 modelviewmat((float*)viewmat);
|
|
|
|
MT_Matrix4x4 projectionmat((float*)winmat);
|
|
|
|
|
|
|
|
MT_Transform trans = MT_Transform((float*)viewmat);
|
|
|
|
camtrans.invert(trans);
|
|
|
|
|
|
|
|
cam->SetModelviewMatrix(modelviewmat);
|
|
|
|
cam->SetProjectionMatrix(projectionmat);
|
|
|
|
|
|
|
|
cam->NodeSetLocalPosition(camtrans.getOrigin());
|
|
|
|
cam->NodeSetLocalOrientation(camtrans.getBasis());
|
2009-04-07 22:14:06 +00:00
|
|
|
cam->NodeUpdateGS(0);
|
2008-07-10 12:47:20 +00:00
|
|
|
|
|
|
|
/* setup rasterizer transformations */
|
2011-08-14 04:37:53 +00:00
|
|
|
/* SetViewMatrix may use stereomode which we temporarily disable here */
|
|
|
|
RAS_IRasterizer::StereoMode stereomode = ras->GetStereoMode();
|
|
|
|
ras->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
|
2008-07-10 12:47:20 +00:00
|
|
|
ras->SetProjectionMatrix(projectionmat);
|
2009-04-26 12:23:30 +00:00
|
|
|
ras->SetViewMatrix(modelviewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->GetCameraData()->m_perspective);
|
2011-08-14 04:37:53 +00:00
|
|
|
ras->SetStereoMode(stereomode);
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras)
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
GPULamp *lamp = GetGPULamp();
|
|
|
|
GPU_lamp_shadow_buffer_unbind(lamp);
|
2008-07-10 12:47:20 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 02:50:17 +00:00
|
|
|
struct Image *KX_LightObject::GetTextureImage(short texslot)
|
|
|
|
{
|
|
|
|
Lamp *la = (Lamp*)GetBlenderObject()->data;
|
|
|
|
|
|
|
|
if (texslot >= MAX_MTEX || texslot < 0)
|
|
|
|
{
|
|
|
|
printf("KX_LightObject::GetTextureImage(): texslot exceeds slot bounds (0-%d)\n", MAX_MTEX-1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (la->mtex[texslot])
|
|
|
|
return la->mtex[texslot]->tex->ima;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-04-21 23:15:18 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python Integration Hooks */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2004-05-30 11:09:46 +00:00
|
|
|
|
|
|
|
PyTypeObject KX_LightObject::Type = {
|
2009-04-29 16:54:45 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"KX_LightObject",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Sequence,
|
|
|
|
&KX_GameObject::Mapping,
|
|
|
|
0,0,0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&KX_GameObject::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2004-05-30 11:09:46 +00:00
|
|
|
};
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
PyMethodDef KX_LightObject::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
PyAttributeDef KX_LightObject::Attributes[] = {
|
|
|
|
KX_PYATTRIBUTE_INT_RW("layer", 1, 20, true, KX_LightObject, m_lightobj.m_layer),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("energy", 0, 10, KX_LightObject, m_lightobj.m_energy),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("distance", 0.01, 5000, KX_LightObject, m_lightobj.m_distance),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("color", KX_LightObject, pyattr_get_color, pyattr_set_color),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("lin_attenuation", 0, 1, KX_LightObject, m_lightobj.m_att1),
|
2009-05-14 23:06:05 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("quad_attenuation", 0, 1, KX_LightObject, m_lightobj.m_att2),
|
2009-04-21 23:15:18 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("spotsize", 1, 180, KX_LightObject, m_lightobj.m_spotsize),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("spotblend", 0, 1, KX_LightObject, m_lightobj.m_spotblend),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("SPOT", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("SUN", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("NORMAL", KX_LightObject, pyattr_get_typeconst),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("type", KX_LightObject, pyattr_get_type, pyattr_set_type),
|
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
return Py_BuildValue("[fff]", self->m_lightobj.m_red, self->m_lightobj.m_green, self->m_lightobj.m_blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KX_LightObject::pyattr_set_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
|
|
|
|
|
|
|
MT_Vector3 color;
|
|
|
|
if (PyVecTo(value, color))
|
|
|
|
{
|
|
|
|
self->m_lightobj.m_red = color[0];
|
|
|
|
self->m_lightobj.m_green = color[1];
|
|
|
|
self->m_lightobj.m_blue = color[2];
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *retvalue;
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
const char* type = attrdef->m_name;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!strcmp(type, "SPOT")) {
|
2009-06-29 02:25:54 +00:00
|
|
|
retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_SPOT);
|
2010-02-04 23:51:41 +00:00
|
|
|
} else if (!strcmp(type, "SUN")) {
|
2009-06-29 02:25:54 +00:00
|
|
|
retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_SUN);
|
2010-02-04 23:51:41 +00:00
|
|
|
} else if (!strcmp(type, "NORMAL")) {
|
2009-06-29 02:25:54 +00:00
|
|
|
retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_NORMAL);
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
2011-09-01 02:12:53 +00:00
|
|
|
else {
|
|
|
|
/* should never happen */
|
|
|
|
PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type");
|
|
|
|
retvalue = NULL;
|
|
|
|
}
|
2009-04-21 23:15:18 +00:00
|
|
|
|
|
|
|
return retvalue;
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_LightObject::pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2009-06-29 02:25:54 +00:00
|
|
|
return PyLong_FromSsize_t(self->m_lightobj.m_type);
|
2009-04-21 23:15:18 +00:00
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
int KX_LightObject::pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
2009-04-21 23:15:18 +00:00
|
|
|
{
|
|
|
|
KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
|
2009-06-29 02:25:54 +00:00
|
|
|
int val = PyLong_AsSsize_t(value);
|
2012-03-24 07:52:14 +00:00
|
|
|
if ((val==-1 && PyErr_Occurred()) || val<0 || val>2) {
|
2009-05-19 07:16:40 +00:00
|
|
|
PyErr_SetString(PyExc_ValueError, "light.type= val: KX_LightObject, expected an int between 0 and 2");
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
switch (val) {
|
2009-04-21 23:15:18 +00:00
|
|
|
case 0:
|
|
|
|
self->m_lightobj.m_type = self->m_lightobj.LIGHT_SPOT;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
self->m_lightobj.m_type = self->m_lightobj.LIGHT_SUN;
|
|
|
|
break;
|
2009-05-19 07:16:40 +00:00
|
|
|
case 2:
|
2009-04-21 23:15:18 +00:00
|
|
|
self->m_lightobj.m_type = self->m_lightobj.LIGHT_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|