diff options
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 257 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Material.h | 3 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Material.py | 54 | ||||
-rw-r--r-- | source/blender/src/buttons_shading.c | 4 |
4 files changed, 306 insertions, 12 deletions
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 038ab5b4394..2f35e9e411f 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -161,6 +161,10 @@ #define EXPP_MAT_COMP_MIRR 6 #define EXPP_MAT_COMP_MIRG 7 #define EXPP_MAT_COMP_MIRB 8 +#define EXPP_MAT_COMP_SSSR 9 +#define EXPP_MAT_COMP_SSSG 10 +#define EXPP_MAT_COMP_SSSB 11 + #define IPOKEY_RGB 0 #define IPOKEY_ALPHA 1 @@ -172,6 +176,21 @@ #define IPOKEY_SIZE 13 #define IPOKEY_ALLMAPPING 11 +/* SSS Settings */ +#define EXPP_MAT_SSS_SCALE_MIN 0.001 +#define EXPP_MAT_SSS_SCALE_MAX 1000.0 +#define EXPP_MAT_SSS_RADIUS_MIN 0.0 +#define EXPP_MAT_SSS_RADIUS_MAX 10000.0 +#define EXPP_MAT_SSS_IOR_MIN 0.1 +#define EXPP_MAT_SSS_IOR_MAX 2.0 +#define EXPP_MAT_SSS_ERROR_MIN 0.0 +#define EXPP_MAT_SSS_ERROR_MAX 1.0 +#define EXPP_MAT_SSS_FRONT_MIN 0.0 +#define EXPP_MAT_SSS_FRONT_MAX 2.0 +#define EXPP_MAT_SSS_BACK_MIN 0.0 +#define EXPP_MAT_SSS_BACK_MAX 10.0 + + /*****************************************************************************/ /* Python API function prototypes for the Material module. */ /*****************************************************************************/ @@ -179,9 +198,6 @@ static PyObject *M_Material_New( PyObject * self, PyObject * args, PyObject * keywords ); static PyObject *M_Material_Get( PyObject * self, PyObject * args ); -/* Not exposed nor used */ -Material *GetMaterialByName( char *name ); - /*****************************************************************************/ /* The following string definitions are used for documentation strings. In */ /* Python these will be written to the console when doing a */ @@ -468,6 +484,7 @@ static int Material_setMode( BPy_Material * self, PyObject * value ); static int Material_setRGBCol( BPy_Material * self, PyObject * value ); static int Material_setSpecCol( BPy_Material * self, PyObject * value ); static int Material_setMirCol( BPy_Material * self, PyObject * value ); +static int Material_setSssCol( BPy_Material * self, PyObject * value ); static int Material_setColorComponent( BPy_Material * self, PyObject * value, void * closure ); static int Material_setAmb( BPy_Material * self, PyObject * value ); @@ -515,6 +532,17 @@ static int Material_setRms( BPy_Material * self, PyObject * value ); static int Material_setFilter( BPy_Material * self, PyObject * value ); static int Material_setTranslucency( BPy_Material * self, PyObject * value ); +static int Material_setSssEnable( BPy_Material * self, PyObject * value ); +static int Material_setSssScale( BPy_Material * self, PyObject * value ); +static int Material_setSssRadius( BPy_Material * self, PyObject * value, void * type ); +static int Material_setSssIOR( BPy_Material * self, PyObject * value ); +static int Material_setSssError( BPy_Material * self, PyObject * value ); +static int Material_setSssColorBlend( BPy_Material * self, PyObject * value ); +static int Material_setSssTexScatter( BPy_Material * self, PyObject * value ); +static int Material_setSssFront( BPy_Material * self, PyObject * value ); +static int Material_setSssBack( BPy_Material * self, PyObject * value ); +static int Material_setSssBack( BPy_Material * self, PyObject * value ); + static PyObject *Material_getColorComponent( BPy_Material * self, void * closure ); @@ -530,6 +558,7 @@ static PyObject *Material_getRGBCol( BPy_Material * self ); /*static PyObject *Material_getAmbCol(BPy_Material *self);*/ static PyObject *Material_getSpecCol( BPy_Material * self ); static PyObject *Material_getMirCol( BPy_Material * self ); +static PyObject *Material_getSssCol( BPy_Material * self ); static PyObject *Material_getAmb( BPy_Material * self ); static PyObject *Material_getEmit( BPy_Material * self ); static PyObject *Material_getAlpha( BPy_Material * self ); @@ -574,6 +603,16 @@ static PyObject *Material_getFresnelTransFac( BPy_Material * self ); static PyObject *Material_getRigidBodyFriction( BPy_Material * self ); static PyObject *Material_getRigidBodyRestitution( BPy_Material * self ); +static PyObject *Material_getSssEnable( BPy_Material * self ); +static PyObject *Material_getSssScale( BPy_Material * self ); +static PyObject *Material_getSssRadius( BPy_Material * self, void * type ); +static PyObject *Material_getSssIOR( BPy_Material * self ); +static PyObject *Material_getSssError( BPy_Material * self ); +static PyObject *Material_getSssColorBlend( BPy_Material * self ); +static PyObject *Material_getSssTexScatter( BPy_Material * self ); +static PyObject *Material_getSssFront( BPy_Material * self ); +static PyObject *Material_getSssBack( BPy_Material * self ); +static PyObject *Material_getSssBack( BPy_Material * self ); static PyObject *Material_getFilter( BPy_Material * self ); static PyObject *Material_getTranslucency( BPy_Material * self ); @@ -940,6 +979,22 @@ static PyGetSetDef BPy_Material_getseters[] = { (getter)Material_getColorComponent, (setter)Material_setColorComponent, "Mirror color blue component", (void *) EXPP_MAT_COMP_MIRB }, + {"sssCol", + (getter)Material_getSssCol, (setter)Material_setSssCol, + "Sss RGB color triplet", + NULL}, + {"sssR", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "SSS color red component", + (void *) EXPP_MAT_COMP_SSSR }, + {"sssG", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "SSS color green component", + (void *) EXPP_MAT_COMP_SSSG }, + {"sssB", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "SSS color blue component", + (void *) EXPP_MAT_COMP_SSSB }, {"mode", (getter)Material_getMode, (setter)Material_setMode, "Material mode bitmask", @@ -1064,6 +1119,52 @@ static PyGetSetDef BPy_Material_getseters[] = { (getter)Material_getColorband, (setter)Material_setColorband, "Set the light group for this material", (void *) 1}, + + /* SSS settings */ + {"enableSSS", + (getter)Material_getSssEnable, (setter)Material_setSssEnable, + "if true, SSS will be rendered for this material", + NULL}, + {"sssScale", + (getter)Material_getSssScale, (setter)Material_setSssScale, + "object scale for sss", + NULL}, + {"sssRadiusRed", + (getter)Material_getSssRadius, (setter)Material_setSssRadius, + "Mean red scattering path length", + (void *) 0}, + {"sssRadiusGreen", + (getter)Material_getSssRadius, (setter)Material_setSssRadius, + "Mean red scattering path length", + (void *) 1}, + {"sssRadiusBlue", + (getter)Material_getSssRadius, (setter)Material_setSssRadius, + "Mean red scattering path length", + (void *) 0}, + {"sssIOR", + (getter)Material_getSssIOR, (setter)Material_setSssIOR, + "index of refraction", + NULL}, + {"sssError", + (getter)Material_getSssError, (setter)Material_setSssError, + "Error", + NULL}, + {"sssColorBlend", + (getter)Material_getSssColorBlend, (setter)Material_setSssColorBlend, + "Blend factor for SSS Colors", + NULL}, + {"sssTextureScatter", + (getter)Material_getSssTexScatter, (setter)Material_setSssTexScatter, + "Texture scattering factor", + NULL}, + {"sssFont", + (getter)Material_getSssFront, (setter)Material_setSssFront, + "Front scattering weight", + NULL}, + {"sssBack", + (getter)Material_getSssBack, (setter)Material_setSssBack, + "Back scattering weight", + NULL}, {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ }; @@ -1170,6 +1271,7 @@ static void Material_dealloc( BPy_Material * self ) Py_DECREF( self->amb ); Py_DECREF( self->spec ); Py_DECREF( self->mir ); + Py_DECREF( self->sss ); PyObject_DEL( self ); } @@ -1181,7 +1283,7 @@ static void Material_dealloc( BPy_Material * self ) PyObject *Material_CreatePyObject( struct Material *mat ) { BPy_Material *pymat; - float *col[3], *amb[3], *spec[3], *mir[3]; + float *col[3], *amb[3], *spec[3], *mir[3], *sss[3]; pymat = ( BPy_Material * ) PyObject_NEW( BPy_Material, &Material_Type ); @@ -1207,16 +1309,22 @@ PyObject *Material_CreatePyObject( struct Material *mat ) mir[0] = &mat->mirr; mir[1] = &mat->mirg; mir[2] = &mat->mirb; + + sss[0] = &mat->sss_col[0]; + sss[1] = &mat->sss_col[1]; + sss[2] = &mat->sss_col[2]; pymat->col = ( BPy_rgbTuple * ) rgbTuple_New( col ); pymat->amb = ( BPy_rgbTuple * ) rgbTuple_New( amb ); pymat->spec = ( BPy_rgbTuple * ) rgbTuple_New( spec ); pymat->mir = ( BPy_rgbTuple * ) rgbTuple_New( mir ); + pymat->sss = ( BPy_rgbTuple * ) rgbTuple_New( sss ); Py_INCREF(pymat->col); Py_INCREF(pymat->amb); Py_INCREF(pymat->spec); Py_INCREF(pymat->mir); + Py_INCREF(pymat->sss); return ( PyObject * ) pymat; } @@ -1273,6 +1381,11 @@ static PyObject *Material_getMirCol( BPy_Material * self ) return rgbTuple_getCol( self->mir ); } +static PyObject *Material_getSssCol( BPy_Material * self ) +{ + return rgbTuple_getCol( self->sss ); +} + static PyObject *Material_getSpecShader( BPy_Material * self ) { PyObject *attr = PyInt_FromLong( ( long ) self->material->spec_shader ); @@ -1765,7 +1878,51 @@ static PyObject* Material_getRigidBodyRestitution( BPy_Material * self ) "couldn't get Material.reflect" ); } +/* SSS */ +static PyObject* Material_getSssEnable( BPy_Material * self ) +{ + return EXPP_getBitfield( &self->material->sss_flag, MA_DIFF_SSS, 'h' ); +} + +static PyObject* Material_getSssScale( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_scale ); +} + +static PyObject* Material_getSssRadius( BPy_Material * self, void * type ) +{ + return PyFloat_FromDouble( ( double ) (self->material->sss_radius[(int)type]) ); +} +static PyObject* Material_getSssIOR( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_ior); +} + +static PyObject* Material_getSssError( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_error); +} + +static PyObject* Material_getSssColorBlend( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_colfac); +} + +static PyObject* Material_getSssTexScatter( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_texfac); +} + +static PyObject* Material_getSssFront( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_front); +} + +static PyObject* Material_getSssBack( BPy_Material * self ) +{ + return PyFloat_FromDouble( ( double ) self->material->sss_back); +} static PyObject *Material_getTextures( BPy_Material * self ) { @@ -1929,6 +2086,11 @@ static int Material_setMirCol( BPy_Material * self, PyObject * value ) return rgbTuple_setCol( self->mir, value ); } +static int Material_setSssCol( BPy_Material * self, PyObject * value ) +{ + return rgbTuple_setCol( self->sss, value ); +} + static int Material_setColorComponent( BPy_Material * self, PyObject * value, void * closure ) { @@ -1969,13 +2131,24 @@ static int Material_setColorComponent( BPy_Material * self, PyObject * value, case EXPP_MAT_COMP_MIRB: self->material->mirb = param; return 0; + case EXPP_MAT_COMP_SSSR: + self->material->sss_col[0] = param; + return 0; + case EXPP_MAT_COMP_SSSG: + self->material->sss_col[1] = param; + return 0; + case EXPP_MAT_COMP_SSSB: + self->material->sss_col[2] = param; + return 0; } return EXPP_ReturnIntError( PyExc_RuntimeError, "unknown color component specified" ); } +/*#define setFloatWrapper(val, min, max) {return EXPP_setFloatClamped ( value, &self->material->#val, #min, #max}*/ + static int Material_setAmb( BPy_Material * self, PyObject * value ) -{ +{ return EXPP_setFloatClamped ( value, &self->material->amb, EXPP_MAT_AMB_MIN, EXPP_MAT_AMB_MAX ); @@ -2276,6 +2449,71 @@ static int Material_setTranslucency( BPy_Material * self, PyObject * value ) EXPP_MAT_TRANSLUCENCY_MAX ); } +/* SSS */ +static int Material_setSssEnable( BPy_Material * self, PyObject * value ) +{ + return EXPP_setBitfield( value, &self->material->sss_flag, MA_DIFF_SSS, 'h' ); +} + +static int Material_setSssScale( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_scale, + EXPP_MAT_SSS_SCALE_MIN, + EXPP_MAT_SSS_SCALE_MAX); +} + +static int Material_setSssRadius( BPy_Material * self, PyObject * value, void *type ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_radius[(int)type], + EXPP_MAT_SSS_RADIUS_MIN, + EXPP_MAT_SSS_RADIUS_MAX); +} + +static int Material_setSssIOR( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_ior, + EXPP_MAT_SSS_IOR_MIN, + EXPP_MAT_SSS_IOR_MAX); +} + +static int Material_setSssError( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_error, + EXPP_MAT_SSS_IOR_MIN, + EXPP_MAT_SSS_IOR_MAX); +} + +static int Material_setSssColorBlend( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_colfac, + 0.0, + 1.0); +} + +static int Material_setSssTexScatter( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_texfac, + 0.0, + 1.0); +} + +static int Material_setSssFront( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_front, + EXPP_MAT_SSS_FRONT_MIN, + EXPP_MAT_SSS_FRONT_MAX); +} + +static int Material_setSssBack( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->sss_back, + EXPP_MAT_SSS_BACK_MIN, + EXPP_MAT_SSS_BACK_MAX); +} + + + + static PyObject *Material_setTexture( BPy_Material * self, PyObject * args ) { int texnum; @@ -2721,6 +2959,15 @@ static PyObject *Material_getColorComponent( BPy_Material * self, case EXPP_MAT_COMP_MIRB: attr = PyFloat_FromDouble( ( double ) self->material->mirb ); break; + case EXPP_MAT_COMP_SSSR: + attr = PyFloat_FromDouble( ( double ) self->material->sss_col[0] ); + break; + case EXPP_MAT_COMP_SSSG: + attr = PyFloat_FromDouble( ( double ) self->material->sss_col[1] ); + break; + case EXPP_MAT_COMP_SSSB: + attr = PyFloat_FromDouble( ( double ) self->material->sss_col[2] ); + break; default: return EXPP_ReturnPyObjError( PyExc_RuntimeError, "unknown color component specified" ); diff --git a/source/blender/python/api2_2x/Material.h b/source/blender/python/api2_2x/Material.h index e939b95a921..c4061f795c7 100644 --- a/source/blender/python/api2_2x/Material.h +++ b/source/blender/python/api2_2x/Material.h @@ -45,8 +45,7 @@ typedef struct { PyObject_HEAD Material * material; /* libdata must be second */ - BPy_rgbTuple *col, *amb, *spec, *mir; - + BPy_rgbTuple *col, *amb, *spec, *mir, *sss; } BPy_Material; extern PyTypeObject Material_Type; /* The Material PyType Object */ diff --git a/source/blender/python/api2_2x/doc/Material.py b/source/blender/python/api2_2x/doc/Material.py index 5fc09edde95..639c33b707f 100644 --- a/source/blender/python/api2_2x/doc/Material.py +++ b/source/blender/python/api2_2x/doc/Material.py @@ -187,18 +187,33 @@ class Material: @ivar ipo: Material Ipo data. Contains the Ipo if one is assigned to the object, None otherwise. Setting to None clears the current Ipo. @type ipo: Blender Ipo - @ivar mirB: Mirror color (L{mirCol}) blue component. - Value is clamped to the range [0.0,1.0]. - @type mirB: float + @ivar mirCol: Mirror RGB color triplet. Components are clamped to the range [0.0,1.0]. @type mirCol: list of 3 floats + @ivar mirB: Mirror color (L{mirCol}) blue component. + Value is clamped to the range [0.0,1.0]. + @type mirB: float @ivar mirG: Mirror color (L{mirCol}) green component. Value is clamped to the range [0.0,1.0]. @type mirG: float @ivar mirR: Mirror color (L{mirCol}) red component. Value is clamped to the range [0.0,1.0]. @type mirR: float + + @ivar sssCol: SubSufrace scattering RGB color triplet. + Components are clamped to the range [0.0,1.0]. + @type sssCol: list of 3 floats + @ivar sssB: SubSufrace scattering color (L{sssCol}) blue component. + Value is clamped to the range [0.0,1.0]. + @type sssB: float + @ivar sssG: SubSufrace scattering color (L{sssCol}) green component. + Value is clamped to the range [0.0,1.0]. + @type sssG: float + @ivar sssR: SubSufrace scattering color (L{sssCol}) red component. + Value is clamped to the range [0.0,1.0]. + @type sssR: float + @ivar mode: Mode mode bitfield. See L{the Modes dictionary<Modes>} keys and descriptions. @type mode: int @ivar nFlares: Number of subflares with halo. @@ -296,6 +311,39 @@ class Material: The colorband can have between 1 and 31 colors. @type colorbandSpecular: list + @ivar enableSSS: If True, subsufrace scattering will be rendered on this material. + @type enableSSS: bool + @ivar sssScale: If True, subsufrace scattering will be rendered on this material. + Value is clamped to the range [0.1,1000.0]. + @type sssScale: bool + @ivar sssRadiusRed: Mean red scattering path length. + Value is clamped to the range [0.0,10000.0]. + @type sssRadiusRed: float + @ivar sssRadiusGreen: Mean green scattering path length. + Value is clamped to the range [0.0,10000.0]. + @type sssRadiusGreen: float + @ivar sssRadiusBlue: Mean blue scattering path length. + Value is clamped to the range [0.0,10000.0]. + @type sssRadiusBlue: float + @ivar sssIOR: Refraction index. + Value is clamped to the range [0.1,2.0]. + @type sssIOR: float + @ivar sssError: Error allowance for the calculation (a low value is slower). + Value is clamped to the range [0.0,10.0]. + @type sssError: float + @ivar sssColorBlend: Blend factor for SSS colors. + Value is clamped to the range [0.0,1.0]. + @type sssColorBlend: float + @ivar sssTextureScatter: Texture scattering factor. + Value is clamped to the range [0.0,1.0]. + @type sssTextureScatter: float + @ivar sssFront: Front scattering weight. + Value is clamped to the range [0.0,2.0]. + @type sssFront: float + @ivar sssBack: Back scattering weight + Value is clamped to the range [0.0,10.0]. + @type sssBack: float + @warning: Most member variables assume values in some [Min, Max] interval. When trying to set them, the given parameter will be clamped to lie in that range: if val < Min, then val = Min, if val > Max, then val = Max. diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c index b290857c23d..4572e104caf 100644 --- a/source/blender/src/buttons_shading.c +++ b/source/blender/src/buttons_shading.c @@ -3340,12 +3340,12 @@ static void material_panel_sss(Material *ma) uiBlockEndAlign(block); bt=uiDefButF(block, NUM, B_MATPRV, "IOR:", 10,60,145,20, - &ma->sss_ior, 0.1, 2, 1, 3, "Index of refraction"); + &ma->sss_ior, 0.1, 2, 1, 3, "Index of refraction (higher values are denser)"); uiButSetFunc(bt, material_sss_custom_set_cb, ma, NULL); uiBlockBeginAlign(block); uiDefButF(block, NUM, B_MATPRV, "Error:", 10,30,145,20, - &ma->sss_error, 0.0001, 10, 1, 3, "Error"); + &ma->sss_error, 0.0001, 10, 1, 3, "Error tolerance (low values are slower and higher quality)"); uiBlockEndAlign(block); uiBlockBeginAlign(block); |