Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Szepe <HG1_public@gmx.net>2015-03-23 23:40:11 +0300
committerThomas Szepe <HG1_public@gmx.net>2015-03-23 23:40:11 +0300
commitd07c666a0e542517914dad580d1b3f4787525852 (patch)
tree4f9c2c5999817acaca97351e72e71f3f19cb7652
parent2affbb437bd3cbf3e1a502bd65a5eefb64a92b9b (diff)
BGE: Add setMistType and setMistIntensity API.
This patch adds the missing setMistType() and setMistIntensity() to the API Reviewers: campbellbarton, brecht, moguri Reviewed By: campbellbarton, brecht, moguri Subscribers: campbellbarton, dingto Differential Revision: https://developer.blender.org/D149
-rw-r--r--doc/python_api/rst/bge.render.rst39
-rw-r--r--source/gameengine/Converter/BlenderWorldInfo.cpp21
-rw-r--r--source/gameengine/Converter/BlenderWorldInfo.h6
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp48
-rw-r--r--source/gameengine/Ketsji/KX_WorldInfo.h13
-rw-r--r--source/gameengine/Rasterizer/RAS_IRasterizer.h2
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp8
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h4
9 files changed, 133 insertions, 10 deletions
diff --git a/doc/python_api/rst/bge.render.rst b/doc/python_api/rst/bge.render.rst
index 3abbd50a453..09d16f4b2ed 100644
--- a/doc/python_api/rst/bge.render.rst
+++ b/doc/python_api/rst/bge.render.rst
@@ -87,6 +87,19 @@ Constants
Right eye being used during stereoscopic rendering.
+.. data:: KX_MIST_QUADRATIC
+
+ Type of quadratic attenuation used to fade mist.
+
+.. data:: KX_MIST_LINEAR
+
+ Type of linear attenuation used to fade mist.
+
+.. data:: KX_MIST_INV_QUADRATIC
+
+ Type of inverse quadratic attenuation used to fade mist.
+
+
*********
Functions
*********
@@ -165,20 +178,27 @@ Functions
:type rgba: list [r, g, b, a]
-.. function:: setMistColor(rgb)
+.. function:: setAmbientColor(rgb)
- Sets the mist color.
+ Sets the color of ambient light.
:type rgb: list [r, g, b]
-
-.. function:: setAmbientColor(rgb)
- Sets the color of ambient light.
+.. function:: setMistColor(rgb)
+
+ Sets the mist color.
:type rgb: list [r, g, b]
+.. function:: setMistType(mode)
+
+ Sets the mist attenuation type.
+
+ :type mode: KX_MIST_QUADRATIC, KX_MIST_LINEAR, KX_MIST_INV_QUADRATIC
+
+
.. function:: setMistStart(start)
Sets the mist start value. Objects further away than start will have mist applied to them.
@@ -193,9 +213,16 @@ Functions
:type end: float
-
+
+.. function:: setMistIntensity(intensity)
+
+ Sets the mist intensity value.
+
+ :type start: float
+
.. function:: disableMist()
+
Disables mist.
.. note:: Deprecated use setUseMist().
diff --git a/source/gameengine/Converter/BlenderWorldInfo.cpp b/source/gameengine/Converter/BlenderWorldInfo.cpp
index 28e42c1cc63..5f476949616 100644
--- a/source/gameengine/Converter/BlenderWorldInfo.cpp
+++ b/source/gameengine/Converter/BlenderWorldInfo.cpp
@@ -70,8 +70,10 @@ BlenderWorldInfo::BlenderWorldInfo(struct Scene *blenderscene, struct World *ble
if (blenderworld) {
m_hasworld = true;
m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false);
+ m_misttype = blenderworld->mistype;
m_miststart = blenderworld->miststa;
m_mistdistance = blenderworld->mistdist;
+ m_mistintensity = blenderworld->misi;
copy_v3_v3(m_mistcolor, &blenderworld->horr);
copy_v3_v3(m_backgroundcolor, &blenderworld->horr);
copy_v3_v3(m_ambientcolor, &blenderworld->ambr);
@@ -131,6 +133,11 @@ float BlenderWorldInfo::getAmbientColorBlue()
return m_ambientcolor[2];
}
+short BlenderWorldInfo::getMistType()
+{
+ return m_misttype;
+}
+
float BlenderWorldInfo::getMistStart()
{
return m_miststart;
@@ -141,6 +148,11 @@ float BlenderWorldInfo::getMistDistance()
return m_mistdistance;
}
+float BlenderWorldInfo::getMistIntensity()
+{
+ return m_mistintensity;
+}
+
float BlenderWorldInfo::getMistColorRed()
{
return m_mistcolor[0];
@@ -163,6 +175,11 @@ void BlenderWorldInfo::setBackColor(float r, float g, float b)
m_backgroundcolor[2] = b;
}
+void BlenderWorldInfo::setMistType(short type)
+{
+ m_misttype = type;
+}
+
void BlenderWorldInfo::setUseMist(bool enable)
{
m_hasmist = enable;
@@ -178,6 +195,10 @@ void BlenderWorldInfo::setMistDistance(float d)
m_mistdistance = d;
}
+void BlenderWorldInfo::setMistIntensity(float intensity)
+{
+ m_mistintensity = intensity;
+}
void BlenderWorldInfo::setMistColor(float r, float g, float b)
{
m_mistcolor[0] = r;
diff --git a/source/gameengine/Converter/BlenderWorldInfo.h b/source/gameengine/Converter/BlenderWorldInfo.h
index 6c67681c3bc..4184d428808 100644
--- a/source/gameengine/Converter/BlenderWorldInfo.h
+++ b/source/gameengine/Converter/BlenderWorldInfo.h
@@ -40,8 +40,10 @@ class BlenderWorldInfo : public KX_WorldInfo
float m_backgroundcolor[3];
bool m_hasmist;
+ short m_misttype;
float m_miststart;
float m_mistdistance;
+ float m_mistintensity;
float m_mistcolor[3];
float m_ambientcolor[3];
@@ -60,16 +62,20 @@ public:
float getAmbientColorGreen();
float getAmbientColorBlue();
+ short getMistType();
float getMistStart();
float getMistDistance();
+ float getMistIntensity();
float getMistColorRed();
float getMistColorGreen();
float getMistColorBlue();
void setBackColor(float r, float g, float b);
void setUseMist(bool enable);
+ void setMistType(short type);
void setMistStart(float d);
void setMistDistance(float d);
+ void setMistIntensity(float intensity);
void setMistColor(float r, float g, float b);
void setAmbientColor(float r, float g, float b);
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 44b667e15e0..8c6cb2b32d4 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -996,8 +996,10 @@ void KX_KetsjiEngine::SetWorldSettings(KX_WorldInfo* wi)
if (wi->hasMist())
{
m_rasterizer->SetFog(
+ wi->getMistType(),
wi->getMistStart(),
wi->getMistDistance(),
+ wi->getMistIntensity(),
wi->getMistColorRed(),
wi->getMistColorGreen(),
wi->getMistColorBlue()
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index e0af3283f44..8fd38db4a2a 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -1091,6 +1091,29 @@ static PyObject *gPySetUseMist(PyObject *, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *gPySetMistType(PyObject *, PyObject *args)
+{
+ short type;
+
+ if (!PyArg_ParseTuple(args,"i:setMistType",&type))
+ return NULL;
+
+ if (type < 0 || type > 2) {
+ PyErr_SetString(PyExc_ValueError, "Rasterizer.setMistType(int): Mist type is not known");
+ return NULL;
+ }
+
+ KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
+ if (!wi->hasWorld()) {
+ PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistType(int), World not available");
+ return NULL;
+ }
+
+ wi->setMistType(type);
+
+ Py_RETURN_NONE;
+}
+
static PyObject *gPySetMistStart(PyObject *, PyObject *args)
{
float miststart;
@@ -1125,6 +1148,24 @@ static PyObject *gPySetMistEnd(PyObject *, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *gPySetMistIntensity(PyObject *, PyObject *args)
+{
+
+ float intensity;
+ if (!PyArg_ParseTuple(args,"f:setMistIntensity",&intensity))
+ return NULL;
+
+ KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
+ if (!wi->hasWorld()) {
+ PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistIntensity(float), World not available");
+ return NULL;
+ }
+
+ wi->setMistIntensity(intensity);
+
+ Py_RETURN_NONE;
+}
+
static PyObject *gPySetAmbientColor(PyObject *, PyObject *value)
{
MT_Vector3 vec;
@@ -1522,8 +1563,10 @@ static struct PyMethodDef rasterizer_methods[] = {
{"disableMist",(PyCFunction)gPyDisableMist,METH_NOARGS,"turn off mist"},
{"setUseMist",(PyCFunction)gPySetUseMist,METH_VARARGS,"enable or disable mist"},
{"setMistColor",(PyCFunction)gPySetMistColor,METH_O,"set Mist Color (rgb)"},
+ {"setMistType",(PyCFunction)gPySetMistType,METH_VARARGS,"set mist type (short type)"},
{"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start"},
{"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End"},
+ {"setMistIntensity",(PyCFunction)gPySetMistIntensity,METH_VARARGS,"set mist intensity (float intensity)"},
{"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"},
{"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"},
@@ -2370,6 +2413,11 @@ PyMODINIT_FUNC initRasterizerPythonBinding()
KX_MACRO_addTypesToDict(d, LEFT_EYE, RAS_IRasterizer::RAS_STEREO_LEFTEYE);
KX_MACRO_addTypesToDict(d, RIGHT_EYE, RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
+ /* KX_WorldInfo mist types */
+ KX_MACRO_addTypesToDict(d, KX_MIST_QUADRATIC, KX_WorldInfo::KX_MIST_QUADRATIC);
+ KX_MACRO_addTypesToDict(d, KX_MIST_LINEAR, KX_WorldInfo::KX_MIST_LINEAR);
+ KX_MACRO_addTypesToDict(d, KX_MIST_INV_QUADRATIC, KX_WorldInfo::KX_MIST_INV_QUADRATIC);
+
// XXXX Add constants here
// Check for errors
diff --git a/source/gameengine/Ketsji/KX_WorldInfo.h b/source/gameengine/Ketsji/KX_WorldInfo.h
index 251ba95f43a..f90a4ff6b6d 100644
--- a/source/gameengine/Ketsji/KX_WorldInfo.h
+++ b/source/gameengine/Ketsji/KX_WorldInfo.h
@@ -43,6 +43,15 @@ class MT_CmMatrix4x4;
class KX_WorldInfo
{
public:
+ /**
+ * Mist options
+ */
+ enum MistType {
+ KX_MIST_QUADRATIC,
+ KX_MIST_LINEAR,
+ KX_MIST_INV_QUADRATIC,
+ };
+
KX_WorldInfo() {}
virtual ~KX_WorldInfo();
@@ -51,8 +60,10 @@ public:
virtual float getBackColorRed() = 0;
virtual float getBackColorGreen() = 0;
virtual float getBackColorBlue() = 0;
+ virtual short getMistType() = 0;
virtual float getMistStart() = 0;
virtual float getMistDistance() = 0;
+ virtual float getMistIntensity() = 0;
virtual float getMistColorRed() = 0;
virtual float getMistColorGreen() = 0;
virtual float getMistColorBlue() = 0;
@@ -62,8 +73,10 @@ public:
virtual float getAmbientColorBlue() = 0;
virtual void setUseMist(bool enable) = 0;
+ virtual void setMistType(short) = 0;
virtual void setMistStart(float) = 0;
virtual void setMistDistance(float) = 0;
+ virtual void setMistIntensity(float) = 0;
virtual void setMistColor(float, float, float) = 0;
virtual void setBackColor(float, float, float) = 0;
virtual void setAmbientColor(float,float,float) = 0;
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h
index 6f5273f035f..22ffcd48739 100644
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h
@@ -297,7 +297,7 @@ public:
/**
* Fog
*/
- virtual void SetFog(float start, float dist, float r, float g, float b) = 0;
+ virtual void SetFog(short type, float start, float dist, float intensity, float r, float g, float b) = 0;
virtual void SetFogColor(float r, float g,float b) = 0;
virtual void SetFogStart(float start) = 0;
virtual void SetFogEnd(float end) = 0;
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
index 14a184bbe7f..9269640afa3 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
@@ -247,14 +247,18 @@ void RAS_OpenGLRasterizer::SetFogEnd(float fogend)
-void RAS_OpenGLRasterizer::SetFog(float start,
+void RAS_OpenGLRasterizer::SetFog(short type,
+ float start,
float dist,
+ float intensity,
float r,
float g,
float b)
{
+ m_fogtype = type;
m_fogstart = start;
m_fogdist = dist;
+ m_fogintensity = intensity;
m_fogr = r;
m_fogg = g;
m_fogb = b;
@@ -279,7 +283,7 @@ void RAS_OpenGLRasterizer::DisplayFog()
{
float params[4] = {m_fogr, m_fogg, m_fogb, 1.0f};
glFogi(GL_FOG_MODE, GL_LINEAR);
- glFogf(GL_FOG_DENSITY, 0.1f);
+ glFogf(GL_FOG_DENSITY, m_fogintensity / 10.0f);
glFogf(GL_FOG_START, m_fogstart);
glFogf(GL_FOG_END, m_fogstart + m_fogdist);
glFogfv(GL_FOG_COLOR, params);
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
index 042243230b3..48023f9786c 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
@@ -80,8 +80,10 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
/* fogging vars */
bool m_fogenabled;
+ short m_fogtype;
float m_fogstart;
float m_fogdist;
+ float m_fogintensity;
float m_fogr;
float m_fogg;
float m_fogb;
@@ -198,7 +200,7 @@ public:
virtual const MT_Point3& GetCameraPosition();
virtual bool GetCameraOrtho();
- virtual void SetFog(float start, float dist, float r, float g, float b);
+ virtual void SetFog(short type, float start, float dist, float intensity, float r, float g, float b);
virtual void SetFogColor(float r, float g, float b);
virtual void SetFogStart(float fogstart);
virtual void SetFogEnd(float fogend);