; Very WIP at the moment

[INCLUDE: materials_base.ini]

[DEFAULTS]
MapTurningLightsProperly = 1
DashHighlightColor = 2, 2, 2
DashIndicatorLag = 0.0
OpenDoorLightLag = 0.8
HeadlightsLag = 0.0
ReverseLightsLag = 0.5
ParkingLightsLag = 0.5
BrakingLightsLag = 0.5
TurningLightsLag = 0.8
LicenseLightsLag = 0.5
HeatingMult = 1
DevMode = 1

DefaultBrakingColor = 40, 0, 0
DefaultReverseColor = 40, 40, 40
DefaultOpenDoorLightColor = 16, 15.6, 6

[LIGHT_TURNSIGNAL_LEFT_0, LIGHT_TURNSIGNAL_RIGHT_0]
; ACTIVE = $MapTurningLightsProperly
PREFER_FRONT = 1

[LIGHT_TURNSIGNAL_LEFT_1, LIGHT_TURNSIGNAL_RIGHT_1]
; ACTIVE = $MapTurningLightsProperly
PREFER_FRONT = 0

[MIXIN: AlphaFromTxDiffuse]
PROP_... = emAlphaFromDiffuse, 1

[MIXIN: DebugEmissiveChannels]
@ACTIVE = $DevMode
DebugVal = ${Debug:number}
PROP_... = emSkipDiffuseMap, $" $DebugVal > 0.5 or discard() "
PROP_... = ksEmissive, $DebugVal, 0, 0
PROP_... = ksEmissive1, 0, $DebugVal, 0
PROP_... = ksEmissive2, 0, 0, $DebugVal
PROP_... = ksEmissive3, $DebugVal, $DebugVal, 0
PROP_... = ksEmissive4, 0, $DebugVal, $DebugVal
PROP_... = ksEmissive5, $DebugVal, 0, $DebugVal
PROP_... = ksEmissive6, $DebugVal, $DebugVal, $DebugVal

[MIXIN: DebugEmissiveMultiChannels]
@ACTIVE = $DevMode
DebugVal = ${Debug:number}
PROP_0 = emSkipDiffuseMap, $" $DebugVal > 0.5 "
PROP_... = ksEmissive, $" $UseEmissive0AsFallback and $DebugVal / 10 or $DebugVal ", 0, 0
PROP_... = ksEmissive1, 0, $DebugVal, 0
PROP_... = ksEmissive2, 0, 0, $DebugVal
PROP_... = ksEmissive3, $DebugVal, $DebugVal, 0
PROP_... = ksEmissive4, 0, $DebugVal, $DebugVal
PROP_... = ksEmissive5, $DebugVal, 0, $DebugVal
PROP_... = ksEmissive6, $DebugVal, $DebugVal, $DebugVal
PROP_... = ksEmissive7, $DebugVal, 0, 0
PROP_... = ksEmissive8, 0, $DebugVal, 0
PROP_... = ksEmissive9, 0, 0, $DebugVal
PROP_... = ksEmissive10, $DebugVal, $DebugVal, 0
PROP_... = ksEmissive11, 0, $DebugVal, $DebugVal
PROP_... = ksEmissive12, $DebugVal, 0, $DebugVal
PROP_... = ksEmissive13, $DebugVal, $DebugVal, $DebugVal
PROP_... = ksEmissive14, $DebugVal, 0, 0
PROP_... = ksEmissive15, 0, $DebugVal, 0
PROP_... = ksEmissive16, 0, 0, $DebugVal
PROP_... = ksEmissive17, $DebugVal, $DebugVal, 0
PROP_... = ksEmissive18, 0, $DebugVal, $DebugVal
PROP_... = ksEmissive19, $DebugVal, 0, $DebugVal
PROP_... = ksEmissive20, $DebugVal, $DebugVal, $DebugVal
PROP_... = ksEmissive21, $DebugVal, 0, 0
PROP_... = ksEmissive22, 0, $DebugVal, 0
PROP_... = ksEmissive23, 0, 0, $DebugVal
PROP_... = ksEmissive24, $DebugVal, $DebugVal, 0

[MIXIN: _CustomEmissive_Reset]
@ACTIVE = $DevMode
PROP_0 = emGeoChannel0P, 0 ; reset
PROP_1 = emGeoChannel0S, 0 ; reset
PROP_2 = emGeoChannel1P, 0 ; reset
PROP_3 = emGeoChannel1S, 0 ; reset
PROP_4 = emGeoChannel2P, 0 ; reset
PROP_5 = emGeoChannel2S, 0 ; reset
PROP_6 = emGeoChannel3P, 0 ; reset
PROP_7 = emGeoChannel3S, 0 ; reset
PROP_8 = emMaskColor0A, 0 ; reset
PROP_9 = emMaskColor0C, 0 ; reset
PROP_10 = emMaskColor0P, 0 ; reset
PROP_11 = emMaskColor1A, 0 ; reset
PROP_12 = emMaskColor1C, 0 ; reset
PROP_13 = emMaskColor1P, 0 ; reset
PROP_14 = emMaskColor2A, 0 ; reset
PROP_15 = emMaskColor2C, 0 ; reset
PROP_16 = emMaskColor2P, 0 ; reset
PROP_17 = emMaskColor3A, 0 ; reset
PROP_18 = emMaskColor3C, 0 ; reset
PROP_19 = emMaskColor3P, 0 ; reset
PROP_20 = emPoly00, 0 ; reset
PROP_21 = emPoly01, 0 ; reset
PROP_22 = emPoly02, 0 ; reset
PROP_23 = emPoly10, 0 ; reset
PROP_24 = emPoly11, 0 ; reset
PROP_25 = emPoly12, 0 ; reset
PROP_26 = emPoly20, 0 ; reset
PROP_27 = emPoly21, 0 ; reset
PROP_28 = emPoly22, 0 ; reset
PROP_29 = emPoly30, 0 ; reset
PROP_30 = emPoly31, 0 ; reset
PROP_31 = emPoly32, 0 ; reset
PROP_32 = emSkipDiffuseMap, 0 ; reset
PROP_33 = ksEmissive, 0 ; reset
PROP_34 = ksEmissive1, 0 ; reset
PROP_35 = ksEmissive2, 0 ; reset
PROP_36 = ksEmissive3, 0 ; reset
PROP_37 = ksEmissive4, 0 ; reset
PROP_38 = ksEmissive5, 0 ; reset
PROP_39 = ksEmissive6, 0 ; reset
PROP_40 = emDiffuseAvgColorAsMultiplier3, 0 ; reset
PROP_41 = emDiffuseAlphaAsMultiplier3, 0 ; reset
PROP_42 = emMirrorUVOffset, 0 ; reset
PROP_43 = emMirrorUV, 0 ; reset

[MIXIN: _CustomEmissive_ShaderGrass]
SHADER = smGlass_emissive
SHADER_OVERRIDE_0 = smGlass_phel, smGlass_phel

[MIXIN: _CustomEmissive_ShaderMultiMap]
SHADER = ksPerPixelMultiMap_emissive
SHADER_OVERRIDE_0 = ?NMDetail?, ksPerPixelMultiMap_NMDetail_emissive

[TEMPLATE: CustomEmissive EXTENDS _Base_Material_Custom]
@OUTPUT = SHADER_REPLACEMENT_9_CUSTOMEMISSIVE_...
@MIXIN = $" $CompatibleWithPBRGlass and '_CustomEmissive_ShaderGrass' or '_CustomEmissive_ShaderMultiMap' "
FILL_MISSING_TEXTURES = 1
Debug = 0
UseAreas = 0
UseAreasAsMask = 0
UseColorMasks = 0
UsePolys = 0
UseVertexMask = 0
VertexMaskAdditive = 0
VertexMaskSubtractive = 0
MirrorDir = 1, 0, 0
MirrorOffset = 0
AreasSubtractNext = 0
ColorSubtractNext = 0
PolySubtractNext = 0
PROP_0_CHANNELSMODE = emChannelsMode, 1
PROP_0_PROCEDURALMODE = emProceduralMode, $" 
  (
    (not ${StartWithWhite:bool} and 1 or 0)
    + (${UseAreas:bool} and (2 + (def($AreasSubtractive, false) and 8 or 4)) or 0) 
    + (${UseColorMasks:bool} and (16 + (def($ColorMasksSubtractive, false) and 64 or not def($ColorMasksAsMultiplier, false) and 32 or 0)) or 0) 
    + (${UsePolys:bool} and (128 + (def($PolysSubtractive, false) and 512 or not def($PolysMasksAsMultiplier, false) and 256 or 0)) or 0)
  )
  + ( ${AreasSubtractNext:bool} and 1024 or 0 )
  + ( ${ColorSubtractNext:bool} and 2048 or 0 )
  + ( ${PolySubtractNext:bool} and 4096 or 0 )
  + ( ${UseVertexMask:bool} and 8192 or 0 )
  + ( ${VertexMaskAdditive:bool} and 16384 or 0 )
  + ( ${VertexMaskSubtractive:bool} and 32768 or 0 )
  + ( ${UseAreasAsMask:bool} and 65536 or 0 )
  + ( ${UseRawUV:bool} and 131072 or 0 ) "
PROP_0_MIRRORDIR = emMirrorDir, $" ${MirrorDir:vec3}:normalize() "
PROP_0_MIRROROFFSET = emMirrorOffset, $MirrorOffset
PROP_0_MASKCOLORINPUTBLUR = emMaskColorInputBlur, $" def($ColorInputBlur, 0) "
; PROP_0_EMMASKRESULTDIFFUSEBLUR = emMaskResultDiffuseBlur, $" def($ApplyBlurredDiffuse, 0) "
; PROP_0_EMMASKRESULTNORMALALPHABLUR = emMaskResultNormalAlphaBlur, $" def($ApplyBlurredNormalAlpha, 0) "
@MIXIN = _CustomEmissive_Reset
@MIXIN = DebugEmissiveChannels, Debug = $Debug

[TEMPLATE: CustomEmissiveMulti EXTENDS _Base_Material_Custom]
SHADER = ksPerPixelMultiMap_emissiveExtra
FILL_MISSING_TEXTURES = 1
Debug = 0
MirrorDir = 1, 0, 0
MirrorOffset = 0
PROP_0_MIRRORDIR = emMirrorDir, $" ${MirrorDir:vec3}:normalize() "
PROP_0_MIRROROFFSET = emMirrorOffset, $MirrorOffset
; PROP_0_EMMASKRESULTDIFFUSEBLUR = emMaskResultDiffuseBlur, $" def($ApplyBlurredDiffuse, 0) "
; PROP_0_EMMASKRESULTNORMALALPHABLUR = emMaskResultNormalAlphaBlur, $" def($ApplyBlurredNormalAlpha, 0) "
PROP_0_EMUSECHANNEL0ASFALLBACK = emUseChannel0AsFallback, $" ${UseEmissive0AsFallback:str} == 'COVER_ALL' and 2 or def($UseEmissive0AsFallback, 0) "
PROP_0_EMSKIPEMISSIVEMAP = emSkipEmissiveMap, $" def($SkipEmissiveMap, 1) "
@MIXIN = _CustomEmissive_Reset
@MIXIN = DebugEmissiveMultiChannels, Debug = $Debug

[MIXIN: CustomEmissive_MirrorUV]
PROP_... = emMirrorUVOffset, $" def($Offset, 0.5) / def2( ${Resolution:vec2}, 1, 1 ).x "
PROP_... = emMirrorUV, $" -def2($Direction, 1, 0):normalize() "

[MIXIN: CustomEmissive_SkipDiffuseMap]
PROP_... = emSkipDiffuseMap, $" def($SkipDiffuseMap, true) "

[MIXIN: CustomEmissive_BounceBack]
PROP_... = extBounceBackMask, $" ${Channel:exists} and { ($Channel == 0) and 1 or 0 , ($Channel == 1) and 1 or 0, ($Channel == 2) and 1 or 0, ($Channel == 3) and 1 or 0 } or def4($Mask, 1, 1, 1, 1) "
PROP_... = extBounceBack, $" def($Intensity, 20) "

[MIXIN: CustomEmissive_Alpha]
PROP_... = emAlphaFromDiffuse, $" (def($FromDiffuseMap, false) and 1 or 0.01) * (def($NMMode, false) and -1 or 1) "

[MIXIN: CustomEmissive_UseDiffuseLuminocity]
_DiffLumFrom = $" ${From:exists} and ${From:vec4} or vec4(0,0,0,0) "
_DiffLumTo = $" ${To:exists} and ${To:vec4} or vec4(1,1,1,1) "
PROP_... = emSkipDiffuseMap, $" def($SkipDiffuseMap, true) "
PROP_... = emDiffuseAvgColorAsMultiplier0, $" lerp(vec4(1, 1, 1, 1), ${Multiplier:exists} and ${Multiplier:vec4} or (1 / ($_DiffLumTo - $_DiffLumFrom)), ${Mask:exists} and ${Mask:vec4} or 1 ) "
PROP_... = emDiffuseAvgColorAsMultiplier1, $" lerp(vec4(0, 0, 0, 0), ${Offset:exists} and ${Offset:vec4} or (-$_DiffLumFrom / ($_DiffLumTo - $_DiffLumFrom)), ${Mask:exists} and ${Mask:vec4} or 1 ) "
PROP_... = emDiffuseAvgColorAsMultiplier2, $" lerp(vec4(1, 1, 1, 1), ${Exponent:exists} and ${Exponent:vec4} or vec4(1,1,1,1), ${Mask:exists} and ${Mask:vec4} or 1 ) "
PROP_... = emDiffuseAvgColorAsMultiplier3, $" lerp(vec4(1, 1, 1, 1), ${Opacity:exists} and ${Opacity:vec4} or vec4(1,1,1,1), ${Mask:exists} and ${Mask:vec4} or 1 ) "

[MIXIN: CustomEmissive_UseDiffuseAlpha]
_DiffAlpFrom = $" ${From:exists} and ${From:vec4} or vec4(0,0,0,0) "
_DiffAlpTo = $" ${To:exists} and ${To:vec4} or vec4(1,1,1,1) "
PROP_... = emSkipDiffuseMap, $" def($SkipDiffuseMap, true) "
PROP_... = emDiffuseAlphaAsMultiplier0, $" ${Multiplier:exists} and ${Multiplier:vec4} or (1 / ($_DiffAlpTo - $_DiffAlpFrom)) "
PROP_... = emDiffuseAlphaAsMultiplier1, $" ${Offset:exists} and ${Offset:vec4} or (-$_DiffAlpFrom / ($_DiffAlpTo - $_DiffAlpFrom)) "
PROP_... = emDiffuseAlphaAsMultiplier2, $" ${Exponent:exists} and ${Exponent:vec4} or vec4(1,1,1,1) "
PROP_... = emDiffuseAlphaAsMultiplier3, $" ( ${Opacity:exists} and ${Opacity:vec4} or vec4(1,1,1,1) ) * (${FromNormalMap:bool} and -1 or 1) "

[MIXIN: CustomEmissive_Color]
UseColorMasks = 1
_ChannelColor = $" def( $Channel, 0 ) "
_ThresholdLevel = $" def( $ThresholdLevel, def( ${Threshold:1}, 0.95 ) ) "
_ThresholdSharpness = $" def( $ThresholdSharpness, def( ${Threshold:2}, 20 ) )"
PROP_... = $" $_ChannelColor == 3 and 'emMirrorChannel3As4' or $_ChannelColor == 2 and 'emMirrorChannel2As5' 
  or $_ChannelColor == 1 and 'emMirrorChannel1As6' ", $" def( $Mirror, 0 ) "
PROP_... = emMaskColor${_ChannelColor}C, $" vec4( lerp( 
    def( ${Color:vec3}, vec3(1, 0.5, 0) ), 
    def( ${Color:vec3}, vec3(1, 0.5, 0) ):normalize(), 
    def( $Normalization, 1 ) ), def( $Normalization, 1 )) "
PROP_... = emMaskColor${_ChannelColor}P, $_ThresholdSharpness, $" $_ThresholdSharpness * $_ThresholdLevel ", $" def2( $AlphaMinMax, 0, 0 ) "
PROP_... = emMaskColor${_ChannelColor}A, $" def( $Opacity, 1 ) "

[MIXIN: CustomEmissive_Area]
UseAreas = 1
_Resolution = $" def2( $Resolution, 1, 1 ) "
_Center = $" def( $Center, ${Start:vec2} + ${Size:vec2} / 2 ) "
_ChannelArea = $" def( $Channel, 0 ) "
PROP_... = $" $_ChannelArea == 3 and 'emMirrorChannel3As4' or $_ChannelArea == 2 and 'emMirrorChannel2As5' 
  or $_ChannelArea == 1 and 'emMirrorChannel1As6' ", $" def( $Mirror, 0 ) "
PROP_... = emGeoChannel${_ChannelArea}S, $" vec4(2 * ${_Resolution:vec2} / ${Size:vec2}, -2 * ${_Center:vec2} / ${Size:vec2})"
PROP_... = emGeoChannel${_ChannelArea}P, $" 1 / def2( ${CornerRadius:vec2}, 0, 0 ):clamp(0.001, 1) ", $" def($Exponent, 1) ", $" def( $Opacity, 1 ) "

[MIXIN: CustomEmissive_AreaMask]
UseAreas = 1
StartWithWhite = 1
UseAreasAsMask = 1
_Resolution = $" def2( $Resolution, 1, 1 ) "
_Center = $" def( $Center, ${Start:vec2} + ${Size:vec2} / 2 ) "
_ChannelAreaMask = $" def($_ChannelAreaMask, -1) + 1 "
PROP_... = emGeoChannel${_ChannelAreaMask}S, $" vec4(2 * ${_Resolution:vec2} / ${Size:vec2}, -2 * ${_Center:vec2} / ${Size:vec2})"
PROP_... = emGeoChannel${_ChannelAreaMask}P, $" 1 / def2( ${CornerRadius:vec2}, 0, 0 ):clamp(0.001, 1) ", $" def($Exponent, 1) ", $" def( $Opacity, 1 ) "

[MIXIN: CustomEmissive_Poly]
UsePolys = 1
_PolyResolution = $" def2( $Resolution, 1, 1 ) "
_ChannelPoly = $" def( $Channel, 0 ) "
PROP_... = $" $_ChannelPoly == 3 and 'emMirrorChannel3As4' or $_ChannelPoly == 2 and 'emMirrorChannel2As5' 
  or $_ChannelPoly == 1 and 'emMirrorChannel1As6' ", $" def( $Mirror, 0 ) "
PROP_... = emPoly${_ChannelPoly}0, $" ${P1:vec2} / ${_PolyResolution:vec2} ", $" ${P2:vec2} / ${_PolyResolution:vec2} "
PROP_... = emPoly${_ChannelPoly}1, $" ${P3:vec2} / ${_PolyResolution:vec2} ", $" ${P4:vec2} / ${_PolyResolution:vec2} "
PROP_... = emPoly${_ChannelPoly}2, $" -def($Sharpness, 1000) ", $" -def($Offset, 0) * def($Sharpness, 1000) ", $" def($Exponent, 1) ", $" def( $Opacity, 1 ) "

[MIXIN: CustomEmissive_VertexMask]
UseVertexMask = 1
PROP_... = emEmissiveArea0, ${Point0:1:3:vec3}, $" def(${Point0:4}, ${Point0:exists} and 1 or 0) "
PROP_... = emEmissiveArea1, ${Point1:1:3:vec3}, $" def(${Point1:4}, ${Point1:exists} and 1 or 0) "
PROP_... = emEmissiveArea2, ${Point2:1:3:vec3}, $" def(${Point2:4}, ${Point2:exists} and 1 or 0) "
PROP_... = emEmissiveArea3, ${Point3:1:3:vec3}, $" def(${Point3:4}, ${Point3:exists} and 1 or 0) "

[MIXIN: CustomEmissive_Rect]
@MIXIN = CustomEmissive_Area

[MIXIN: CustomEmissive_CoverAll]
@MIXIN = CustomEmissive_Rect, Start = 0, Size = $" def2( $Resolution, 1, 1 ) "

[MIXIN: CustomEmissive_Circle]
@MIXIN = CustomEmissive_Area, CornerRadius = 1, Exponent = $" def($Exponent, 0.1) "

[FUNCTION: _Emissive_GuessLocation]
ARGUMENTS = Meshes
CODE = '
  local ret = "NONE"
  function testMesh(mesh)
    if string.match(mesh:lower(), "front") then ret = "FRONT" end
    if string.match(mesh:lower(), "head") then ret = "FRONT" end
    if string.match(mesh:lower(), "rear") then ret = "REAR" end
    if string.match(mesh:lower(), "tail") then ret = "REAR" end
  end
  if type(Meshes) == "table" then
    for k, v in pairs(Meshes) do
      testMesh(v)
    end
  else
    testMesh(Meshes)
  end
  return ret
'

[FUNCTION: _Emissive_GuessColor]
ARGUMENTS = Input
CODE = '
  if Input == "HIGHBEAM" then return vec3(0, 4, 20) end
  if Input == "TURNSIGNAL" or Input == "TURNSIGNAL_LEFT" or Input == "TURNSIGNAL_RIGHT" or Input == "LIGHT" then return vec3(0, 20, 0) end
  if Input == "ABS_INACTION" or Input == "TRACTIONCONTROL_INACTION" 
    or Input == "ENGINE_LIFE" or Input == "TYRE_PRESSURE" or Input == "HAZARD" 
    or Input == "TRACTIONCONTROL" then return vec3(20, 12, 0) end
  return vec3(20, 0, 0)
'

[FUNCTION: _Emissive_GetSideMeshes]
ARGUMENTS = LeftAndRight, NeedsRight, Meshes
CODE = '
  if not LeftAndRight or LeftAndRight == 0 or type(Meshes) ~= "table" then 
    return Meshes
  end

  if LeftAndRight == "AUTO" then
    local ret = {}
    for k, v in pairs(Meshes) do
      if not string.match(v:lower(), "right") and not NeedsRight then ret[#ret + 1] = v end
      if not string.match(v:lower(), "left") and NeedsRight then ret[#ret + 1] = v end
    end
    return ret
  end

  local ret = {}
  for i = 1 + (NeedsRight and #Meshes / 2 or 0), NeedsRight and #Meshes or #Meshes / 2, 1 do
    ret[#ret + 1] = Meshes[i]
  end
  return ret
'

[MIXIN: TurningLightsFront]
@GENERATOR = _TurningLights_Emissive, 2, Location = FRONT
@GENERATOR = _TurningLights, 2, ExplicitLocation

[MIXIN: TurningLightsRear]
@GENERATOR = _TurningLights_Emissive, 2, Location = REAR
@GENERATOR = _TurningLights, 2, IsRear, ExplicitLocation

[MIXIN: TurningLightsFrontCorner]
@MIXIN = TurningLightsFront, Direction = "1, 0, 1", Spot = 250

[MIXIN: TurningLightsRearCorner]
@MIXIN = TurningLightsRear, Direction = "1, 0, -1", Spot = 250

[MIXIN: TurningLightsRearCombined]
@MIXIN = TurningLightsRear, HeadlightsIntensity = 0.3, BrakingLightsIntensity = 1, Color = $DefaultBrakingColor

[MIXIN: TurningLightsRearCornerCombined]
@MIXIN = TurningLightsRearCorner, HeadlightsIntensity = 0.3, BrakingLightsIntensity = 1, Color = $DefaultBrakingColor

[MIXIN: _LightParams]
COLOR = ${LightColor:?}
SPOT = ${Spot:1:?}
SPOT_SHAPNESS = ${Spot:2:?}
SPOT_SHAPNESS = ${SpotSharpness:?}
AFFECTS_TRACK = ${Debug:?}
ONESIDED = ${Onesided:?}
SELF_LIGHTNING = ${SelfLighting:?}

[TEMPLATE: _TurningLights]
@ACTIVE = $" not def( $NotCastingLight, false) "
@OUTPUT = $" ( $1 == 2 and 'LIGHT_TURNSIGNAL_RIGHT_' or 'LIGHT_TURNSIGNAL_LEFT_' ) .. (${IsRear:bool} and 1 or 0)  "
DIRECTION = $" ${Direction:vec3:?} * ($1 == 2 and vec3(-1, 1, 1) or vec3(1, 1, 1)) "
OFFSET = $" ${Offset:vec3:?} * ($1 == 2 and vec3(-1, 1, 1) or vec3(1, 1, 1)) "
PREFER_FRONT = $" not ${ExplicitLocation:bool} and discard() or not ${IsRear:bool} "
EMISSIVE_INDEX = $" ${EmissiveIndex:?} "
RELATIVE_TO = $" ${AnimatedDoors:size} == 2 and ($1 == 2 and ${AnimatedDoors:2} or ${AnimatedDoors:1}) or discard() "
@MIXIN = _LightParams

[TEMPLATE: _TurningLights_Lights]
@OUTPUT = $" ($1 == 2 and 'LIGHT_TURNSIGNAL_RIGHT_' or 'LIGHT_TURNSIGNAL_LEFT_') .. ($2 - 1) "

[MIXIN: TurningLights]
@GENERATOR = _TurningLights_Emissive, 2
@GENERATOR = _TurningLights, 2
@GENERATOR = _TurningLights, 2, IsRear
@GENERATOR = _TurningLights_Lights_FrontAndRear, 2, 2

[MIXIN: DashTurningLights]
@MIXIN = TurningLights, Color = $" def3( $Color, 0, 20, 2 ) ", Lag = $" def( $Lag, 0 ) ", NotCastingLight

[TEMPLATE: _TurningLights_Emissive]
@OUTPUT = $" ( $1 == 2 and 'EMISSIVE_TURNSIGNAL_RIGHT_' or 'EMISSIVE_TURNSIGNAL_LEFT_' ) .. def($EmissiveIndex, '...') "
NAME = $" _Emissive_GetSideMeshes(${AnimatedDoors:size} == 2 or $LeftAndRight, $1 == 2, $Meshes) "
COLOR = $" def( $Color, vec3(25, 12, 0) ) * def( $Intensity, 1 ) "
FALLBACK_HEADLIGHTS_COLOR = $" def( $Color, vec3(25, 12, 0) ) * def( $Intensity, 1 ) * ( $HeadlightsIntensity or discard() ) "
FALLBACK_BRAKES_COLOR = $" def( $Color, vec3(25, 12, 0) ) * def( $Intensity, 1 ) * ( $BrakingLightsIntensity or discard() ) "
CHANNEL = $" $1 == 2 and def($ChannelAlt, ($Channel == 3 and 4 or $Channel == 2 and 5 or $Channel == 1 and 6)) or $Channel "
LAG = $" def( $Lag, $TurningLightsLag ) "
SIMULATE_HEATING = $" $BrakingLightsIntensity and $HeatingMult * 0.2 or 2 "
LOCATION = $" $FrontAndRear and 'REAR' or def( $Location, _Emissive_GuessLocation($Meshes) ) "
CAST_LIGHT = $" not ${NotCastingLight} "

[TEMPLATE: _TurningLights_Lights_FrontAndRear]
@ACTIVE = $FrontAndRear
@OUTPUT = $" ($1 == 2 and 'LIGHT_TURNSIGNAL_RIGHT_' or 'LIGHT_TURNSIGNAL_LEFT_') .. ($2 - 1) "
EMISSIVE_INDEX = 0
PREFER_FRONT = $" $2 == 1 "

[MIXIN: Headlights]
@GENERATOR = _Headlights_Emissive
@GENERATOR = _Headlights_Lights

[TEMPLATE: _Headlights_Emissive]
@OUTPUT = EMISSIVE_HEADLIGHTS_...
NAME = $Meshes
COLOR = $" def( $Color, vec3(20, 20, 20) ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
ACT_AS_HEADLIGHTS = 1
LAG = $" def( $Lag, $HeadlightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" def( $Location, 'FRONT' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[TEMPLATE: _Headlights_Lights]
@OUTPUT = LIGHT_HEADLIGHT_0
PREFER_FRONT = 0
DIRECTION = ${Direction:vec3:?}
OFFSET = ${Offset:vec3:?}
@MIXIN = _LightParams

[MIXIN: ReverseLights]
@GENERATOR = _ReverseLights_Emissive
@GENERATOR = _ReverseLights_Lights

[TEMPLATE: _ReverseLights_Emissive]
@OUTPUT = EMISSIVE_REVERSE_...
NAME = $Meshes
COLOR = $" def( $Color, $DefaultReverseColor ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
LAG = $" def( $Lag, $ReverseLightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" $FrontAndRear and 'REAR' or def( $Location, 'REAR' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[TEMPLATE: _ReverseLights_Lights]
@OUTPUT = LIGHT_REVERSE_0
PREFER_FRONT = 0
DIRECTION = ${Direction:vec3:?}
OFFSET = ${Offset:vec3:?}
@MIXIN = _LightParams

[MIXIN: BrakingLights]
@GENERATOR = _BrakingLights_Emissive

[TEMPLATE: _BrakingLights_Emissive]
@OUTPUT = EMISSIVE_BRAKE_...
NAME = $Meshes
COLOR = $" def( $Color, $DefaultBrakingColor ) * def( $Intensity, 1 ) "
FALLBACK_HEADLIGHTS_COLOR = $" def( $Color, $DefaultBrakingColor ) * def( $Intensity, 1 ) * ( $HeadlightsIntensity or discard() ) "
CHANNEL = $Channel
LAG = $" def( $Lag, $BrakingLightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" $FrontAndRear and 'REAR' or def( $Location, 'REAR' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[MIXIN: ParkingLights]
@GENERATOR = _ParkingLights_Emissive

[TEMPLATE: _ParkingLights_Emissive]
@OUTPUT = EMISSIVE_LIGHT_...
NAME = $Meshes
COLOR = $" def( $Color, vec3(5, 0, 0) ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
LAG = $" def( $Lag, $ParkingLightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" $FrontAndRear and 'REAR' or def( $Location, 'REAR' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[MIXIN: LicensePlateLights]
@GENERATOR = _LicensePlateLights_Emissive

[TEMPLATE: _LicensePlateLights_Emissive]
@OUTPUT = EMISSIVE_LIGHT_...
NAME = $Meshes
COLOR = $" def( $Color, vec3(10, 10, 10) ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
LAG = $" def( $Lag, $LicenseLightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" $FrontAndRear and 'REAR' or def( $Location, 'REAR' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[MIXIN: FogLights]
@GENERATOR = _FogLights_Emissive
@GENERATOR = _FogLights_Lights

[MIXIN: _FogLightsParams]
BIND_TO_EXTRA_A = 1
NOT_WITH_HEADLIGHTS = 0
SPOT = 120
SPOT_SHARPNESS = 0
RANGE = 8
SPECULAR_MULT = 1
SELF_LIGHTNING = 0
AFFECTS_TRACK = 1
POPUP_ENABLED = 0
RANGE_GRADIENT_OFFSET = 0.2
FADE_AT = 15
FADE_SMOOTH = 5
INTERIOR_ONLY = 0

[TEMPLATE: _FogLights_Emissive]
@OUTPUT = EMISSIVE_EXTRA_A_...
NAME = $Meshes
COLOR = $" def( $Color, vec3(20, 20, 20) ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
ACT_AS_HEADLIGHTS = 1
LAG = $" def( $Lag, $HeadlightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" def( $Location, 'FRONT' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[TEMPLATE: _FogLights_Lights]
@OUTPUT = LIGHT_EXTRA_0FOGFRONT
PREFER_FRONT = 1
COLOR = $" def( $Color, vec3(4, 4, 4) ) "
POSITION = $" ${Position:vec3} * vec3(0, 1, 1) "
MIRROR = ${Position:1:?}
DIRECTION = $" def( $Direction, vec3(0, 0, 1) ) "
OFFSET = ${Offset:vec3:?}
@MIXIN = _LightParams
@MIXIN = _FogLightsParams
EXTERIOR_ONLY = 0

[MIXIN: FogLightsFront]
@ = FogLights

[MIXIN: FogLightsRear]
@GENERATOR = _FogLightsRear_Emissive
@GENERATOR = _FogLightsRear_Lights

[TEMPLATE: _FogLightsRear_Emissive]
@OUTPUT = EMISSIVE_EXTRA_A_...
NAME = $Meshes
COLOR = $" def( $Color, vec3(20, 0, 0) ) * def( $Intensity, 1 ) "
CHANNEL = $Channel
ACT_AS_HEADLIGHTS = 1
LAG = $" def( $Lag, $HeadlightsLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = $" def( $Location, 'REAR' ) "
CAST_LIGHT = $" not ${NotCastingLight:bool} "

[TEMPLATE: _FogLightsRear_Lights]
@OUTPUT = LIGHT_EXTRA_0FOGREAR
PREFER_FRONT = 0
COLOR = $" def( $Color, vec3(4, 0, 0) ) "
POSITION = ${Position:vec3:?}
MIRROR = ${Mirror:number:?}
DIRECTION = $" def( $Direction, vec3(0, 0, -1) ) "
OFFSET = ${Offset:vec3:?}
RANGE = 2
@MIXIN = _LightParams
@MIXIN = _FogLightsParams
EXTERIOR_ONLY = 1

[MIXIN: InteriorLights]
@GENERATOR = _DashIndicator_Emissive, Input = LIGHT, Color = "20, 20, 20"

[MIXIN: DashIndicator]
@GENERATOR = _DashIndicator_Emissive

[MIXIN: DashHighlight]
@GENERATOR = _DashIndicator_Emissive, Input = LIGHT, Color = $DashHighlightColor

[MIXIN: DashWarningABS]
@GENERATOR = _DashIndicator_Emissive, Input = ABS, Invert, Color = "20, 12, 0"

[MIXIN: DashWarningTC]
@GENERATOR = _DashIndicator_Emissive, Input = TRACTIONCONTROL, Invert
; @GENERATOR = _DashIndicator_Emissive, Input = TRACTIONCONTROL, Color = "20, 12, 0", Invert

[MIXIN: DashWarningCollision]
@GENERATOR = _DashIndicator_Emissive, Input = BODY_DAMAGE, Color = "20, 0, 0"

[MIXIN: DashWarningAirbag]
@GENERATOR = _DashIndicator_Emissive, Input = BODY_DAMAGE, Color = "20, 0, 0"

[MIXIN: DashWarningEngine]
@GENERATOR = _DashIndicator_Emissive, Input = ENGINE_LIFE, Color = "20, 0, 0", InputThreshold = 100, InputInverse

[MIXIN: DashWarningTemperature]
@GENERATOR = _DashIndicator_Emissive, Input = OIL_TEMP, Color = "20, 0, 0", InputThreshold = 90, InputInverse, Invert

[MIXIN: DashWarningTyrePressure]
@GENERATOR = _DashIndicator_Emissive, Input = TYRE_PRESSURE, Color = "20, 0, 0", InputThreshold = $" def($Pressure, 20) ", InputInverse, InputSelector = MIN

[MIXIN: DashWarningFuel]
@GENERATOR = _DashIndicator_Emissive, Input = FUEL, Color = "20, 10, 0", InputThreshold = $" read('data/digital_instruments.ini/FUEL_WARNING_0/FUEL_SWITCH', 1) ", InputInverse

[MIXIN: DashWarningSeatbelt]
@GENERATOR = _DashIndicator_Emissive, Input = SEATBELT, Invert

[MIXIN: DashInteriorLight]
@GENERATOR = _DashIndicator_Emissive, Input = OPENDOORS, Color = "20, 20, 0"

[MIXIN: DashEmissiveDisplay]
@GENERATOR = _DashIndicator_Emissive, Input = ONE, Color = "5, 5, 5"

[MIXIN: DashFogLights]
@GENERATOR = _DashIndicator_Emissive, Input = EXTRA_A

[MIXIN: DashWarningBrakes]
@GENERATOR = _DashIndicator_Emissive, Input = __WARNING_BRAKES ; not doing anything for now

[MIXIN: DashWarningSteering]
@GENERATOR = _DashIndicator_Emissive, Input = __WARNING_STEERING ; not doing anything for now

[MIXIN: DashWarningCarLocked]
@GENERATOR = _DashIndicator_Emissive, Input = __WARNING_CAR_LOCKED ; not doing anything for now

[TEMPLATE: _DashIndicator_Emissive]
@OUTPUT = EMISSIVE_0DASHINDICATOR_...
INPUT = $Input
INPUT_THRESHOLD = ${InputThreshold:?}
INPUT_THRESHOLD_INVERSE = ${InputInverse:?}
INPUT_SELECTOR = ${InputSelector:?}
INPUT_MIN = ${InputMin:?}
INPUT_MAX = ${InputMax:?}
INPUT_LUT = ${InputLut:?}
INPUT_LAG_UP = ${InputLagUp:?}
INPUT_LAG_DOWN = ${InputLagDown:?}
USE_SMOOTH_TRANSITION = ${UseSmoothTransition:?}
NAME = $Meshes
_Color = $" def( $Color, _Emissive_GuessColor($Input) ) * def( $Intensity, 1 ) "
_OffColor = $" def3( $OffColor, 0, 0, 0 ) * def( $Intensity, 1 ) "
COLOR = $" def( $Invert, false ) and $_OffColor or $_Color "
OFF_COLOR = $" def( $Invert, false ) and $_Color or $_OffColor "
FALLBACK_HEADLIGHTS_COLOR = $" ${DashHighlight:bool} and $DashHighlightColor or discard() "
CHANNEL = $Channel
LAG = $" def( $Lag, $DashIndicatorLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.2 "
LOCATION = NONE

[MIXIN: OpenDoorLight]
@GENERATOR = _OpenDoorLight_Emissive
@GENERATOR = _OpenDoorLight_Light

[TEMPLATE: _OpenDoorLight_Emissive]
@OUTPUT = EMISSIVE_OPENDOORS_...
NAME = $Meshes
_Color = $" def( $Color, $DefaultOpenDoorLightColor ) * def( $Intensity, 1 ) "
_OffColor = $" def3( $OffColor, 0, 0, 0 ) * def( $Intensity, 1 ) "
COLOR = $" def( $Invert, false ) and $_OffColor or $_Color "
OFF_COLOR = $" def( $Invert, false ) and $_Color or $_OffColor "
CHANNEL = $Channel
LAG = $" def( $Lag, $OpenDoorLightLag ) "
SIMULATE_HEATING = $" $HeatingMult * 0.8 "
LOCATION = NONE

[TEMPLATE: _OpenDoorLight_Light]
@OUTPUT = LIGHT_OPENDOORS_0
POSITION = ${Position:vec3:?}
OFFSET = ${Offset:vec3:?}
MIRROR = ${Mirror:number:?}
DIRECTION = ${Direction:vec3:?}
OFFSET = ${Offset:vec3:?}
@MIXIN = _LightParams

[FUNCTION: _Emissive_MultiItemIsInput]
ARGUMENTS = val
CODE = 'return string.upper(val) == val'

[MIXIN: MultiItem]
_MultiChannel = $" def($_MultiChannel, 0) + 1 "
@ = $" $Circle and 'CustomEmissive_Circle' or 'CustomEmissive_Rect' ", Channel = $_MultiChannel
@ = $" def($Debug, 0) > 0 and discard() or (function(r) if string.upper(r) == r then return 'DashIndicator' end return r end)(def($Role, 'DashIndicator')) ",\
  Input = $" (function(r, i) if string.upper(r) == r then return r end return i end)(def($Role, 'DashIndicator'), def($Input, '')) ",\
  Channel = $_MultiChannel

; =====
; These templates allow to create new dashboard indicators for cars which miss some. To use, 
; start with [CustomEmissiveExtra] and add icons and arrows.
; =====

[TEMPLATE: CustomEmissiveExtra EXTENDS CustomEmissiveMulti, _CustomEmissiveExtra_Init]
@OUTPUT = $_CustomEmissive_SectionName
MESH_NAME = $Meshes
PARENT = COCKPIT_HR
PROP_... = ksDiffuse, ${Brightness:or=0.05}
PROP_... = ksAmbient, ${Brightness:or=0.05}
RESOURCE_0 = txDiffuse
RESOURCE_FILE_0 = common/dashboard.dds
@ = AlphaFromTxDiffuse
BLEND_MODE = ALPHA_TEST

[MIXIN: CustomEmissiveExtra_Icon]
; Creates new icon with some emissive behaviour. Parameters: 
; • Position: coordinates
; • Axis (def. 1,0,0): directional vector
; • Normal (def. 0,0,-1): perpendicular vector
; • Size (def. 0.004, 0.004): size, width and height
; • Role: emissive role, same as with MultiItem
; • Icon (def. Role): icon name
; • FlipHorizontal: flip icon horizontally
; • FlipVertical: flip icon horizontally
@ = _CustomEmissive_ExtraShape_Index
_IconID = $" ${Icon:exists} and ${Icon:str} or ${Role:str} "
_IconUV = $" ${_IconID:exists} and _CustomEmissive_ExtraShape_IconUV(${_IconID:str}) or {0,0,1,1} "
@GENERATOR = _CustomEmissive_ExtraShape_Rect
@ = MultiItem, Start = ${_IconUV:1:2}, Size = $" vec2(${_IconUV:3:2}) - vec2(${_IconUV:1:2}) "

[MIXIN: CustomEmissiveExtra_Arrow]
; Creates an arrow with some emissive behaviour. Parameters: 
; • Position: coordinates
; • Axis (def. 1,0,0): directional vector
; • Normal (def. 0,0,-1): perpendicular vector
; • SizeBase (def. 0.004, 0.004): size of base part, thickness and length, could be zeroes
; • SizeArrow (def. 0.008, 0.006): size of arrow part, thickness and length, could be zeroes
@ = _CustomEmissive_ExtraShape_Index
_ArrowUV = $" 0.01 + saturate(${_CustomEmissive_ShapeIndex} / 100) * 0.01 ", 0.01
@GENERATOR = _CustomEmissive_ExtraShape_Arrow
@ = MultiItem, Start = $" ${_ArrowUV:vec2} - 0.00001 ", Size = 0.00002

[MIXIN: CustomEmissiveExtra_TurnArrows]
; Creates a couple of arrows for turning signals on dashboard. Parameters: 
; • Position: coordinates
; • Gap: distance between left and right arrows
; • Axis (def. 1,0,0): directional vector
; • Normal (def. 0,0,-1): perpendicular vector
; • SizeBase (def. 0.004, 0.004): size of base part, thickness and length, could be zeroes
; • SizeArrow (def. 0.008, 0.006): size of arrow part, thickness and length, could be zeroes
@ = CustomEmissiveExtra_Arrow, Position = $" ${Position:vec3} + vec3(${Gap:number}, 0, 0) ", Role = TURNSIGNAL_LEFT
@ = CustomEmissiveExtra_Arrow, Position = $" ${Position:vec3} - vec3(${Gap:number}, 0, 0) ", Role = TURNSIGNAL_RIGHT, Axis = $" -${Axis:vec3:or=vec3(1,0,0)} "

; =====
; Inner workings of those templates creating new shapes. Only useful thing here is _CustomEmissive_ExtraShape_IconUV 
; function: use it to see what icons are available.
; =====

[FUNCTION: _CustomEmissive_ExtraShape_IconUV]
ARGUMENTS = IconID
CODE = '
  local columns, rows, icons = 8, 4, { 

    -- Here are available icons. First value is icon name,
    -- second is default Role icon is associated with.

    { "Solid", nil }, 
    { "ArrowLeft", "TURNSIGNAL_LEFT" }, 
    { "ArrowRight", "TURNSIGNAL_RIGHT" }, 
    { "LowBeams", "LIGHT" }, 
    { "HighBeams", "HIGHBEAM" }, 
    { "FogLights", "DashFogLights" }, 
    { "LightsAdjustment", nil }, 
    { "HighBeamsFilled", nil },

    { "BrakesWarning", "DashWarningBrakes" }, 
    { "Handbrake", "HANDBRAKE" }, 
    { "BrakePadsWarning", nil }, 
    { "ABS", "DashWarningABS" },
    { "TC", "TRACTIONCONTROL_INACTION" }, 
    { "TCDisabled", "DashWarningTC" }, 
    { "Seatbelt", "DashWarningSeatbelt" }, 
    { "Airbag", "DashWarningCollision" },

    { "TyresWarning", "DashWarningTyrePressure" }, 
    { "SteeringWarning", "DashWarningSteering" },
    { "Fuel", "DashWarningFuel" }, 
    { "Oil", nil }, 
    { "Engine", "DashWarningEngine" }, 
    { "Temperature", "DashWarningTemperature" }, 
    { "Battery", "STALLED" }, 
    { "OpenDoors", "DashInteriorLight" }, 

    { "Circle", nil },
    { "Lamp", nil }, 
    { "ABS_2", nil }, 
    { "TC_2", nil },
  }
  for index, value in ipairs(icons) do
    if value[1] == IconID or value[2] == IconID then 
      local column, row = (index - 1) % columns, math.floor((index - 1) / columns)
      return { column / columns, row / rows, (column + 1) / columns, (row + 1) / rows }
    end
  end
  return { 0.01, 0.01, 0.01, 0.01 }
'

[MIXIN: _CustomEmissive_ExtraShape_Index]
_CustomEmissive_ShapeIndex = $" ${_CustomEmissive_ShapeIndex:number:or=0} + 1 "

[TEMPLATE: _CustomEmissive_ExtraShape_Arrow]
@OUTPUT = $_CustomEmissive_SectionName
VERTICES_${_CustomEmissive_ShapeIndex} = $"
  local position = ${Position:vec3}
  local axis = ${Axis:vec3:or=vec3(1,0,0)}
  local up = ${Normal:vec3:or=vec3(0,0,-1)}:cross(axis):normalizeSelf()
  local sizeBase = ${SizeBase:vec2:or=vec2(0.004,0.004)}
  local sizeArrow = ${SizeArrow:vec2:or=vec2(0.008,0.006)}
  return {
    sizeArrow[1] > 0 and sizeArrow[2] > 0 and {
      position - up * (sizeArrow[1] / 2),
      position + axis * sizeArrow[2],
      position + up * (sizeArrow[1] / 2),
    } or {},

    sizeBase[1] > 0 and sizeBase[2] > 0 and {
      position - up * (sizeBase[1] / 2),
      position + up * (sizeBase[1] / 2),
      position + up * (sizeBase[1] / 2) - axis * sizeBase[2],

      position - up * (sizeBase[1] / 2),
      position + up * (sizeBase[1] / 2) - axis * sizeBase[2],
      position - up * (sizeBase[1] / 2) - axis * sizeBase[2],
    } or {}
  }"
VERTICES_${_CustomEmissive_ShapeIndex}_UV = $_ArrowUV

[TEMPLATE: _CustomEmissive_ExtraShape_Rect]
@OUTPUT = $_CustomEmissive_SectionName
VERTICES_${_CustomEmissive_ShapeIndex} = $"
  local position = ${Position:vec3}
  local axis = ${Axis:vec3:or=vec3(1,0,0)}
  local up = ${Normal:vec3:or=vec3(0,0,-1)}:cross(axis):normalizeSelf()
  local size = ${Size:vec2:or=vec2(0.004,0.004)}
  return {
    position - up * (size[1] / 2) + axis * (size[2] / 2),
    position + up * (size[1] / 2) + axis * (size[2] / 2),
    position + up * (size[1] / 2) - axis * (size[2] / 2),

    position - up * (size[1] / 2) + axis * (size[2] / 2),
    position + up * (size[1] / 2) - axis * (size[2] / 2),
    position - up * (size[1] / 2) - axis * (size[2] / 2),
  }"
VERTICES_${_CustomEmissive_ShapeIndex}_UV = $"
  local uv0, uv1 = vec2(${_IconUV:1:2}), vec2(${_IconUV:3:2})
  if ${FlipHorizontal:bool} then uv0[1], uv1[1] = uv1[1], uv0[1] end
  if ${FlipVertical:bool} then uv0[2], uv1[2] = uv1[2], uv0[2] end
  return { uv0, vec2(uv0[1], uv1[2]), uv1, uv0, uv1, vec2(uv1[1], uv0[2]) }"

[TEMPLATE: _CustomEmissiveExtra_Init EARLYRESOLVE]
_CustomEmissive_SectionIndex = $" _CustomEmissive_SectionIndex = (_CustomEmissive_SectionIndex or 4000) + 1 return _CustomEmissive_SectionIndex "
_CustomEmissive_SectionName = EXTRA_SHAPE_${_CustomEmissive_SectionIndex}
Meshes = __emissive_mesh_${_CustomEmissive_SectionIndex}
