---------------------------------------------------------------------------
-- FlightSimX Extended Material Properties
---------------------------------------------------------------------------

plugin material FSXMaterial
    name:"FlightSimX"
    classID:#(0x7e8caded, 0xb6927fa7)
    extends:Standard replaceUI:false
(
        parameters main rollout:params
        (
                bFresnelDiffuse    type:#boolean  ui:bDiffuse         default:false
                bFresnelReflection type:#boolean  ui:bReflection      default:false
                bFresnelSpecular   type:#boolean  ui:bSpecular        default:false
                texFresnelRamp     type:#texturemap
                bHasFresnelRamp    type:#boolean                      default:false
                texDetailMap       type:#texturemap
                bHasDetailMap      type:#boolean                      default:false

                bUsePrecip         type:#boolean  ui:bUsePrecip       default:false
                bUsePrecipOffset   type:#boolean  ui:bUsePrecipOffset default:false
                fPrecipOffset      type:#float    ui:POffset          default:0

                iBumpScale         type:#integer  ui:PBumpScale       default:1
                iDetailScale       type:#integer  ui:PDetailScale     default:1
                iEnvLevelScale     type:#integer  ui:ReflectScale     default:100
                fSpecMapPowerScale type:#float    ui:SpecMapPowScale  default:64

                bBlendInvBaseAlpha type:#boolean ui:specialEnvInvBaseAlpha default:false
                bBlendInvSpecAlpha type:#boolean ui:specialEnvInvSpecAlpha default:false
                bBlendDiffuseBaseAlpha          type:#boolean   ui:bBlendDiffuseBaseAlpha       default:false
                bBlendDiffuseInvSpecAlpha       type:#boolean   ui:bBlendDiffuseInvSpecAlpha    default:false
                bUseGlobalEnv      type:#boolean ui:specialUseGlobalEnv    default:false

                iSrcBlend         type:#integer ui:SrcBlend            default:2
                iDstBlend         type:#integer ui:DstBlend            default:1

                bAllowBloom          type:#boolean  ui:bAllowBloom         default:true
                bBloomCopy           type:#boolean  ui:bBloomCopy          default:false
                bBloomModulate       type:#boolean  ui:bBloomModulate      default:false
                bNoSpecularBloom     type:#boolean  ui:bNoSpecularBloom    default:false
                bAllowEmissiveBloom  type:#boolean  ui:bAllowEmissiveBloom default:false
                fSpecularBloomFloor  type:#float    ui:SpecularBloomFloor  default:0.9
                fAmbientLightScale   type:#float    ui:AmbientLightScale  default:1.0

                iEmissiveMode     type:#integer  ui:EmissiveMode        default:1

                bZTestAlpha       type:#boolean  ui:bZTestAlpha         default:false
                iAlphaTestMode    type:#integer  ui:AlphaTestMode       default:1
                fAlphaTestLevel   type:#float    ui:AlphaTestLevel      default:0

                bFinalAlphaWrite  type:#boolean  ui:bFinalAlphaWrite    default:false
                fFinalAlphaWriteValue   type:#float     ui:FinalAlphaWriteValue default:255.0

                bAssumeVerticalNormal   type:#boolean   ui:bAssumeVerticalNormal        default:false
                bZWriteAlpha            type:#boolean   ui:bZWriteAlpha                 default:false
                bNoZWrite               type:#boolean   ui:bNoZWrite                    default:false
                bVolumeShadow           type:#boolean   ui:bVolumeShadow                default:false
                bNoShadow               type:#boolean   ui:bNoShadow                    default:false
                bPrelitVertices         type:#boolean   ui:bPrelitVertices              default:false
                bNoBaseMaterialSpecular type:#boolean   ui:bNoBaseMaterialSpecular      default:false
                bSkinned                type:#boolean   ui:bSkinned                     default:false
                bDoubleSided            type:#boolean   ui:bDoubleSided                 default:false

                bBlendConstant            type:#boolean   ui:bBlendConstant             default:false
                bForceTextureAddressWrap  type:#boolean   ui:bForceTextureAddressWrap   default:false
                bForceTextureAddressClamp type:#boolean   ui:bForceTextureAddressClamp  default:false

                bIsPanelTexture         type:#boolean   ui:bIsPanelTexture              default:false
                bIsNNumberTexture       type:#boolean   ui:bIsNNumberTexture            default:false
        )

        rollout params "Flight Simulator Extended Params"
        (
                group "Other Texture Info"
                (
                        label lbl_Detail "Detail Map:" align:#left across:3
                        mapbutton chooseDetail "<<None>>" align:#left width:110 offset:[-25,0]
                        bitmap dispDetailBitmap bitmap:(bitmap 110 20) align:#right width:110 height:20

                        label lbl_DetailScale1 "Detail: " align:#left across:3
                        label lbl_DetailScale2 "1" align:#left offset:[-65,0]
                        slider   PDetailScale type:#integer align:#left range:[0,64,1] width:230 offset:[-130,0] ticks:16

                        label lbl_BumpScale1 "Bump: " align:#left across:3
                        label lbl_BumpScale2 "1" align:#left offset:[-65,0]
                        slider   PBumpScale type:#integer align:#left range:[0,64,1] width:230 offset:[-130,0] ticks:16
                )
                group "Fresnel Ramp"
                (
                        label lbl_Fresnel "FresnelRamp:" align:#left across:3
                        mapbutton chooseFresnel "<<None>>" align:#left width:110 offset:[-25,0]
                        bitmap dispBitmap bitmap:(bitmap 110 20) align:#right width:110 height:20
                        checkbox bDiffuse    "Diffuse"
                        checkbox bReflection "Reflection"
                        checkbox bSpecular   "Specular"
                )
                group "Precipitation"
                (
                        checkbox bUsePrecip       "Take into account" type:#boolean
                        checkbox bUsePrecipOffset "Apply offset to start" type:#boolean
                        label lbl_Offset1 "Offset: " align:#left across:3
                        label lbl_Offset2 "0.0" align:#left offset:[-65,0]
                        slider   POffset type:#float align:#left range:[0,1,0] width:230 offset:[-130,0]
                )
                group "Special Functionality"
                (
                        checkbox specialEnvInvBaseAlpha "Blend environment by inverse of diffuse alpha"
                        checkbox specialEnvInvSpecAlpha "Blend environment by specular map alpha"
                        checkbox bBlendDiffuseBaseAlpha "Blend diffuse by diffuse alpha"
                        checkbox bBlendDiffuseInvSpecAlpha "Blend diffuse by inverse of specular map alpha"
                        checkbox specialUseGlobalEnv    "Use global environment map as reflection"
                        label lbl_ReflectScale1 "Reflection Scale: " align:#left across:2
                        label lbl_ReflectScale2 "100" align:#left offset:[-60,0]
                        slider   ReflectScale type:#integer range:[0,100,100]
                        label lbl_SpecMapPowScale1 "Specular Map Power Scale: " align:#left across:2
                        label lbl_SpecMapPowScale2 "64.0" align:#left offset:[-15,0]
                        slider   SpecMapPowScale type:#integer range:[0,256,64]

                )
                group "Bloom"
                (
                        checkbox bAllowBloom    "Allow bloom"

                        checkbox bBloomCopy     "Bloom material by copying"
                        checkbox bBloomModulate "Bloom material modulating by alpha"

                        checkbox bNoSpecularBloom "No specular bloom"
                        checkbox bAllowEmissiveBloom "Allow emissive bloom"

                        label lbl_SpecularBloomFloor1 "Specular Bloom Floor: " align:#left across:2
                        label lbl_SpecularBloomFloor2 "0.9" align:#left offset:[-15,0]
                        slider   SpecularBloomFloor type:#float range:[0,1.0,0.9]

                        label lbl_AmbientLightScale "Ambient light scale: " align:#left across:2
                        label lbl_AmbientLightScale2 "1.0" align:#left offset:[-15,0]
                        slider   AmbientLightScale type:#float range:[0,1.0,1.0]
                )

                group "Framebuffer Blend"
                (
                        button butOpaque "Set Default Opaque" across:2
                        button butTransp "Set Default Transparent"
                        dropdownlist srcBlend "Source Blend:" items:#("Zero", "One", "SrcColor", "InvSrcColor", "SrcAlpha", "InvSrcAlpha", "DestAlpha", "InvDestAlpha", "DestColor", "InvDestColor")
                        dropdownlist dstBlend "Destination Blend:" items:#("Zero", "One", "SrcColor", "InvSrcColor", "SrcAlpha", "InvSrcAlpha", "DestAlpha", "InvDestAlpha", "DestColor", "InvDestColor")
                )

                group "Emissive Properties"
                (
                        dropdownlist emissiveMode "Emissive Mode:" items:#("Additive", "Blend", "AdditiveUserControlled", "BlendUserControlled" )
                )

                group "Material Alpha Test"
                (
                        checkbox bZTestAlpha "Z-Test Alpha"
                        label lbl_AlphaTestLevel1 "Alpha Test Level: " align:#left across:2
                        label lbl_AlphaTestLevel2 "0.0" align:#left offset:[-15,0]
                        slider   AlphaTestLevel type:#float range:[0.0,255.0,0.0]
                        dropdownlist AlphaTestMode "Alpha Test Mode:" items:#( "Never", "Less", "Equal", "LessEqual", "Greater", "NotEqual", "GreaterEqual", "Always" )
                )

                group "Final Alpha Blend"
                (
                        checkbox bFinalAlphaWrite "Set final alpha value at render time"
                        label lbl_FinalAlphaWrite1 "Final Alpha Multiply: " align:#left across:2
                        label lbl_FinalAlphaWrite2 "1.0" align:#left offset:[-15,0]
                        slider   FinalAlphaWriteValue type:#float range:[0.0,1.0,1.0]
                )

                group "Enhanced Parameters"
                (
                        checkbox bAssumeVerticalNormal  "Assume vertical normal"
                        checkbox bZWriteAlpha           "Z-Write Alpha"
                        checkbox bNoZWrite              "No Z Write"
                        checkbox bVolumeShadow          "Volume shadow"
                        checkbox bNoShadow              "No shadow"
                        checkbox bPrelitVertices        "Prelit vertices"
                        checkbox bNoBaseMaterialSpecular        "No Base Material Specular"
                        checkbox bSkinned               "Skinned mesh"
                        checkbox bDoubleSided           "Double sided"
                        checkbox bBlendConstant         "Blend Constant"
                        checkbox bForceTextureAddressWrap "Force Texture Address Wrap"
                        checkbox bForceTextureAddressClamp "Force Texture Address Clamp"
                )

                group "Aircraft Material Params"
                (
                        checkbox bIsPanelTexture        "Is virtual cockpit panel texture"
                        checkbox bIsNNumberTexture      "Is N-Number texture"
                )

                on butOpaque pressed do
                (
                        srcBlend.selection = 2
                        dstBlend.selection = 1
                )

                on butTransp pressed do
                (
                        srcBlend.selection = 5
                        dstBlend.selection = 6
                )

                on bBloomCopy changed val do
                (
                        if val == true do
                        (
                                bBloomModulate.state = false
                        )
                )

                on bBloomModulate changed val do
                (
                        if val == true do
                        (
                                bBloomCopy.state = false
                        )
                )

                on specialEnvInvBaseAlpha changed val do
                (
                        if val == true do
                        (
                                specialEnvInvSpecAlpha.state = false
                        )
                )

                on specialEnvInvSpecAlpha changed val do
                (
                        if val == true do
                        (
                                specialEnvInvBaseAlpha.state = false
                        )
                )

                on chooseFresnel picked texmap do
                (
                        if texmap != undefined then
                        (
                                texFresnelRamp = texmap
                                chooseFresnel.text = getFilenameFile texmap.filename as string
                                dispBitmap.bitmap = texmap.bitmap
                                bHasFresnelRamp = true
                        )
                        else
                        (
                                bHasFresnelRamp = false
                        )
                )
                on chooseDetail picked texmap do
                (
                        if texmap != undefined then
                        (
                                texDetailMap = texmap
                                chooseDetail.text = getFilenameFile texmap.filename as string
                                dispDetailBitmap.bitmap = texmap.bitmap
                                bHasDetailMap = true
                        )
                        else
                        (
                                bHasDetailMap = false
                        )
                )

                on POffset changed fNewVal do
                (
                        lbl_Offset2.text = fNewVal as string
                )

                on PDetailScale changed fNewVal do
                (
                        lbl_DetailScale2.text = fNewVal as string
                )

                on PBumpScale changed fNewVal do
                (
                        lbl_BumpScale2.text = fNewVal as string
                )

                on ReflectScale changed fNewVal do
                (
                        lbl_ReflectScale2.text = fNewVal as string
                )

                on SpecMapPowScale changed fNewVal do
                (
                        lbl_SpecMapPowScale2.text = fNewVal as string
                )

                on SpecularBloomFloor changed fNewVal do
                (
                        lbl_SpecularBloomFloor2.text = fNewVal as string
                )

                on AmbientLightScale changed fNewVal do
                (
                        lbl_AmbientLightScale2.text = fNewVal as string
                )

                on AlphaTestLevel changed fNewVal do
                (
                        lbl_AlphaTestLevel2.text = fNewVal as string
                )

                on FinalAlphaWriteValue changed fNewVal do
                (
                        lbl_FinalAlphaWrite2.text = fNewVal as string
                )

                on params open do
                (
                        lbl_Offset2.text       = POffset.value as string
                        lbl_DetailScale2.text  = PDetailScale.value as string
                        lbl_BumpScale2.text    = PBumpScale.value as string
                        lbl_ReflectScale2.text = ReflectScale.value as string
                        lbl_SpecMapPowScale2.text = SpecMapPowScale.value as string
                        lbl_SpecularBloomFloor2.text = SpecularBloomFloor.value as string
                        lbl_AmbientLightScale2.text = AmbientLightScale.value as string
                        lbl_AlphaTestLevel2.text = AlphaTestLevel.value as string
                        lbl_FinalAlphaWrite2.text = FinalAlphaWriteValue.value as string

                        if bHasFresnelRamp then
                        (
                                chooseFresnel.text = getFilenameFile texFresnelRamp.filename as string
                                try
                                (
                                        dispBitmap.bitmap = texFresnelRamp.bitmap
                                )
                                catch
                                (
                                        dispBitmap.bitmap = bitmap 110 20
                                )
                        )
                        else
                                dispBitmap.bitmap = bitmap 110 20

                        if bHasDetailMap then
                        (
                                chooseDetail.text = getFilenameFile texDetailMap.filename as string
                                try
								(
									dispDetailBitmap.bitmap = texDetailMap.bitmap
								)
								catch
								(
									dispBitmap.bitmap = bitmap 110 20
								)
                        )
                        else
                                dispDetailBitmap.bitmap = bitmap 110 20
                )
        )
)
