2012-09-19 15:15:01 +00:00
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
# include "platform/platform.h"
# include "materials/materialDefinition.h"
# include "console/consoleTypes.h"
2014-11-04 03:42:51 +00:00
# include "console/engineAPI.h"
2012-09-19 15:15:01 +00:00
# include "math/mathTypes.h"
# include "materials/materialManager.h"
# include "sceneData.h"
# include "gfx/sim/cubemapData.h"
# include "gfx/gfxCubemap.h"
# include "math/mathIO.h"
# include "materials/matInstance.h"
# include "sfx/sfxTrack.h"
# include "sfx/sfxTypes.h"
# include "core/util/safeDelete.h"
2014-12-21 20:07:42 +00:00
# include "T3D/accumulationVolume.h"
2019-05-13 05:28:23 +00:00
# include "gui/controls/guiTreeViewCtrl.h"
2021-08-10 03:08:55 +00:00
# include <console/persistenceManager.h>
2025-03-09 16:53:23 +00:00
# include "console/typeValidators.h"
2021-07-19 06:07:08 +00:00
IMPLEMENT_CONOBJECT ( Material ) ;
ConsoleDocClass ( Material ,
" @brief A material in Torque 3D is a data structure that describes a surface. \n \n "
" It contains many different types of information for rendering properties. "
" Torque 3D generates shaders from Material definitions. The shaders are compiled "
" at runtime and output into the example/shaders directory. Any errors or warnings "
" generated from compiling the procedurally generated shaders are output to the console "
" as well as the output window in the Visual C IDE. \n \n "
" @tsexample \n "
" singleton Material(DECAL_scorch) \n "
" { \n "
" baseTex[0] = \" ./scorch_decal.png \" ; \n "
" vertColor[ 0 ] = true; \n \n "
" translucent = true; \n "
" translucentBlendOp = None; \n "
" translucentZWrite = true; \n "
" alphaTest = true; \n "
" alphaRef = 84; \n "
" }; \n "
" @endtsexample \n \n "
" @see Rendering \n "
" @see ShaderData \n "
" @ingroup GFX \n " ) ;
ImplementBitfieldType ( MaterialAnimType ,
2012-09-19 15:15:01 +00:00
" The type of animation effect to apply to this material. \n "
" @ingroup GFX \n \n " )
2025-03-07 01:04:22 +00:00
{ Material : : Scroll , " $Scroll " , " Scroll the material along the X/Y axis. \n " } ,
{ Material : : Rotate , " $Rotate " , " Rotate the material around a point. \n " } ,
{ Material : : Wave , " $Wave " , " Warps the material with an animation using Sin, Triangle or Square mathematics. \n " } ,
{ Material : : Scale , " $Scale " , " Scales the material larger and smaller with a pulsing effect. \n " } ,
{ Material : : Sequence , " $Sequence " , " Enables the material to have multiple frames of animation in its imagemap. \n " }
2012-09-19 15:15:01 +00:00
EndImplementBitfieldType ;
2021-07-19 06:07:08 +00:00
ImplementEnumType ( MaterialBlendOp ,
2012-09-19 15:15:01 +00:00
" The type of graphical blending operation to apply to this material \n "
" @ingroup GFX \n \n " )
2025-03-07 02:55:40 +00:00
{ Material : : None , " None " , " Disable blending for this material. " } ,
2021-07-19 06:07:08 +00:00
{ Material : : Mul , " Mul " , " Multiplicative blending. " } ,
{ Material : : PreMul , " PreMul " , " Premultiplied alpha. " } ,
{ Material : : Add , " Add " , " Adds the color of the material to the frame buffer with full alpha for each pixel. " } ,
{ Material : : AddAlpha , " AddAlpha " , " The color is modulated by the alpha channel before being added to the frame buffer. " } ,
{ Material : : Sub , " Sub " , " Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect. " } ,
{ Material : : LerpAlpha , " LerpAlpha " , " Linearly interpolates between Material color and frame buffer color based on alpha. " }
2012-09-19 15:15:01 +00:00
EndImplementEnumType ;
2021-07-19 06:07:08 +00:00
ImplementEnumType ( MaterialWaveType ,
" When using the Wave material animation, one of these Wave Types will be used to determine the type of wave to display. \n "
2012-09-19 15:15:01 +00:00
" @ingroup GFX \n " )
2021-07-19 06:07:08 +00:00
{
Material : : Sin , " Sin " , " Warps the material along a curved Sin Wave. "
} ,
{ Material : : Triangle , " Triangle " , " Warps the material along a sharp Triangle Wave. " } ,
{ Material : : Square , " Square " , " Warps the material along a wave which transitions between two oppposite states. As a Square Wave, the transition is quick and sudden. " } ,
EndImplementEnumType ;
2012-09-19 15:15:01 +00:00
bool Material : : sAllowTextureTargetAssignment = false ;
2021-07-19 06:07:08 +00:00
GFXCubemap * Material : : GetNormalizeCube ( )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( smNormalizeCube )
2012-09-19 15:15:01 +00:00
return smNormalizeCube ;
smNormalizeCube = GFX - > createCubemap ( ) ;
smNormalizeCube - > initNormalize ( 64 ) ;
return smNormalizeCube ;
}
GFXCubemapHandle Material : : smNormalizeCube ;
2020-05-11 20:59:22 +00:00
2012-09-19 15:15:01 +00:00
Material : : Material ( )
{
2021-07-19 06:07:08 +00:00
for ( U32 i = 0 ; i < MAX_STAGES ; i + + )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
mDiffuse [ i ] . set ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
2017-06-23 16:36:20 +00:00
mDiffuseMapSRGB [ i ] = true ;
2012-09-19 15:15:01 +00:00
2020-09-30 18:51:12 +00:00
mRoughness [ i ] = 1.0f ;
2018-09-16 01:19:57 +00:00
mMetalness [ i ] = 0.0f ;
2021-07-19 06:07:08 +00:00
mIsSRGb [ i ] = false ;
2018-09-16 01:19:57 +00:00
2022-12-03 14:54:30 +00:00
mAOChan [ i ] = 0 ;
mInvertRoughness [ i ] = false ;
mRoughnessChan [ i ] = 1 ;
2018-09-16 01:19:57 +00:00
mMetalChan [ i ] = 2 ;
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
mAccuEnabled [ i ] = false ;
mAccuScale [ i ] = 1.0f ;
2014-12-21 20:07:42 +00:00
mAccuDirection [ i ] = 1.0f ;
2021-07-19 06:07:08 +00:00
mAccuStrength [ i ] = 0.6f ;
mAccuCoverage [ i ] = 0.9f ;
mAccuSpecular [ i ] = 16.0f ;
2012-09-19 15:15:01 +00:00
mParallaxScale [ i ] = 0.0f ;
mVertLit [ i ] = false ;
2021-07-19 06:07:08 +00:00
mVertColor [ i ] = false ;
2012-09-19 15:15:01 +00:00
mGlow [ i ] = false ;
2022-12-29 19:38:30 +00:00
mReceiveShadows [ i ] = true ;
2023-02-15 02:57:44 +00:00
mIgnoreLighting [ i ] = false ;
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
mDetailScale [ i ] . set ( 2.0f , 2.0f ) ;
2012-09-19 15:15:01 +00:00
mDetailNormalMapStrength [ i ] = 1.0f ;
mMinnaertConstant [ i ] = - 1.0f ;
mSubSurface [ i ] = false ;
2021-07-19 06:07:08 +00:00
mSubSurfaceColor [ i ] . set ( 1.0f , 0.2f , 0.2f , 1.0f ) ;
2012-09-19 15:15:01 +00:00
mSubSurfaceRolloff [ i ] = 0.2f ;
2021-07-19 06:07:08 +00:00
2012-09-19 15:15:01 +00:00
mAnimFlags [ i ] = 0 ;
2021-07-19 06:07:08 +00:00
mScrollDir [ i ] . set ( 0.0f , 0.0f ) ;
2012-09-19 15:15:01 +00:00
mScrollSpeed [ i ] = 0.0f ;
2021-07-19 06:07:08 +00:00
mScrollOffset [ i ] . set ( 0.0f , 0.0f ) ;
2012-09-19 15:15:01 +00:00
mRotSpeed [ i ] = 0.0f ;
2021-07-19 06:07:08 +00:00
mRotPivotOffset [ i ] . set ( 0.0f , 0.0f ) ;
2012-09-19 15:15:01 +00:00
mRotPos [ i ] = 0.0f ;
mWavePos [ i ] = 0.0f ;
mWaveFreq [ i ] = 0.0f ;
mWaveAmp [ i ] = 0.0f ;
mWaveType [ i ] = 0 ;
mSeqFramePerSec [ i ] = 0.0f ;
mSeqSegSize [ i ] = 0.0f ;
The final step (barring any overlooked missing bits, requested refactors, and of course, rolling in dependencies already submitted as PRs) consists of:
renderPrePassMgr.cpp related:
A) shifting .addFeature( MFT_XYZ); calls from ProcessedShaderMaterial::_determineFeatures to ProcessedPrePassMaterial::_determineFeatures
B) mimicking the "// set the XXX if different" entries from RenderMeshMgr::render in RenderPrePassMgr::render
C) fleshing out ProcessedPrePassMaterial::getNumStages() so that it shares a 1:1 correlation with ProcessedShaderMaterial::getNumStages()
D) causing inline void Swizzle<T, mapLength>::ToBuffer( void *destination, const void *source, const dsize_t size ) to silently fail rather than fatally assert if a source or destination buffer is not yet ready to be filled. (support for #customTarget scripted render targets)
Reflections:
A) removing reflectRenderState.disableAdvancedLightingBins(true); entries. this would otherwise early out from prepass and provide no color data whatsoever.
B) removing the fd.features.addFeature( MFT_ForwardShading ); entry forcing all materials to be forward lit when reflected.
C) 2 things best described bluntly as working hacks:
C1) when reflected, a scattersky is rotated PI along it's z then x axis in order to draw properly.
C2) along similar lines, in terraincellmaterial, we shut off culling if it's a prepass material.
Skies: scattersky is given a pair of rotations for reflection purposes, all sky objects are given a z value for depth testing.
2016-02-16 08:50:49 +00:00
// Deferred Shading
mMatInfoFlags [ i ] = 0.0f ;
2020-05-13 07:10:11 +00:00
2019-10-22 20:11:39 +00:00
mGlowMul [ i ] = 0.0f ;
2012-09-19 15:15:01 +00:00
}
dMemset ( mCellIndex , 0 , sizeof ( mCellIndex ) ) ;
dMemset ( mCellLayout , 0 , sizeof ( mCellLayout ) ) ;
dMemset ( mCellSize , 0 , sizeof ( mCellSize ) ) ;
dMemset ( mNormalMapAtlas , 0 , sizeof ( mNormalMapAtlas ) ) ;
2019-11-06 06:23:07 +00:00
dMemset ( mUseAnisotropic , 1 , sizeof ( mUseAnisotropic ) ) ;
2012-09-19 15:15:01 +00:00
mImposterLimits = Point4F : : Zero ;
mDoubleSided = false ;
mTranslucent = false ;
2022-08-15 21:50:06 +00:00
mTranslucentBlendOp = PreMul ;
2012-09-19 15:15:01 +00:00
mTranslucentZWrite = false ;
mAlphaTest = false ;
mAlphaRef = 1 ;
mCastShadows = true ;
mPlanarReflection = false ;
mCubemapData = NULL ;
2021-10-05 00:04:21 +00:00
mDynamicCubemap = false ;
2012-09-19 15:15:01 +00:00
mLastUpdateTime = 0 ;
mAutoGenerated = false ;
mShowDust = false ;
mShowFootprints = true ;
2021-07-19 06:07:08 +00:00
dMemset ( mEffectColor , 0 , sizeof ( mEffectColor ) ) ;
2012-09-19 15:15:01 +00:00
2022-03-31 23:58:06 +00:00
mEffectColor [ 0 ] = LinearColorF : : WHITE ;
mEffectColor [ 1 ] = LinearColorF : : WHITE ;
2012-09-19 15:15:01 +00:00
mFootstepSoundId = - 1 ; mImpactSoundId = - 1 ;
2020-05-13 07:10:11 +00:00
mImpactFXIndex = - 1 ;
2021-10-15 00:09:20 +00:00
INIT_ASSET ( CustomFootstepSound ) ;
INIT_ASSET ( CustomImpactSound ) ;
2012-09-19 15:15:01 +00:00
mFriction = 0.0 ;
2021-07-19 06:07:08 +00:00
2012-09-19 15:15:01 +00:00
mDirectSoundOcclusion = 1.f ;
mReverbSoundOcclusion = 1.0 ;
}
2025-03-09 16:53:23 +00:00
IRangeValidator bmpChanRange ( 0 , 3 ) ;
FRangeValidator glowMulRange ( 0.0f , 20.0f ) ;
FRangeValidator parallaxScaleRange ( 0.0f , 4.0f ) ;
FRangeValidator scrollSpeedRange ( 0.0f , 10.0f ) ;
FRangeValidator waveFreqRange ( 0.0f , 10.0f ) ;
2020-05-11 20:59:22 +00:00
2012-09-19 15:15:01 +00:00
void Material : : initPersistFields ( )
{
2023-01-27 07:13:15 +00:00
docsURL ;
2012-09-19 15:15:01 +00:00
addField ( " mapTo " , TypeRealString , Offset ( mMapTo , Material ) ,
2021-07-19 06:07:08 +00:00
" Used to map this material to the material name used by TSShape. " ) ;
addArray ( " Stages " , MAX_STAGES ) ;
2024-02-04 05:50:32 +00:00
addGroup ( " Basic Texture Maps " ) ;
2024-12-27 12:53:04 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( DiffuseMap , MAX_STAGES , Material , " Albedo " ) ;
2024-02-04 05:50:32 +00:00
addField ( " diffuseColor " , TypeColorF , Offset ( mDiffuse , Material ) , MAX_STAGES ,
" This color is multiplied against the diffuse texture color. If no diffuse texture "
" is present this is the material color. " ) ;
addField ( " diffuseMapSRGB " , TypeBool , Offset ( mDiffuseMapSRGB , Material ) , MAX_STAGES ,
" Enable sRGB for the diffuse color texture map. " ) ;
2024-12-27 12:53:04 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( NormalMap , MAX_STAGES , Material , " NormalMap " ) ;
2024-02-04 05:50:32 +00:00
endGroup ( " Basic Texture Maps " ) ;
addGroup ( " Light Influence Maps " ) ;
2024-12-27 14:16:47 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( ORMConfigMap , MAX_STAGES , Material , " AO|Roughness|metalness map " ) ;
2024-02-04 05:50:32 +00:00
addField ( " isSRGb " , TypeBool , Offset ( mIsSRGb , Material ) , MAX_STAGES ,
" Substance Designer Workaround. " ) ;
2025-03-09 16:53:23 +00:00
addField ( " invertRoughness " , TypeBool , Offset ( mInvertRoughness , Material ) , MAX_STAGES ,
" Treat Roughness as Roughness " ) ;
2024-02-04 05:50:32 +00:00
2024-12-27 14:38:01 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( AOMap , MAX_STAGES , Material , " AOMap " ) ;
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( RoughMap , MAX_STAGES , Material , " RoughMap (also needs MetalMap) " ) ;
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( MetalMap , MAX_STAGES , Material , " MetalMap (also needs RoughMap) " ) ;
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( GlowMap , MAX_STAGES , Material , " GlowMap (needs Albedo) " ) ;
2025-03-24 20:07:06 +00:00
2025-03-09 16:53:23 +00:00
addFieldV ( " AOChan " , TypeRangedS32 , Offset ( mAOChan , Material ) , & bmpChanRange , MAX_STAGES ,
" The input channel AO maps use. " ) ;
addFieldV ( " roughness " , TypeRangedF32 , Offset ( mRoughness , Material ) , & CommonValidators : : F32_8BitPercent , MAX_STAGES ,
" The degree of roughness when not using a ORMConfigMap. " ) ;
addFieldV ( " roughnessChan " , TypeRangedS32 , Offset ( mRoughnessChan , Material ) , & bmpChanRange , MAX_STAGES ,
" The input channel roughness maps use. " ) ;
addFieldV ( " metalness " , TypeRangedF32 , Offset ( mMetalness , Material ) , & CommonValidators : : F32_8BitPercent , MAX_STAGES ,
" The degree of Metalness when not using a ORMConfigMap. " ) ;
addFieldV ( " metalChan " , TypeRangedS32 , Offset ( mMetalChan , Material ) , & bmpChanRange , MAX_STAGES ,
" The input channel metalness maps use. " ) ;
2024-02-04 05:50:32 +00:00
2025-03-09 16:53:23 +00:00
addFieldV ( " glowMul " , TypeRangedF32 , Offset ( mGlowMul , Material ) , & glowMulRange , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" glow mask multiplier " ) ;
endGroup ( " Light Influence Maps " ) ;
addGroup ( " Advanced Texture Maps " ) ;
2024-12-27 14:16:47 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( DetailMap , MAX_STAGES , Material , " DetailMap " ) ;
2024-02-04 05:50:32 +00:00
addField ( " detailScale " , TypePoint2F , Offset ( mDetailScale , Material ) , MAX_STAGES ,
" The scale factor for the detail map. " ) ;
2024-12-27 12:53:04 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( DetailNormalMap , MAX_STAGES , Material , " DetailNormalMap " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " detailNormalMapStrength " , TypeRangedF32 , Offset ( mDetailNormalMapStrength , Material ) , & CommonValidators : : PositiveFloat , MAX_STAGES ,
2025-03-24 20:07:06 +00:00
2024-02-04 05:50:32 +00:00
" Used to scale the strength of the detail normal map when blended with the base normal map. " ) ;
2024-12-27 14:16:47 +00:00
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( OverlayMap , MAX_STAGES , Material , " Overlay " ) ;
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( LightMap , MAX_STAGES , Material , " LightMap " ) ;
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR ( ToneMap , MAX_STAGES , Material , " ToneMap " ) ;
2024-02-04 05:50:32 +00:00
endGroup ( " Advanced Texture Maps " ) ;
addGroup ( " Accumulation Properties " ) ;
addProtectedField ( " accuEnabled " , TYPEID < bool > ( ) , Offset ( mAccuEnabled , Material ) ,
& _setAccuEnabled , & defaultProtectedGetFn , MAX_STAGES , " Accumulation texture. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " accuScale " , TypeRangedF32 , Offset ( mAccuScale , Material ) , & CommonValidators : : PositiveFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The scale that is applied to the accu map texture. You can use this to fit the texture to smaller or larger objects. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " accuDirection " , TypeRangedF32 , Offset ( mAccuDirection , Material ) , & CommonValidators : : DirFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The direction of the accumulation. Chose whether you want the accu map to go from top to bottom (ie. snow) or upwards (ie. mold). " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " accuStrength " , TypeRangedF32 , Offset ( mAccuStrength , Material ) , & CommonValidators : : NormalizedFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The strength of the accu map. This changes the transparency of the accu map texture. Make it subtle or add more contrast. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " accuCoverage " , TypeRangedF32 , Offset ( mAccuCoverage , Material ) , & CommonValidators : : NormalizedFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The coverage ratio of the accu map texture. Use this to make the entire shape pick up some of the accu map texture or none at all. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " accuSpecular " , TypeRangedF32 , Offset ( mAccuSpecular , Material ) , & CommonValidators : : NormalizedFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" Changes specularity to this value where the accumulated material is present. " ) ;
endGroup ( " Accumulation Properties " ) ;
addGroup ( " Lighting Properties " ) ;
addField ( " receiveShadows " , TypeBool , Offset ( mReceiveShadows , Material ) , MAX_STAGES ,
" Shadows being cast onto the material. " ) ;
addField ( " ignoreLighting " , TypeBool , Offset ( mIgnoreLighting , Material ) , MAX_STAGES ,
" Enables emissive lighting for the material. " ) ;
addField ( " glow " , TypeBool , Offset ( mGlow , Material ) , MAX_STAGES ,
" Enables rendering as glowing. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " parallaxScale " , TypeRangedF32 , Offset ( mParallaxScale , Material ) , & parallaxScaleRange , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" Enables parallax mapping and defines the scale factor for the parallax effect. Typically "
" this value is less than 0.4 else the effect breaks down. " ) ;
addField ( " useAnisotropic " , TypeBool , Offset ( mUseAnisotropic , Material ) , MAX_STAGES ,
" Use anisotropic filtering for the textures of this stage. " ) ;
addField ( " vertLit " , TypeBool , Offset ( mVertLit , Material ) , MAX_STAGES ,
" If true the vertex color is used for lighting. " ) ;
addField ( " vertColor " , TypeBool , Offset ( mVertColor , Material ) , MAX_STAGES ,
" If enabled, vertex colors are premultiplied with diffuse colors. " ) ;
2025-03-09 16:53:23 +00:00
/* presently unsupported directly. advice would be to use a glowmap+glowmul to fine tune backscatter effects
2024-02-04 05:50:32 +00:00
addField ( " subSurface " , TypeBool , Offset ( mSubSurface , Material ) , MAX_STAGES ,
" Enables the subsurface scattering approximation. " ) ;
addField ( " minnaertConstant " , TypeF32 , Offset ( mMinnaertConstant , Material ) , MAX_STAGES ,
" The Minnaert shading constant value. Must be greater than 0 to enable the effect. " ) ;
addField ( " subSurfaceColor " , TypeColorF , Offset ( mSubSurfaceColor , Material ) , MAX_STAGES ,
" The color used for the subsurface scattering approximation. " ) ;
addField ( " subSurfaceRolloff " , TypeF32 , Offset ( mSubSurfaceRolloff , Material ) , MAX_STAGES ,
" The 0 to 1 rolloff factor used in the subsurface scattering approximation. " ) ;
2025-03-09 16:53:23 +00:00
*/
2024-02-04 05:50:32 +00:00
endGroup ( " Lighting Properties " ) ;
addGroup ( " Animation Properties " ) ;
2024-05-04 14:56:04 +00:00
addField ( " animFlags " , TypeMaterialAnimType , Offset ( mAnimFlags , Material ) , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The types of animation to play on this material. " ) ;
addField ( " scrollDir " , TypePoint2F , Offset ( mScrollDir , Material ) , MAX_STAGES ,
" The scroll direction in UV space when scroll animation is enabled. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " scrollSpeed " , TypeRangedF32 , Offset ( mScrollSpeed , Material ) , & scrollSpeedRange , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The speed to scroll the texture in UVs per second when scroll animation is enabled. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " rotSpeed " , TypeRangedF32 , Offset ( mRotSpeed , Material ) , & CommonValidators : : DegreeRange , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The speed to rotate the texture in degrees per second when rotation animation is enabled. " ) ;
addField ( " rotPivotOffset " , TypePoint2F , Offset ( mRotPivotOffset , Material ) , MAX_STAGES ,
" The piviot position in UV coordinates to center the rotation animation. " ) ;
addField ( " waveType " , TYPEID < WaveType > ( ) , Offset ( mWaveType , Material ) , MAX_STAGES ,
" The type of wave animation to perform when wave animation is enabled. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " waveFreq " , TypeRangedF32 , Offset ( mWaveFreq , Material ) , & waveFreqRange , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The wave frequency when wave animation is enabled. " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " waveAmp " , TypeRangedF32 , Offset ( mWaveAmp , Material ) , & CommonValidators : : NormalizedFloat , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" The wave amplitude when wave animation is enabled. " ) ;
addField ( " sequenceFramePerSec " , TypeF32 , Offset ( mSeqFramePerSec , Material ) , MAX_STAGES ,
" The number of frames per second for frame based sequence animations if greater than zero. " ) ;
addField ( " sequenceSegmentSize " , TypeF32 , Offset ( mSeqSegSize , Material ) , MAX_STAGES ,
" The size of each frame in UV units for sequence animations. " ) ;
// Texture atlasing
addField ( " cellIndex " , TypePoint2I , Offset ( mCellIndex , Material ) , MAX_STAGES ,
" @internal " ) ;
addField ( " cellLayout " , TypePoint2I , Offset ( mCellLayout , Material ) , MAX_STAGES ,
" @internal " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " cellSize " , TypeRangedS32 , Offset ( mCellSize , Material ) , & CommonValidators : : PositiveInt , MAX_STAGES ,
2024-02-04 05:50:32 +00:00
" @internal " ) ;
addField ( " bumpAtlas " , TypeBool , Offset ( mNormalMapAtlas , Material ) , MAX_STAGES ,
" @internal " ) ;
endGroup ( " Animation Properties " ) ;
2021-07-19 06:07:08 +00:00
2024-02-04 05:50:32 +00:00
endArray ( " Stages " ) ;
2021-07-19 06:07:08 +00:00
2024-02-04 05:50:32 +00:00
addGroup ( " Advanced Properties (All Layers) " ) ;
addField ( " doubleSided " , TypeBool , Offset ( mDoubleSided , Material ) ,
" Disables backface culling casing surfaces to be double sided. "
" Note that the lighting on the backside will be a mirror of the front "
" side of the surface. " ) ;
addField ( " castShadows " , TypeBool , Offset ( mCastShadows , Material ) ,
" If set to false the lighting system will not cast shadows from this material. " ) ;
addField ( " planarReflection " , TypeBool , Offset ( mPlanarReflection , Material ) , " @internal " ) ;
addField ( " translucent " , TypeBool , Offset ( mTranslucent , Material ) ,
" If true this material is translucent blended. " ) ;
addField ( " translucentBlendOp " , TYPEID < BlendOp > ( ) , Offset ( mTranslucentBlendOp , Material ) ,
" The type of blend operation to use when the material is translucent. " ) ;
addField ( " translucentZWrite " , TypeBool , Offset ( mTranslucentZWrite , Material ) ,
" If enabled and the material is translucent it will write into the depth buffer. " ) ;
addField ( " alphaTest " , TypeBool , Offset ( mAlphaTest , Material ) ,
" Enables alpha test when rendering the material. \n @see alphaRef \n " ) ;
2025-03-09 16:53:23 +00:00
addFieldV ( " alphaRef " , TypeRangedS32 , Offset ( mAlphaRef , Material ) , & CommonValidators : : S32_8BitCap ,
2024-02-04 05:50:32 +00:00
" The alpha reference value for alpha testing. Must be between 0 to 255. \n @see alphaTest \n " ) ;
addField ( " cubemap " , TypeRealString , Offset ( mCubemapName , Material ) ,
" The name of a CubemapData for environment mapping. " ) ;
addField ( " dynamicCubemap " , TypeBool , Offset ( mDynamicCubemap , Material ) ,
" Enables the material to use the dynamic cubemap from the ShapeBase object its applied to. " ) ;
endGroup ( " Advanced Properties (All Layers) " ) ;
addGroup ( " Behavioral (All Layers) " ) ;
addField ( " showFootprints " , TypeBool , Offset ( mShowFootprints , Material ) ,
" Whether to show player footprint decals on this material. \n \n "
" @see PlayerData::decalData " ) ;
addField ( " showDust " , TypeBool , Offset ( mShowDust , Material ) ,
" Whether to emit dust particles from a shape moving over the material. This is, for example, used by "
" vehicles or players to decide whether to show dust trails. " ) ;
addField ( " effectColor " , TypeColorF , Offset ( mEffectColor , Material ) , NUM_EFFECT_COLOR_STAGES ,
" If #showDust is true, this is the set of colors to use for the ParticleData of the dust "
" emitter. \n \n "
" @see ParticleData::colors " ) ;
addField ( " footstepSoundId " , TypeS32 , Offset ( mFootstepSoundId , Material ) ,
" What sound to play from the PlayerData sound list when the player walks over the material. -1 (default) to not play any sound. \n "
" \n "
" The IDs are: \n \n "
" - 0: PlayerData::FootSoftSound \n "
" - 1: PlayerData::FootHardSound \n "
" - 2: PlayerData::FootMetalSound \n "
" - 3: PlayerData::FootSnowSound \n "
" - 4: PlayerData::FootShallowSound \n "
" - 5: PlayerData::FootWadingSound \n "
" - 6: PlayerData::FootUnderwaterSound \n "
" - 7: PlayerData::FootBubblesSound \n "
" - 8: PlayerData::movingBubblesSound \n "
" - 9: PlayerData::waterBreathSound \n "
" - 10: PlayerData::impactSoftSound \n "
" - 11: PlayerData::impactHardSound \n "
" - 12: PlayerData::impactMetalSound \n "
" - 13: PlayerData::impactSnowSound \n "
" - 14: PlayerData::impactWaterEasy \n "
" - 15: PlayerData::impactWaterMedium \n "
" - 16: PlayerData::impactWaterHard \n "
" - 17: PlayerData::exitingWater \n " ) ;
INITPERSISTFIELD_SOUNDASSET ( CustomFootstepSound , Material ,
" The sound to play when the player walks over the material. If this is set, it overrides #footstepSoundId. This field is "
" useful for directly assigning custom footstep sounds to materials without having to rely on the PlayerData sound assignment. \n \n "
" @warn Be aware that materials are client-side objects. This means that the SFXTracks assigned to materials must be client-side, too. " ) ;
addField ( " impactSoundId " , TypeS32 , Offset ( mImpactSoundId , Material ) ,
" What sound to play from the PlayerData sound list when the player impacts on the surface with a velocity equal or greater "
" than PlayerData::groundImpactMinSpeed. \n \n "
" For a list of IDs, see #footstepSoundId " ) ;
addField ( " ImpactFXIndex " , TypeS32 , Offset ( mImpactFXIndex , Material ) ,
" What FX to play from the PlayerData sound list when the player impacts on the surface with a velocity equal or greater "
" than PlayerData::groundImpactMinSpeed. \n \n "
" For a list of IDs, see #impactFXId " ) ;
INITPERSISTFIELD_SOUNDASSET ( CustomImpactSound , Material ,
" The sound to play when the player impacts on the surface with a velocity equal or greater than PlayerData::groundImpactMinSpeed. "
" If this is set, it overrides #impactSoundId. This field is useful for directly assigning custom impact sounds to materials "
" without having to rely on the PlayerData sound assignment. \n \n "
" @warn Be aware that materials are client-side objects. This means that the SFXTracks assigned to materials must be client-side, too. " ) ;
//Deactivate these for the moment as they are not used.
#if 0
addField ( " friction " , TypeF32 , Offset ( mFriction , Material ) ) ;
addField ( " directSoundOcclusion " , TypeF32 , Offset ( mDirectSoundOcclusion , Material ) ) ;
addField ( " reverbSoundOcclusion " , TypeF32 , Offset ( mReverbSoundOcclusion , Material ) ) ;
# endif
endGroup ( " Behavioral (All Layers) " ) ;
2021-07-19 06:07:08 +00:00
// For backwards compatibility.
2025-03-09 16:53:23 +00:00
//
// They point at the new 'map' fields, but reads always return
// an empty string and writes only apply if the value is not empty.
//
2021-07-19 06:07:08 +00:00
addProtectedField ( " colorMultiply " , TypeColorF , Offset ( mDiffuse , Material ) ,
defaultProtectedSetNotEmptyFn , emptyStringProtectedGetFn , MAX_STAGES ,
" For backwards compatibility. \n @see diffuseColor \n " , AbstractClassRep : : FIELD_HideInInspectors ) ;
2012-09-19 15:15:01 +00:00
Parent : : initPersistFields ( ) ;
}
2021-07-19 06:07:08 +00:00
bool Material : : writeField ( StringTableEntry fieldname , const char * value )
{
2012-09-19 15:15:01 +00:00
// Never allow the old field names to be written.
2021-07-19 06:07:08 +00:00
if ( fieldname = = StringTable - > insert ( " baseTex " ) | |
fieldname = = StringTable - > insert ( " detailTex " ) | |
fieldname = = StringTable - > insert ( " overlayTex " ) | |
fieldname = = StringTable - > insert ( " bumpTex " ) | |
fieldname = = StringTable - > insert ( " envTex " ) | |
2022-01-30 17:50:16 +00:00
fieldname = = StringTable - > insert ( " colorMultiply " ) | |
fieldname = = StringTable - > insert ( " internalName " ) )
2012-09-19 15:15:01 +00:00
return false ;
2021-07-19 06:07:08 +00:00
return Parent : : writeField ( fieldname , value ) ;
2012-09-19 15:15:01 +00:00
}
bool Material : : onAdd ( )
{
if ( Parent : : onAdd ( ) = = false )
return false ;
2021-07-19 06:07:08 +00:00
mCubemapData = dynamic_cast < CubemapData * > ( Sim : : findObject ( mCubemapName ) ) ;
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
if ( mTranslucentBlendOp > = NumBlendTypes | | mTranslucentBlendOp < 0 )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
Con : : errorf ( " Invalid blend op in material: %s " , getName ( ) ) ;
2022-06-08 03:05:47 +00:00
mTranslucentBlendOp = PreMul ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
SimSet * matSet = MATMGR - > getMaterialSet ( ) ;
if ( matSet )
matSet - > addObject ( ( SimObject * ) this ) ;
2012-09-19 15:15:01 +00:00
// save the current script path for texture lookup later
2020-12-12 15:54:16 +00:00
const String scriptFile = Con : : getVariable ( " $Con::File " ) ; // current script file - local materials.tscript
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
String : : SizeType slash = scriptFile . find ( ' / ' , scriptFile . length ( ) , String : : Right ) ;
if ( slash ! = String : : NPos )
mPath = scriptFile . substr ( 0 , slash + 1 ) ;
//convert any non-assets we have
/*for (U32 i = 0; i < MAX_STAGES; i++)
{
AUTOCONVERT_IMAGEASSET_ARRAY ( DiffuseMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( OverlayMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( LightMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( ToneMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( DetailMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( ORMConfigMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( AOMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( RoughMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( MetalMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( GlowMap , i ) ;
AUTOCONVERT_IMAGEASSET_ARRAY ( DetailNormalMap , i ) ;
}
2012-09-19 15:15:01 +00:00
2019-06-03 07:47:30 +00:00
//bind any assets we have
for ( U32 i = 0 ; i < MAX_STAGES ; i + + )
{
2021-07-19 06:07:08 +00:00
LOAD_IMAGEASSET_ARRAY ( DiffuseMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( OverlayMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( LightMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( ToneMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( DetailMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( ORMConfigMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( AOMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( RoughMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( MetalMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( GlowMap , i ) ;
LOAD_IMAGEASSET_ARRAY ( DetailNormalMap , i ) ;
} */
inspectPostApply ( ) ;
2019-06-03 07:47:30 +00:00
2012-09-19 15:15:01 +00:00
_mapMaterial ( ) ;
return true ;
}
void Material : : onRemove ( )
{
smNormalizeCube = NULL ;
Parent : : onRemove ( ) ;
}
void Material : : inspectPostApply ( )
{
Parent : : inspectPostApply ( ) ;
// Reload the material instances which
// use this material.
2021-07-19 06:07:08 +00:00
if ( isProperlyAdded ( ) )
2012-09-19 15:15:01 +00:00
reload ( ) ;
}
bool Material : : isLightmapped ( ) const
{
bool ret = false ;
2021-07-19 06:07:08 +00:00
for ( U32 i = 0 ; i < MAX_STAGES ; i + + )
2024-12-27 14:16:47 +00:00
ret | = mLightMapAsset [ i ] . notNull ( ) | | mToneMapAsset [ i ] . notNull ( ) | | mVertLit [ i ] ;
2012-09-19 15:15:01 +00:00
return ret ;
}
void Material : : updateTimeBasedParams ( )
{
U32 lastTime = MATMGR - > getLastUpdateTime ( ) ;
F32 dt = MATMGR - > getDeltaTime ( ) ;
if ( mLastUpdateTime ! = lastTime )
{
for ( U32 i = 0 ; i < MAX_STAGES ; i + + )
{
mScrollOffset [ i ] + = mScrollDir [ i ] * mScrollSpeed [ i ] * dt ;
2020-12-13 01:07:01 +00:00
mScrollOffset [ i ] . x = mWrapF ( mScrollOffset [ i ] . x , 0.0 , 1.0 ) ;
mScrollOffset [ i ] . y = mWrapF ( mScrollOffset [ i ] . y , 0.0 , 1.0 ) ;
mRotPos [ i ] = mWrapF ( ( mRotPos [ i ] + ( mRotSpeed [ i ] * dt ) ) , 0.0 , 360.0 ) ;
mWavePos [ i ] = mWrapF ( ( mWavePos [ i ] + ( mWaveFreq [ i ] * dt ) ) , 0.0 , 1.0 ) ;
2012-09-19 15:15:01 +00:00
}
mLastUpdateTime = lastTime ;
}
}
void Material : : _mapMaterial ( )
{
2021-07-19 06:07:08 +00:00
if ( String ( getName ( ) ) . isEmpty ( ) )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
Con : : warnf ( " [Material::mapMaterial] - Cannot map unnamed Material " ) ;
2012-09-19 15:15:01 +00:00
return ;
}
// If mapTo not defined in script, try to use the base texture name instead
2021-07-19 06:07:08 +00:00
if ( mMapTo . isEmpty ( ) )
2012-09-19 15:15:01 +00:00
{
2024-12-27 12:53:04 +00:00
if ( mDiffuseMapAsset - > isNull ( ) )
2012-09-19 15:15:01 +00:00
return ;
2024-12-27 12:53:04 +00:00
else if ( mDiffuseMapAsset - > notNull ( ) )
2012-09-19 15:15:01 +00:00
{
2024-12-27 12:53:04 +00:00
mMapTo = mDiffuseMapAsset [ 0 ] - > getImageFile ( ) ;
2012-09-19 15:15:01 +00:00
}
}
// add mapping
2021-07-19 06:07:08 +00:00
MATMGR - > mapMaterial ( mMapTo , getName ( ) ) ;
2012-09-19 15:15:01 +00:00
}
BaseMatInstance * Material : : createMatInstance ( )
{
return new MatInstance ( * this ) ;
}
void Material : : flush ( )
{
2021-07-19 06:07:08 +00:00
MATMGR - > flushInstance ( this ) ;
2012-09-19 15:15:01 +00:00
}
void Material : : reload ( )
{
2021-07-19 06:07:08 +00:00
MATMGR - > reInitInstance ( this ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
void Material : : StageData : : getFeatureSet ( FeatureSet * outFeatures ) const
2012-09-19 15:15:01 +00:00
{
TextureTable : : ConstIterator iter = mTextures . begin ( ) ;
2021-07-19 06:07:08 +00:00
for ( ; iter ! = mTextures . end ( ) ; iter + + )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( iter - > value . isValid ( ) )
outFeatures - > addFeature ( * iter - > key ) ;
2012-09-19 15:15:01 +00:00
}
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , flush , void , ( ) , ,
" Flushes all material instances that use this material. " )
2012-09-19 15:15:01 +00:00
{
object - > flush ( ) ;
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , reload , void , ( ) , ,
" Reloads all material instances that use this material. " )
2012-09-19 15:15:01 +00:00
{
object - > reload ( ) ;
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , dumpInstances , void , ( ) , ,
" Dumps a formatted list of the currently allocated material instances for this material to the console. " )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
MATMGR - > dumpMaterialInstances ( object ) ;
2012-09-19 15:15:01 +00:00
}
2019-05-13 05:28:23 +00:00
DefineEngineMethod ( Material , getMaterialInstances , void , ( GuiTreeViewCtrl * matTree ) , ( nullAsType < GuiTreeViewCtrl * > ( ) ) ,
" Dumps a formatted list of the currently allocated material instances for this material to the console. " )
{
MATMGR - > getMaterialInstances ( object , matTree ) ;
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , getAnimFlags , const char * , ( U32 id ) , , " " )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
char * animFlags = Con : : getReturnBuffer ( 512 ) ;
2012-09-19 15:15:01 +00:00
2021-07-19 06:07:08 +00:00
if ( object - > mAnimFlags [ id ] & Material : : Scroll )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( String : : compare ( animFlags , " " ) = = 0 )
dStrcpy ( animFlags , " $Scroll " , 512 ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
if ( object - > mAnimFlags [ id ] & Material : : Rotate )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( String : : compare ( animFlags , " " ) = = 0 )
dStrcpy ( animFlags , " $Rotate " , 512 ) ;
else
dStrcat ( animFlags , " | $Rotate " , 512 ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
if ( object - > mAnimFlags [ id ] & Material : : Wave )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( String : : compare ( animFlags , " " ) = = 0 )
dStrcpy ( animFlags , " $Wave " , 512 ) ;
else
dStrcat ( animFlags , " | $Wave " , 512 ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
if ( object - > mAnimFlags [ id ] & Material : : Scale )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( String : : compare ( animFlags , " " ) = = 0 )
dStrcpy ( animFlags , " $Scale " , 512 ) ;
else
dStrcat ( animFlags , " | $Scale " , 512 ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
if ( object - > mAnimFlags [ id ] & Material : : Sequence )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
if ( String : : compare ( animFlags , " " ) = = 0 )
dStrcpy ( animFlags , " $Sequence " , 512 ) ;
else
dStrcat ( animFlags , " | $Sequence " , 512 ) ;
2012-09-19 15:15:01 +00:00
}
2021-07-19 06:07:08 +00:00
return animFlags ;
2012-09-19 15:15:01 +00:00
}
2021-10-26 03:54:19 +00:00
DefineEngineMethod ( Material , setAnimFlags , void , ( S32 id , const char * flags ) , ( 0 , " " ) , " setAnimFlags " )
{
object - > mAnimFlags [ id ] = 0 ;
if ( String ( flags ) . find ( " $Scroll " ) ! = String : : NPos )
object - > mAnimFlags [ id ] | = Material : : Scroll ;
if ( String ( flags ) . find ( " $Rotate " ) ! = String : : NPos )
object - > mAnimFlags [ id ] | = Material : : Rotate ;
if ( String ( flags ) . find ( " $Wave " ) ! = String : : NPos )
object - > mAnimFlags [ id ] | = Material : : Wave ;
if ( String ( flags ) . find ( " $Scale " ) ! = String : : NPos )
object - > mAnimFlags [ id ] | = Material : : Scale ;
if ( String ( flags ) . find ( " $Sequence " ) ! = String : : NPos )
object - > mAnimFlags [ id ] | = Material : : Sequence ;
//if we're still unset, see if they tried assigning a number
if ( object - > mAnimFlags [ id ] = = 0 )
object - > mAnimFlags [ id ] = dAtoi ( flags ) ;
2024-02-04 20:58:26 +00:00
//if we're *still* unset, make sure we've cleared all cases
if ( object - > mAnimFlags [ id ] = = 0 )
{
object - > mScrollOffset [ id ] . set ( 0.0f , 0.0f ) ;
object - > mRotPos [ id ] = 0.0f ;
object - > mWavePos [ id ] = 0.0f ;
}
2021-10-26 03:54:19 +00:00
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , getFilename , const char * , ( ) , , " Get filename of material " )
2012-09-19 15:15:01 +00:00
{
2021-07-19 06:07:08 +00:00
SimObject * material = static_cast < SimObject * > ( object ) ;
2012-09-19 15:15:01 +00:00
return material - > getFilename ( ) ;
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , isAutoGenerated , bool , ( ) , ,
" Returns true if this Material was automatically generated by MaterialList::mapMaterials() " )
2012-09-19 15:15:01 +00:00
{
return object - > isAutoGenerated ( ) ;
}
2021-07-19 06:07:08 +00:00
DefineEngineMethod ( Material , setAutoGenerated , void , ( bool isAutoGenerated ) , ,
" setAutoGenerated(bool isAutoGenerated): Set whether or not the Material is autogenerated. " )
2012-09-19 15:15:01 +00:00
{
2014-11-04 03:42:51 +00:00
object - > setAutoGenerated ( isAutoGenerated ) ;
2014-12-21 20:07:42 +00:00
}
2018-12-12 22:01:26 +00:00
DefineEngineMethod ( Material , getAutogeneratedFile , const char * , ( ) , , " Get filename of autogenerated shader file " )
2018-09-16 01:19:57 +00:00
{
2021-07-19 06:07:08 +00:00
SimObject * material = static_cast < SimObject * > ( object ) ;
2018-09-16 01:19:57 +00:00
return material - > getFilename ( ) ;
}
2014-12-21 20:07:42 +00:00
// Accumulation
2021-07-19 06:07:08 +00:00
bool Material : : _setAccuEnabled ( void * object , const char * index , const char * data )
2014-12-21 20:07:42 +00:00
{
2021-07-19 06:07:08 +00:00
Material * mat = reinterpret_cast < Material * > ( object ) ;
2014-12-21 20:07:42 +00:00
2021-07-19 06:07:08 +00:00
if ( index )
2014-12-21 20:07:42 +00:00
{
U32 i = dAtoui ( index ) ;
mat - > mAccuEnabled [ i ] = dAtob ( data ) ;
AccumulationVolume : : refreshVolumes ( ) ;
}
return true ;
2018-03-06 05:48:44 +00:00
}
2021-07-19 06:07:08 +00:00
//declare general get<entry>, get<entry>Asset and set<entry> methods
//signatures are:
//using DiffuseMap as an example
//material.getDiffuseMap(%layer); //returns the raw file referenced
//material.getDiffuseMapAsset(%layer); //returns the asset id
//material.setDiffuseMap(%texture, %layer); //tries to set the asset and failing that attempts a flat file reference
2024-12-27 12:53:04 +00:00
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , DiffuseMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , NormalMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , DetailNormalMap , Material : : Constants : : MAX_STAGES )
2024-12-27 14:16:47 +00:00
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , OverlayMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , LightMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , ToneMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , DetailMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , ORMConfigMap , Material : : Constants : : MAX_STAGES )
2024-12-27 14:38:01 +00:00
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , RoughMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , AOMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , MetalMap , Material : : Constants : : MAX_STAGES )
DEF_IMAGEASSET_ARRAY_BINDS_REFACTOR ( Material , GlowMap , Material : : Constants : : MAX_STAGES )