; --
; Material library for license plate shaders. Mainly intended for original Kunos license plates and
; textures, although could be used for other types of license plates in theory (as long as letters
; could be easily distinguished from background via brightness).
; In first half of this file, you can see available templates and parameters for them.
; Pro tip: make sure TextureRatio is correct width-to-height aspect ratio, or parallax won’t work 
; properly.
; --

; European Kunos license plate: 4-to-1 aspect ratio
[TEMPLATE: Material_LicensePlate_Europe EXTENDS Material_LicensePlate]
LettersDarkening = 0.85
LettersSpecularDarkening = 0.5
BounceBackBrightness = 0.5
LettersCenter = 0.5, 0.5
LettersSize = 0.7, 0.8
InsideCenter = 0.5, 0.5
InsideSize = 0.964, 0.88
InsideRadius = 0.03, 0.12
TextureRatio = 4

; Japanese Kunos license plate: 2-to-1 aspect ratio, dark letters (making them darker with LettersDarkening; for green letters, change LettersDarkening to 0)
[TEMPLATE: Material_LicensePlate_Japan EXTENDS Material_LicensePlate]
LettersDarkening = 0.6
LettersSpecularDarkening = 0.5
BounceBackBrightness = 0.5
LettersCenter = 0.5, 0.5
LettersSize = 0.95, 0.92
InsideCenter = 0.5, 0.5
InsideSize = 0.96, 0.93
InsideRadius = 0.03, 0.06
TextureRatio = 2

; Old Kunos license plate: no borders, letters cover everything, no light bouncing back
[TEMPLATE: Material_LicensePlate_Old EXTENDS Material_LicensePlate]
LettersCenter = 0.5, 0.5
LettersSize = 2, 2
InsideCenter = 0.5, 0.5
InsideSize = 2, 2
InsideRadius = 0, 0
TextureRatio = 4

; Basic template with default the options:
[TEMPLATE: Material_LicensePlate]
Debug = 0                       ; change to 1 to see different areas highlighted
Depth = 1                       ; depth multiplier
TextureRatio = 4.0              ; width-to-height ratio, very important
LettersDarkening = 0.0          ; increase to make letters darker
LettersSpecularDarkening = 0.0  ; increase to make letters specular darker
BounceBackBrightness = 0.0      ; increase to make light bouncing back brighter
ExtrudeLetters = 1              ; set to 0 do disable letters extrusion (for glowing letters which would be more like holes in the surface)

; those parameters set letters area; if you have anything which would be as dark or bright as letters, but wouldn’t need to be extruded (like some logos on the left),
; set this area in such a way as to exclude those symbols
LettersCenter = 0.5, 0.5
LettersSize = 0.95, 0.92

; inside area: everything around it will be considered an extruded border
InsideCenter = 0.5, 0.5
InsideSize = 0.96, 0.93
InsideRadius = 0.03, 0.06 ; corner radius; set to 1 to make it a full circle

; letters mask based on texture brightness
LettersBrightnessStart = 0.67  ; this is where letters start
LettersBrightnessFull = 0.33   ; this is where letters are in full power; here, it’s smaller, so letters in full power are for everything darker than 0.33

; subtle emissive mask for better emissive fallback for license plate light
; EmissiveFadeX = 0.8      ; how much emissive darkens towards left and right edges; reverse to make it get darker in the middle
; EmissiveFadeY = 0.8      ; how much emissive darkens towards bottom; revers to make it get darker towards the top
; EmissiveTotalMult = 1.6  ; how much brigher is emissive to compensate for that shape

; --
; Here goes second half, actual implementation of those templates.
; If you want to go futher, here is some documentation for the whole format:
; https://github.com/ac-custom-shaders-patch/inipp
; --

[INCLUDE: materials_base.ini]

[MIXIN: Emissive_LicensePlate_Top]
EmissiveFadeX = 0.8
EmissiveFadeY = 0.8
EmissiveTotalMult = 1

[MIXIN: Emissive_LicensePlate_Bottom]
EmissiveFadeX = 0.8
EmissiveFadeY = -0.8
EmissiveTotalMult = 1

[MIXIN: Emissive_LicensePlate_Sides]
EmissiveFadeX = -0.8
EmissiveFadeY = 0
EmissiveTotalMult = 1

[MIXIN: Emissive_LicensePlate_None]
EmissiveFadeX = 0
EmissiveFadeY = 0
EmissiveTotalMult = 0

[TEMPLATE: _Material_LicensePlate_Layout]
@OUTPUT = LIGHT_LICENSEPLATE
LAYOUT = ${LightLayout:?}

[TEMPLATE: Material_LicensePlate EXTENDS _Base_Material_Custom]
Materials = '{ texture:Plate_D.dds & texture:Plate_NM.dds }'

@OUTPUT = SHADER_REPLACEMENT_0LICENSEPLATE_...
@GENERATOR = _Material_LicensePlate_Layout
@MIXIN = $" ${LightLayout:str} == 'NONE' and 'Emissive_LicensePlate_None' or 
  ${LightLayout:str} == 'AT_SIDES' and 'Emissive_LicensePlate_Sides' or 
  string.find(${LightLayout:str}, 'BOTTOM') and 'Emissive_LicensePlate_Bottom' or 'Emissive_LicensePlate_Top'"

EmissiveFadeX = 0.8
EmissiveFadeY = 0.8
EmissiveTotalMult = 1.6
BrightnessAdjustment = 0.4

; base material settings
SHADER = smLicensePlate
FILL_MISSING_TEXTURES = 1
TAGS = LICENSE_PLATE

; proper material parameters
PROP_... = ksAmbient, $" 0.5 * $BrightnessAdjustment "
PROP_... = ksDiffuse, $" 0.5 * $BrightnessAdjustment "
PROP_... = ksSpecular, 0.2
PROP_... = ksSpecularEXP, 80
PROP_... = sunSpecular, $" 0.8 / max(1 - $LettersSpecularDarkening, 0.1) "
PROP_... = sunSpecularEXP, 20
PROP_... = fresnelMaxLevel, 1
PROP_... = fresnelEXP, 5
PROP_... = fresnelC, 0.01
PROP_... = isAdditive, 1
PROP_... = extExtraSharpLocalReflections, 1

; light bouncing back
PROP_... = extBounceBack, $BounceBackBrightness

; optional glowing letters
PROP_... = extGlowingLettersLampsPI, $" 2 * pi "
PROP_... = extGlowingLettersLampsFactor, 1

; emissive mask for nicer license plate fallback
PROP_... = extEmissiveShapeMult, $EmissiveTotalMult
PROP_... = extEmissiveFadeX, $EmissiveFadeX
PROP_... = extEmissiveFadeY, $EmissiveFadeY

; shape, parallax
PROP_... = extDebugMode, $Debug
PROP_... = extDarkeningFactor, $LettersDarkening
PROP_... = extOcclusionFactor, $LettersSpecularDarkening
PROP_... = extWidthRatio, $TextureRatio
PROP_... = extLettersExtrude, $ExtrudeLetters
PROP_... = extLettersMult, $" 1 / ($LettersBrightnessFull - $LettersBrightnessStart) "
PROP_... = extLettersAdd, $" -$LettersBrightnessStart / ($LettersBrightnessFull - $LettersBrightnessStart) "
PROP_... = extParallaxHeight, $" $Depth * -0.007 "

_Resolution = $" def2( $Resolution, 1, 1 ) "
_LettersCenter = $" def( $LettersCenter, ${LettersStart:vec2} + ${LettersSize:vec2} / 2 ) "
_InsideCenter = $" def( $InsideCenter, ${InsideStart:vec2} + ${InsideSize:vec2} / 2 ) "

PROP_... = extLettersArea, $" vec4(2 * ${_Resolution:vec2} / ${LettersSize:vec2}, -2 * ${_LettersCenter:vec2} / ${LettersSize:vec2})"
PROP_... = extBorderedArea, $" vec4(2 * ${_Resolution:vec2} / ${InsideSize:vec2}, -2 * ${_InsideCenter:vec2} / ${InsideSize:vec2})"
PROP_... = extBorderedRadius, $" 1 / def2( ${InsideRadius:vec2}, 0, 0 ):clamp(0.001, 1) "

