; Adds local cubemaps for oldschool headlights, the ones which look like chrome spheres
; if looked at from behind. Compatible with ksMultiMap shader.

[DEFAULTS]
Offset = 0.02, 0.01, -0.02
ExcludeNodes = COCKPIT_HR, HUB_LR, HUB_RR
DynamicReflections = 0
HigherResolution = 0
DebugMode = 0
SplitAxis = 1, 0, 0
SplitThreshold = 0
SplitInModelSpace = 0
Reflectivity = 0.5 ; commonly used value for chrome

; Other optional params
MeshesLeft =
MeshesRight =
MeshesToCut =
ChromeMaterials =
ChromeMeshes =
MeshesMiddle =

[MESH_SPLIT_0_LOCALCUBEMAP]
MESHES = ${MeshesToCut}
SPLIT_AXIS = ${SplitAxis}
SPLIT_THRESHOLD = ${SplitThreshold}
SPLIT_POSTFIX = ___loccbmp_cut_
MODEL_SPACE = ${SplitInModelSpace}

[MIXIN: _LOCAL_CUBEMAP_POS_LEFT]
@ACTIVE = ${Position:count}
POSITION = ${Position}

[MIXIN: _LOCAL_CUBEMAP_POS_RIGHT]
@ACTIVE = ${Position:count}
POSITION = -${Position:1}, ${Position:2:2}

[LOCAL_CUBEMAP_0_LEFT]
MESHES = ${MeshesLeft}, ${MeshesToCut}
OFFSET = ${Offset}
IS_DYNAMIC = ${DynamicReflections}
HIGH_RESOLUTION = ${HigherResolution}
DEBUG = ${DebugMode}
STATIC_FACES = TOP, RIGHT, FRONT
EXCLUDE_NODES = ${ExcludeNodes}
@MIXIN = _LOCAL_CUBEMAP_POS_LEFT

[LOCAL_CUBEMAP_0_RIGHT]
MESHES = ${MeshesRight}, ${MeshesToCut}___loccbmp_cut_
OFFSET = -${Offset:1}, ${Offset:2:2}
IS_DYNAMIC = ${DynamicReflections}
HIGH_RESOLUTION = ${HigherResolution}
DEBUG = ${DebugMode}
STATIC_FACES = TOP, LEFT, FRONT
EXCLUDE_NODES = ${ExcludeNodes}
@MIXIN = _LOCAL_CUBEMAP_POS_RIGHT

[LOCAL_CUBEMAP_0_MIDDLE]
MESHES = ${MeshesMiddle}
OFFSET = 0, 0, 0
IS_DYNAMIC = 0
HIGH_RESOLUTION = ${HigherResolution}
DEBUG = ${DebugMode}
STATIC_FACES = TOP, LEFT, FRONT
EXCLUDE_NODES = ${ExcludeNodes}
@MIXIN = _LOCAL_CUBEMAP_POS_RIGHT

[FUNCTION: _PBR_EstimateF90FromF0]
; From Frostbite presentation:
; Moving Frostbite to Physically Based Rendering, page 78 here:
; https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
ARGUMENTS = F0
CODE = ' return saturate( 50 * F0 ) '

[SHADER_REPLACEMENT_0_LOCALCUBEMAP_HEADLIGHTS]
ACTIVE = ${ChromeMaterials:count}
MATERIALS = ${ChromeMaterials}
SHADER = ksPerPixelMultiMap
PROP_0 = fresnelMaxLevel, $" _PBR_EstimateF90FromF0( $Reflectivity ) "
PROP_1 = fresnelEXP, 5
PROP_2 = fresnelC, $Reflectivity
PROP_3 = ksSpecularEXP, 200
PROP_4 = ksSpecular, $" 50 * saturate( $Reflectivity * 2 ) "
PROP_5 = ksDiffuse, 0.05
PROP_6 = ksAmbient, 0.05
FILL_MISSING_TEXTURES = 1
RESOURCE_2 = txDiffuse
RESOURCE_COLOR_2 = 1

[SHADER_REPLACEMENT_1_LOCALCUBEMAP_HEADLIGHTS]
ACTIVE = ${ChromeMeshes:count}
MESHES = ${ChromeMeshes}
SHADER = ksPerPixelMultiMap
PROP_0 = fresnelMaxLevel, $" _PBR_EstimateF90FromF0( $Reflectivity ) "
PROP_1 = fresnelEXP, 5
PROP_2 = fresnelC, $Reflectivity
PROP_3 = ksSpecularEXP, 200
PROP_4 = ksSpecular, $" 50 * saturate( $Reflectivity * 2 ) "
PROP_5 = ksDiffuse, 0.05
PROP_6 = ksAmbient, 0.05
FILL_MISSING_TEXTURES = 1
RESOURCE_2 = txDiffuse
RESOURCE_COLOR_2 = 1