Explorar o código

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe %!s(int64=8) %!d(string=hai) anos
pai
achega
3fbe1ef9f0
Modificáronse 24 ficheiros con 1528 adicións e 112 borrados
  1. BIN=BIN
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Plugins/BabylonExport.Entities.dll
  2. 334 0
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Shader/UnitySpecular.shader
  3. 345 0
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Shader/UnityStandard.shader
  4. 480 0
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/BabylonShaderInterface.cs
  5. 3 1
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExportationOptions.cs
  6. 8 4
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExporterWindow.cs
  7. 7 5
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Cameras.cs
  8. 80 13
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Materials.cs
  9. 11 3
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Meshes.cs
  10. 8 1
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.cs
  11. 6 0
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/Tools.cs
  12. 3 0
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Templates/Config/index.html
  13. 74 67
      Exporters/Unity 5/EditorToolkit/Assets/Babylon/Templates/Shaders/amiga.template
  14. BIN=BIN
      Exporters/Unity 5/EditorToolkit/Redist/Asset Store-5.x/BabylonJS/BabylonJS Editor Toolkit.unitypackage
  15. 3 1
      Playground/zipContent/index.html
  16. 1 0
      Tools/Gulp/config.json
  17. 14 4
      canvas2D/src/Engine/babylon.renderablePrim2d.ts
  18. 4 0
      dist/preview release/canvas2D/babylon.canvas2d.d.ts
  19. 12 3
      dist/preview release/canvas2D/babylon.canvas2d.js
  20. 6 6
      dist/preview release/canvas2D/babylon.canvas2d.min.js
  21. 1 0
      dist/preview release/what's new.md
  22. 111 0
      src/Cameras/Holographic/babylon.holographicCamera.ts
  23. 13 3
      src/babylon.engine.ts
  24. 4 1
      src/babylon.scene.ts

BIN=BIN
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Plugins/BabylonExport.Entities.dll


+ 334 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Shader/UnitySpecular.shader

@@ -0,0 +1,334 @@
+Shader "BabylonJS/Materials/PBR Material (Specular)"
+{
+	Properties
+	{
+		_Color("Color", Color) = (1,1,1,1)
+		_MainTex("Albedo", 2D) = "white" {}
+		
+		_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
+
+		_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
+		_GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0
+		[Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0
+
+		_SpecColor("Specular", Color) = (0.2,0.2,0.2)
+		_SpecGlossMap("Specular", 2D) = "white" {}
+		[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
+		[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
+
+		_BumpScale("Scale", Float) = 1.0
+		_BumpMap("Normal Map", 2D) = "bump" {}
+
+		_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
+		_ParallaxMap ("Height Map", 2D) = "black" {}
+
+		_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
+		_OcclusionMap("Occlusion", 2D) = "white" {}
+
+		_EmissionColor("Color", Color) = (0,0,0)
+		_EmissionMap("Emission", 2D) = "white" {}
+		
+		_DetailMask("Detail Mask", 2D) = "white" {}
+
+		_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
+		_DetailNormalMapScale("Scale", Float) = 1.0
+		_DetailNormalMap("Normal Map", 2D) = "bump" {}
+
+		[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
+
+		// Babylon Properties (Lighting & Blending)
+		[Enum(Disable,0,Additive,1,Combine,2,Subtract,3,Multiply,4,Maximized,5,OneOne,6)] _AlphaMode ("Alpha Blending Mode", int) = 2
+		[ToggleOff] _DisableLighting("Disable Surface Lighting", Int) = 0
+		[ToggleOff] _UseEmissiveAsIllumination("Use Emissive Illumination", Int) = 0
+
+		// Blending state
+		[HideInInspector] _Mode ("__mode", Float) = 0.0
+		[HideInInspector] _SrcBlend ("__src", Float) = 1.0
+		[HideInInspector] _DstBlend ("__dst", Float) = 0.0
+		[HideInInspector] _ZWrite ("__zw", Float) = 1.0
+	}
+
+	CGINCLUDE
+		#define UNITY_SETUP_BRDF_INPUT SpecularSetup
+	ENDCG
+
+	SubShader
+	{
+		Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
+		LOD 300
+	
+
+		// ------------------------------------------------------------------
+		//  Base forward pass (directional light, emission, lightmaps, ...)
+		Pass
+		{
+			Name "FORWARD" 
+			Tags { "LightMode" = "ForwardBase" }
+
+			Blend [_SrcBlend] [_DstBlend]
+			ZWrite [_ZWrite]
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile_fwdbase
+			#pragma multi_compile_fog
+
+			#pragma vertex vertBase
+			#pragma fragment fragBase
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Additive forward pass (one light per pass)
+		Pass
+		{
+			Name "FORWARD_DELTA"
+			Tags { "LightMode" = "ForwardAdd" }
+			Blend [_SrcBlend] One
+			Fog { Color (0,0,0,0) } // in additive pass fog should be black
+			ZWrite Off
+			ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile_fwdadd_fullshadows
+			#pragma multi_compile_fog
+
+			#pragma vertex vertAdd
+			#pragma fragment fragAdd
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Shadow rendering pass
+		Pass {
+			Name "ShadowCaster"
+			Tags { "LightMode" = "ShadowCaster" }
+
+			ZWrite On ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _PARALLAXMAP
+			#pragma multi_compile_shadowcaster
+
+			#pragma vertex vertShadowCaster
+			#pragma fragment fragShadowCaster
+
+			#include "UnityStandardShadow.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Deferred pass
+		Pass
+		{
+			Name "DEFERRED"
+			Tags { "LightMode" = "Deferred" }
+
+			CGPROGRAM
+			#pragma target 3.0
+			#pragma exclude_renderers nomrt
+
+
+			// -------------------------------------
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile ___ UNITY_HDR_ON
+			#pragma multi_compile ___ LIGHTMAP_ON
+			#pragma multi_compile ___ DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
+			#pragma multi_compile ___ DYNAMICLIGHTMAP_ON
+
+			#pragma vertex vertDeferred
+			#pragma fragment fragDeferred
+
+			#include "UnityStandardCore.cginc"
+
+			ENDCG
+		}
+
+		// ------------------------------------------------------------------
+		// Extracts information for lightmapping, GI (emission, albedo, ...)
+		// This pass it not used during regular rendering.
+		Pass
+		{
+			Name "META" 
+			Tags { "LightMode"="Meta" }
+
+			Cull Off
+
+			CGPROGRAM
+			#pragma vertex vert_meta
+			#pragma fragment frag_meta
+
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature ___ _DETAIL_MULX2
+
+			#include "UnityStandardMeta.cginc"
+			ENDCG
+		}
+	}
+
+	SubShader
+	{
+		Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
+		LOD 150
+
+		// ------------------------------------------------------------------
+		//  Base forward pass (directional light, emission, lightmaps, ...)
+		Pass
+		{
+			Name "FORWARD" 
+			Tags { "LightMode" = "ForwardBase" }
+
+			Blend [_SrcBlend] [_DstBlend]
+			ZWrite [_ZWrite]
+
+			CGPROGRAM
+			#pragma target 2.0
+			
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION 
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
+
+			#pragma skip_variants SHADOWS_SOFT DYNAMICLIGHTMAP_ON DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
+			
+			#pragma multi_compile_fwdbase
+			#pragma multi_compile_fog
+
+			#pragma vertex vertBase
+			#pragma fragment fragBase
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Additive forward pass (one light per pass)
+		Pass
+		{
+			Name "FORWARD_DELTA"
+			Tags { "LightMode" = "ForwardAdd" }
+			Blend [_SrcBlend] One
+			Fog { Color (0,0,0,0) } // in additive pass fog should be black
+			ZWrite Off
+			ZTest LEqual
+			
+			CGPROGRAM
+			#pragma target 2.0
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
+			#pragma skip_variants SHADOWS_SOFT
+			
+			#pragma multi_compile_fwdadd_fullshadows
+			#pragma multi_compile_fog
+			
+			#pragma vertex vertAdd
+			#pragma fragment fragAdd
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Shadow rendering pass
+		Pass {
+			Name "ShadowCaster"
+			Tags { "LightMode" = "ShadowCaster" }
+			
+			ZWrite On ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 2.0
+
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma skip_variants SHADOWS_SOFT
+			#pragma multi_compile_shadowcaster
+
+			#pragma vertex vertShadowCaster
+			#pragma fragment fragShadowCaster
+
+			#include "UnityStandardShadow.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		// Extracts information for lightmapping, GI (emission, albedo, ...)
+		// This pass it not used during regular rendering.
+		Pass
+		{
+			Name "META" 
+			Tags { "LightMode"="Meta" }
+
+			Cull Off
+
+			CGPROGRAM
+			#pragma vertex vert_meta
+			#pragma fragment frag_meta
+
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _SPECGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature ___ _DETAIL_MULX2
+
+			#include "UnityStandardMeta.cginc"
+			ENDCG
+		}
+	}
+
+	FallBack "VertexLit"
+	CustomEditor "BabylonShaderInterface"
+}

+ 345 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Shader/UnityStandard.shader

@@ -0,0 +1,345 @@
+Shader "BabylonJS/Materials/PBR Material"
+{
+	Properties
+	{
+		_Color("Color", Color) = (1,1,1,1)
+		_MainTex("Albedo", 2D) = "white" {}
+		
+		_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
+
+		// Babylon Properties (Roughness)
+		_Roughness("Roughness", Range(0.0, 10.0)) = 1.0
+		[ToggleOff] _UseRoughnessFromMetallicTextureAlpha("From Alpha", Int) = 0
+		[ToggleOff] _UseRoughnessFromMetallicTextureGreen("From Green", Int) = 0
+
+		_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
+		_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
+		[Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0
+
+		[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
+		_MetallicGlossMap("Metallic", 2D) = "white" {}
+
+		[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
+		[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
+
+		_BumpScale("Scale", Float) = 1.0
+		_BumpMap("Normal Map", 2D) = "bump" {}
+
+		_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
+		_ParallaxMap ("Height Map", 2D) = "black" {}
+
+		_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
+		_OcclusionMap("Occlusion", 2D) = "white" {}
+
+		_EmissionColor("Color", Color) = (0,0,0)
+		_EmissionMap("Emission", 2D) = "white" {}
+		
+		_DetailMask("Detail Mask", 2D) = "white" {}
+
+		_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
+		_DetailNormalMapScale("Scale", Float) = 1.0
+		_DetailNormalMap("Normal Map", 2D) = "bump" {}
+
+		[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
+
+		// Babylon Properties (Lighting & Blending)
+		[Enum(Disable,0,Additive,1,Combine,2,Subtract,3,Multiply,4,Maximized,5,OneOne,6)] _AlphaMode ("Alpha Blending Mode", int) = 2
+		[ToggleOff] _DisableLighting("Disable Surface Lighting", Int) = 0
+		[ToggleOff] _UseEmissiveAsIllumination("Use Emissive Illumination", Int) = 0
+
+		// Blending state
+		[HideInInspector] _Mode ("__mode", Float) = 0.0
+		[HideInInspector] _SrcBlend ("__src", Float) = 1.0
+		[HideInInspector] _DstBlend ("__dst", Float) = 0.0
+		[HideInInspector] _ZWrite ("__zw", Float) = 1.0
+	}
+
+	CGINCLUDE
+		#define UNITY_SETUP_BRDF_INPUT MetallicSetup
+	ENDCG
+
+	SubShader
+	{
+		Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
+		LOD 300
+	
+
+		// ------------------------------------------------------------------
+		//  Base forward pass (directional light, emission, lightmaps, ...)
+		Pass
+		{
+			Name "FORWARD" 
+			Tags { "LightMode" = "ForwardBase" }
+
+			Blend [_SrcBlend] [_DstBlend]
+			ZWrite [_ZWrite]
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile_fwdbase
+			#pragma multi_compile_fog
+
+			#pragma vertex vertBase
+			#pragma fragment fragBase
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Additive forward pass (one light per pass)
+		Pass
+		{
+			Name "FORWARD_DELTA"
+			Tags { "LightMode" = "ForwardAdd" }
+			Blend [_SrcBlend] One
+			Fog { Color (0,0,0,0) } // in additive pass fog should be black
+			ZWrite Off
+			ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile_fwdadd_fullshadows
+			#pragma multi_compile_fog
+
+
+			#pragma vertex vertAdd
+			#pragma fragment fragAdd
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Shadow rendering pass
+		Pass {
+			Name "ShadowCaster"
+			Tags { "LightMode" = "ShadowCaster" }
+
+			ZWrite On ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 3.0
+
+			// -------------------------------------
+
+
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _PARALLAXMAP
+			#pragma multi_compile_shadowcaster
+
+			#pragma vertex vertShadowCaster
+			#pragma fragment fragShadowCaster
+
+			#include "UnityStandardShadow.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Deferred pass
+		Pass
+		{
+			Name "DEFERRED"
+			Tags { "LightMode" = "Deferred" }
+
+			CGPROGRAM
+			#pragma target 3.0
+			#pragma exclude_renderers nomrt
+
+
+			// -------------------------------------
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			#pragma shader_feature _PARALLAXMAP
+
+			#pragma multi_compile ___ UNITY_HDR_ON
+			#pragma multi_compile ___ LIGHTMAP_ON
+			#pragma multi_compile ___ DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
+			#pragma multi_compile ___ DYNAMICLIGHTMAP_ON
+
+			#pragma vertex vertDeferred
+			#pragma fragment fragDeferred
+
+			#include "UnityStandardCore.cginc"
+
+			ENDCG
+		}
+
+		// ------------------------------------------------------------------
+		// Extracts information for lightmapping, GI (emission, albedo, ...)
+		// This pass it not used during regular rendering.
+		Pass
+		{
+			Name "META" 
+			Tags { "LightMode"="Meta" }
+
+			Cull Off
+
+			CGPROGRAM
+			#pragma vertex vert_meta
+			#pragma fragment frag_meta
+
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature ___ _DETAIL_MULX2
+
+			#include "UnityStandardMeta.cginc"
+			ENDCG
+		}
+	}
+
+	SubShader
+	{
+		Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
+		LOD 150
+
+		// ------------------------------------------------------------------
+		//  Base forward pass (directional light, emission, lightmaps, ...)
+		Pass
+		{
+			Name "FORWARD" 
+			Tags { "LightMode" = "ForwardBase" }
+
+			Blend [_SrcBlend] [_DstBlend]
+			ZWrite [_ZWrite]
+
+			CGPROGRAM
+			#pragma target 2.0
+			
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _EMISSION 
+			#pragma shader_feature _METALLICGLOSSMAP 
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
+			// SM2.0: NOT SUPPORTED shader_feature ___ _DETAIL_MULX2
+			// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
+
+			#pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
+
+			#pragma multi_compile_fwdbase
+			#pragma multi_compile_fog
+
+			#pragma vertex vertBase
+			#pragma fragment fragBase
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Additive forward pass (one light per pass)
+		Pass
+		{
+			Name "FORWARD_DELTA"
+			Tags { "LightMode" = "ForwardAdd" }
+			Blend [_SrcBlend] One
+			Fog { Color (0,0,0,0) } // in additive pass fog should be black
+			ZWrite Off
+			ZTest LEqual
+			
+			CGPROGRAM
+			#pragma target 2.0
+
+			#pragma shader_feature _NORMALMAP
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
+			#pragma shader_feature ___ _DETAIL_MULX2
+			// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
+			#pragma skip_variants SHADOWS_SOFT
+			
+			#pragma multi_compile_fwdadd_fullshadows
+			#pragma multi_compile_fog
+			
+			#pragma vertex vertAdd
+			#pragma fragment fragAdd
+			#include "UnityStandardCoreForward.cginc"
+
+			ENDCG
+		}
+		// ------------------------------------------------------------------
+		//  Shadow rendering pass
+		Pass {
+			Name "ShadowCaster"
+			Tags { "LightMode" = "ShadowCaster" }
+			
+			ZWrite On ZTest LEqual
+
+			CGPROGRAM
+			#pragma target 2.0
+
+			#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma skip_variants SHADOWS_SOFT
+			#pragma multi_compile_shadowcaster
+
+			#pragma vertex vertShadowCaster
+			#pragma fragment fragShadowCaster
+
+			#include "UnityStandardShadow.cginc"
+
+			ENDCG
+		}
+
+		// ------------------------------------------------------------------
+		// Extracts information for lightmapping, GI (emission, albedo, ...)
+		// This pass it not used during regular rendering.
+		Pass
+		{
+			Name "META" 
+			Tags { "LightMode"="Meta" }
+
+			Cull Off
+
+			CGPROGRAM
+			#pragma vertex vert_meta
+			#pragma fragment frag_meta
+
+			#pragma shader_feature _EMISSION
+			#pragma shader_feature _METALLICGLOSSMAP
+			#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
+			#pragma shader_feature ___ _DETAIL_MULX2
+
+			#include "UnityStandardMeta.cginc"
+			ENDCG
+		}
+	}
+
+	Dependency "BabylonMaterial" = "Hidden/Babylon/Material"
+
+	FallBack "VertexLit"
+	CustomEditor "BabylonShaderInterface"
+}

+ 480 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/BabylonShaderInterface.cs

@@ -0,0 +1,480 @@
+using System;
+using UnityEngine;
+
+namespace UnityEditor
+{
+	public class BabylonShaderInterface : ShaderGUI
+	{
+		private enum WorkflowMode
+		{
+			Specular,
+			Metallic,
+			Dielectric
+		}
+
+		public enum BlendMode
+		{
+			Opaque,
+			Cutout,
+			Fade,		// Old school alpha-blending mode, fresnel does not affect amount of transparency
+			Transparent // Physically plausible transparency mode, implemented as alpha pre-multiply
+		}
+
+		public enum SmoothnessMapChannel
+		{
+			SpecularMetallicAlpha,
+			AlbedoAlpha,
+		}
+
+		private static class Styles
+		{
+			public static GUIStyle optionsButton = "PaneOptions";
+			public static GUIContent uvSetLabel = new GUIContent("UV Set");
+			public static GUIContent[] uvSetOptions = new GUIContent[] { new GUIContent("UV channel 0"), new GUIContent("UV channel 1") };
+
+			public static string emptyTootip = "";
+			public static GUIContent albedoText = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
+			public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
+			public static GUIContent specularMapText = new GUIContent("Specular", "Specular (RGB) and Smoothness (A)");
+			public static GUIContent metallicMapText = new GUIContent("Metallic", "Metallic (R) and Smoothness (A)");
+			public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness value");
+			public static GUIContent smoothnessScaleText = new GUIContent("Smoothness", "Smoothness scale factor");
+			public static GUIContent smoothnessMapChannelText = new GUIContent("Source", "Smoothness texture and channel");
+			public static GUIContent highlightsText = new GUIContent("Specular Highlights", "Specular Highlights");
+			public static GUIContent reflectionsText = new GUIContent("Reflections", "Glossy Reflections");
+			public static GUIContent alphaModeText = new GUIContent("Alpha Blending Mode", "Alpha Blending Mode");
+			public static GUIContent disableLightingText = new GUIContent("Disable Surface Lighting", "Disable Surface Lighting");
+			public static GUIContent useEmissiveAsIlluminationText = new GUIContent("Use Emissive Illumination", "Use Emissive Illumination");
+			public static GUIContent roughnessText = new GUIContent("Roughness", "Roughness");
+			public static GUIContent useRoughnessAlphaText = new GUIContent("From Alpha", "From Alpha");
+			public static GUIContent useRoughnessGreenText = new GUIContent("From Green", "From Green");
+			public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
+			public static GUIContent heightMapText = new GUIContent("Height Map", "Height Map (G)");
+			public static GUIContent occlusionText = new GUIContent("Occlusion", "Occlusion (G)");
+			public static GUIContent emissionText = new GUIContent("Emission", "Emission (RGB)");
+			public static GUIContent detailMaskText = new GUIContent("Detail Mask", "Mask for Secondary Maps (A)");
+			public static GUIContent detailAlbedoText = new GUIContent("Detail Albedo x2", "Albedo (RGB) multiplied by 2");
+			public static GUIContent detailNormalMapText = new GUIContent("Normal Map", "Normal Map");
+
+			public static string whiteSpaceString = " ";
+			public static string primaryMapsText = "Main Maps";
+			public static string secondaryMapsText = "Secondary Maps";
+			public static string babylonText = "Babylon Rendering Options";
+			public static string forwardText = "Forward Rendering Options";
+			public static string renderingMode = "Rendering Mode";
+			public static GUIContent emissiveWarning = new GUIContent ("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
+			public static GUIContent emissiveColorWarning = new GUIContent ("Ensure emissive color is non-black for emission to have effect.");
+			public static readonly string[] blendNames = Enum.GetNames (typeof (BlendMode));
+		}
+
+		MaterialProperty blendMode = null;
+		MaterialProperty albedoMap = null;
+		MaterialProperty albedoColor = null;
+		MaterialProperty alphaCutoff = null;
+		MaterialProperty specularMap = null;
+		MaterialProperty specularColor = null;
+		MaterialProperty metallicMap = null;
+		MaterialProperty metallic = null;
+		MaterialProperty smoothness = null;
+		MaterialProperty smoothnessScale = null;
+		MaterialProperty smoothnessMapChannel = null;
+		MaterialProperty highlights = null;
+		MaterialProperty reflections = null;
+		MaterialProperty alphaMode = null;
+		MaterialProperty disableLighting = null;
+		MaterialProperty useEmissiveAsIllumination = null;
+		MaterialProperty roughness = null;
+		MaterialProperty useRoughnessAlpha = null;
+		MaterialProperty useRoughnessGreen = null;
+		MaterialProperty bumpScale = null;
+		MaterialProperty bumpMap = null;
+		MaterialProperty occlusionStrength = null;
+		MaterialProperty occlusionMap = null;
+		MaterialProperty heigtMapScale = null;
+		MaterialProperty heightMap = null;
+		MaterialProperty emissionColorForRendering = null;
+		MaterialProperty emissionMap = null;
+		MaterialProperty detailMask = null;
+		MaterialProperty detailAlbedoMap = null;
+		MaterialProperty detailNormalMapScale = null;
+		MaterialProperty detailNormalMap = null;
+		MaterialProperty uvSetSecondary = null;
+
+		MaterialEditor m_MaterialEditor;
+		WorkflowMode m_WorkflowMode = WorkflowMode.Specular;
+		ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, 99f, 1/99f, 3f);
+
+		bool m_FirstTimeApply = true;
+
+		public void FindProperties (MaterialProperty[] props)
+		{
+			blendMode = FindProperty ("_Mode", props);
+			albedoMap = FindProperty ("_MainTex", props);
+			albedoColor = FindProperty ("_Color", props);
+			alphaCutoff = FindProperty ("_Cutoff", props);
+			specularMap = FindProperty ("_SpecGlossMap", props, false);
+			specularColor = FindProperty ("_SpecColor", props, false);
+			metallicMap = FindProperty ("_MetallicGlossMap", props, false);
+			metallic = FindProperty ("_Metallic", props, false);
+			if (specularMap != null && specularColor != null)
+				m_WorkflowMode = WorkflowMode.Specular;
+			else if (metallicMap != null && metallic != null)
+				m_WorkflowMode = WorkflowMode.Metallic;
+			else
+				m_WorkflowMode = WorkflowMode.Dielectric;
+			smoothness = FindProperty ("_Glossiness", props);
+			smoothnessScale = FindProperty ("_GlossMapScale", props, false);
+			smoothnessMapChannel = FindProperty ("_SmoothnessTextureChannel", props, false);
+			highlights = FindProperty ("_SpecularHighlights", props, false);
+			reflections = FindProperty ("_GlossyReflections", props, false);
+			disableLighting = FindProperty ("_DisableLighting", props, false);
+			useEmissiveAsIllumination = FindProperty ("_UseEmissiveAsIllumination", props, false);
+			roughness = FindProperty ("_Roughness", props, false);
+			useRoughnessAlpha = FindProperty ("_UseRoughnessFromMetallicTextureAlpha", props, false);
+			useRoughnessGreen = FindProperty ("_UseRoughnessFromMetallicTextureGreen", props, false);
+			bumpScale = FindProperty ("_BumpScale", props);
+			bumpMap = FindProperty ("_BumpMap", props);
+			heigtMapScale = FindProperty ("_Parallax", props);
+			heightMap = FindProperty("_ParallaxMap", props);
+			occlusionStrength = FindProperty ("_OcclusionStrength", props);
+			occlusionMap = FindProperty ("_OcclusionMap", props);
+			emissionColorForRendering = FindProperty ("_EmissionColor", props);
+			emissionMap = FindProperty ("_EmissionMap", props);
+			detailMask = FindProperty ("_DetailMask", props);
+			detailAlbedoMap = FindProperty ("_DetailAlbedoMap", props);
+			detailNormalMapScale = FindProperty ("_DetailNormalMapScale", props);
+			detailNormalMap = FindProperty ("_DetailNormalMap", props);
+			uvSetSecondary = FindProperty ("_UVSec", props);
+			alphaMode = FindProperty ("_AlphaMode", props);
+		}
+
+		public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
+		{
+			FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
+			m_MaterialEditor = materialEditor;
+			Material material = materialEditor.target as Material;
+
+			// Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing
+			// material to a standard shader.
+			// Do this before any GUI code has been issued to prevent layout issues in subsequent GUILayout statements (case 780071)
+			if (m_FirstTimeApply)
+			{
+				MaterialChanged(material, m_WorkflowMode);
+				m_FirstTimeApply = false;
+			}
+
+			ShaderPropertiesGUI (material);
+		}
+
+		public void ShaderPropertiesGUI (Material material)
+		{
+			// Use default labelWidth
+			EditorGUIUtility.labelWidth = 0f;
+
+			// Detect any changes to the material
+			EditorGUI.BeginChangeCheck();
+			{
+				BlendModePopup();
+
+				// Primary properties
+				GUILayout.Label (Styles.primaryMapsText, EditorStyles.boldLabel);
+				DoAlbedoArea(material);
+				DoSpecularMetallicArea();
+
+				m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
+				m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightMap.textureValue != null ? heigtMapScale : null);
+				m_MaterialEditor.TexturePropertySingleLine(Styles.occlusionText, occlusionMap, occlusionMap.textureValue != null ? occlusionStrength : null);
+				DoEmissionArea(material);
+				m_MaterialEditor.TexturePropertySingleLine(Styles.detailMaskText, detailMask);
+				EditorGUI.BeginChangeCheck();
+				m_MaterialEditor.TextureScaleOffsetProperty(albedoMap);
+				if (EditorGUI.EndChangeCheck())
+					emissionMap.textureScaleAndOffset = albedoMap.textureScaleAndOffset; // Apply the main texture scale and offset to the emission texture as well, for Enlighten's sake
+
+				EditorGUILayout.Space();
+
+				// Secondary properties
+				GUILayout.Label(Styles.secondaryMapsText, EditorStyles.boldLabel);
+				m_MaterialEditor.TexturePropertySingleLine(Styles.detailAlbedoText, detailAlbedoMap);
+				m_MaterialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, detailNormalMap, detailNormalMapScale);
+				m_MaterialEditor.TextureScaleOffsetProperty(detailAlbedoMap);
+				m_MaterialEditor.ShaderProperty(uvSetSecondary, Styles.uvSetLabel.text);
+
+				// Third properties
+				GUILayout.Label(Styles.babylonText, EditorStyles.boldLabel);
+				if (alphaMode != null)
+					m_MaterialEditor.ShaderProperty(alphaMode, Styles.alphaModeText);
+				if (disableLighting != null)
+					m_MaterialEditor.ShaderProperty(disableLighting, Styles.disableLightingText);
+				if (useEmissiveAsIllumination != null)
+					m_MaterialEditor.ShaderProperty(useEmissiveAsIllumination, Styles.useEmissiveAsIlluminationText);
+
+				// Forth properties
+				GUILayout.Label(Styles.forwardText, EditorStyles.boldLabel);
+				if (highlights != null)
+					m_MaterialEditor.ShaderProperty(highlights, Styles.highlightsText);
+				if (reflections != null)
+					m_MaterialEditor.ShaderProperty(reflections, Styles.reflectionsText);
+			}
+			if (EditorGUI.EndChangeCheck())
+			{
+				foreach (var obj in blendMode.targets)
+					MaterialChanged((Material)obj, m_WorkflowMode);
+			}
+		}
+
+		internal void DetermineWorkflow(MaterialProperty[] props)
+		{
+			if (FindProperty("_SpecGlossMap", props, false) != null && FindProperty("_SpecColor", props, false) != null)
+				m_WorkflowMode = WorkflowMode.Specular;
+			else if (FindProperty("_MetallicGlossMap", props, false) != null && FindProperty("_Metallic", props, false) != null)
+				m_WorkflowMode = WorkflowMode.Metallic;
+			else
+				m_WorkflowMode = WorkflowMode.Dielectric;
+		}
+
+		public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
+		{
+			// _Emission property is lost after assigning Standard shader to the material
+			// thus transfer it before assigning the new shader
+			if (material.HasProperty("_Emission"))
+			{
+				material.SetColor("_EmissionColor", material.GetColor("_Emission"));
+			}
+
+			base.AssignNewShaderToMaterial(material, oldShader, newShader);
+
+			if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
+			{
+				SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
+				return;
+			}
+
+			BlendMode blendMode = BlendMode.Opaque;
+			if (oldShader.name.Contains("/Transparent/Cutout/"))
+			{
+				blendMode = BlendMode.Cutout;
+			}
+			else if (oldShader.name.Contains("/Transparent/"))
+			{
+				// NOTE: legacy shaders did not provide physically based transparency
+				// therefore Fade mode
+				blendMode = BlendMode.Fade;
+			}
+			material.SetFloat("_Mode", (float)blendMode);
+
+			DetermineWorkflow( MaterialEditor.GetMaterialProperties (new Material[] { material }) );
+			MaterialChanged(material, m_WorkflowMode);
+		}
+
+		void BlendModePopup()
+		{
+			EditorGUI.showMixedValue = blendMode.hasMixedValue;
+			var mode = (BlendMode)blendMode.floatValue;
+
+			EditorGUI.BeginChangeCheck();
+			mode = (BlendMode)EditorGUILayout.Popup(Styles.renderingMode, (int)mode, Styles.blendNames);
+			if (EditorGUI.EndChangeCheck())
+			{
+				m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Mode");
+				blendMode.floatValue = (float)mode;
+			}
+
+			EditorGUI.showMixedValue = false;
+		}
+
+		void DoAlbedoArea(Material material)
+		{
+			m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
+			if (((BlendMode)material.GetFloat("_Mode") == BlendMode.Cutout))
+			{
+				m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel+1);
+			}
+		}
+
+		void DoEmissionArea(Material material)
+		{
+			bool showHelpBox = !HasValidEmissiveKeyword(material);
+			
+			bool hadEmissionTexture = emissionMap.textureValue != null;
+
+			// Texture and HDR color controls
+			m_MaterialEditor.TexturePropertyWithHDRColor(Styles.emissionText, emissionMap, emissionColorForRendering, m_ColorPickerHDRConfig, false);
+
+			// If texture was assigned and color was black set color to white
+			float brightness = emissionColorForRendering.colorValue.maxColorComponent;
+			if (emissionMap.textureValue != null && !hadEmissionTexture && brightness <= 0f)
+				emissionColorForRendering.colorValue = Color.white;
+
+			// Emission for GI?
+			m_MaterialEditor.LightmapEmissionProperty (MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
+			
+			if (showHelpBox)
+			{
+				EditorGUILayout.HelpBox(Styles.emissiveWarning.text, MessageType.Warning);
+			}
+		}
+
+		void DoSpecularMetallicArea()
+		{
+			bool hasGlossMap = false;
+			if (m_WorkflowMode == WorkflowMode.Specular)
+			{
+				hasGlossMap = specularMap.textureValue != null;
+				m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapText, specularMap, hasGlossMap ? null : specularColor);
+			}
+			else if (m_WorkflowMode == WorkflowMode.Metallic)
+			{
+				hasGlossMap = metallicMap.textureValue != null;
+				m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap, hasGlossMap ? null : metallic);
+			}
+
+			bool showSmoothnessScale = hasGlossMap;
+			if (smoothnessMapChannel != null)
+			{
+				int smoothnessChannel = (int) smoothnessMapChannel.floatValue;
+				if (smoothnessChannel == (int) SmoothnessMapChannel.AlbedoAlpha)
+					showSmoothnessScale = true;
+			}
+
+			int indentation = 2; // align with labels of texture properties
+
+			// Roughness properties
+			if (roughness != null)
+				m_MaterialEditor.ShaderProperty(roughness, Styles.roughnessText, indentation);
+			if (useRoughnessAlpha != null)
+				m_MaterialEditor.ShaderProperty(useRoughnessAlpha, Styles.useRoughnessAlphaText, indentation);
+			if (useRoughnessGreen != null)
+				m_MaterialEditor.ShaderProperty(useRoughnessGreen, Styles.useRoughnessGreenText, indentation);
+			if (roughness != null || useRoughnessAlpha != null || useRoughnessGreen != null)
+  				EditorGUILayout.Space();
+
+			m_MaterialEditor.ShaderProperty(showSmoothnessScale ? smoothnessScale : smoothness, showSmoothnessScale ? Styles.smoothnessScaleText : Styles.smoothnessText, indentation);
+		
+			++indentation;
+			if (smoothnessMapChannel != null)
+				m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText, indentation);
+		}
+
+		public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
+		{
+			switch (blendMode)
+			{
+				case BlendMode.Opaque:
+					material.SetOverrideTag("RenderType", "");
+					material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
+					material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
+					material.SetInt("_ZWrite", 1);
+					material.DisableKeyword("_ALPHATEST_ON");
+					material.DisableKeyword("_ALPHABLEND_ON");
+					material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
+					material.renderQueue = -1;
+					break;
+				case BlendMode.Cutout:
+					material.SetOverrideTag("RenderType", "TransparentCutout");
+					material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
+					material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
+					material.SetInt("_ZWrite", 1);
+					material.EnableKeyword("_ALPHATEST_ON");
+					material.DisableKeyword("_ALPHABLEND_ON");
+					material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
+					material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
+					break;
+				case BlendMode.Fade:
+					material.SetOverrideTag("RenderType", "Transparent");
+					material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
+					material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
+					material.SetInt("_ZWrite", 0);
+					material.DisableKeyword("_ALPHATEST_ON");
+					material.EnableKeyword("_ALPHABLEND_ON");
+					material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
+					material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
+					break;
+				case BlendMode.Transparent:
+					material.SetOverrideTag("RenderType", "Transparent");
+					material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
+					material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
+					material.SetInt("_ZWrite", 0);
+					material.DisableKeyword("_ALPHATEST_ON");
+					material.DisableKeyword("_ALPHABLEND_ON");
+					material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
+					material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
+					break;
+			}
+		}
+
+		static SmoothnessMapChannel GetSmoothnessMapChannel(Material material)
+		{
+			int ch = (int) material.GetFloat("_SmoothnessTextureChannel");
+			if (ch == (int) SmoothnessMapChannel.AlbedoAlpha)
+				return SmoothnessMapChannel.AlbedoAlpha;
+			else
+				return SmoothnessMapChannel.SpecularMetallicAlpha;
+		}
+
+		static bool ShouldEmissionBeEnabled(Material mat, Color color)
+		{
+			var realtimeEmission = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.RealtimeEmissive) > 0;
+			return color.maxColorComponent > 0.1f / 255.0f || realtimeEmission;
+		}
+
+		static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
+		{
+			// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
+			// (MaterialProperty value might come from renderer material property block)
+			SetKeyword (material, "_NORMALMAP", material.GetTexture ("_BumpMap") || material.GetTexture ("_DetailNormalMap"));
+			if (workflowMode == WorkflowMode.Specular)
+				SetKeyword (material, "_SPECGLOSSMAP", material.GetTexture ("_SpecGlossMap"));
+			else if (workflowMode == WorkflowMode.Metallic)
+				SetKeyword (material, "_METALLICGLOSSMAP", material.GetTexture ("_MetallicGlossMap"));
+			SetKeyword (material, "_PARALLAXMAP", material.GetTexture ("_ParallaxMap"));
+			SetKeyword (material, "_DETAIL_MULX2", material.GetTexture ("_DetailAlbedoMap") || material.GetTexture ("_DetailNormalMap"));
+
+			bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material, material.GetColor("_EmissionColor"));
+			SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
+
+			if (material.HasProperty("_SmoothnessTextureChannel"))
+			{
+				SetKeyword (material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha);
+			}
+
+			// Setup lightmap emissive flags
+			MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
+			if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
+			{
+				flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
+				if (!shouldEmissionBeEnabled)
+					flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
+
+				material.globalIlluminationFlags = flags;
+			}
+		}
+
+		bool HasValidEmissiveKeyword (Material material)
+		{
+			// Material animation might be out of sync with the material keyword.
+			// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
+			// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
+			bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
+			if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue))
+				return false;
+			else
+				return true;
+		}
+
+		static void MaterialChanged(Material material, WorkflowMode workflowMode)
+		{
+			SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
+
+			SetMaterialKeywords(material, workflowMode);
+		}
+
+		static void SetKeyword(Material m, string keyword, bool state)
+		{
+			if (state)
+				m.EnableKeyword (keyword);
+			else
+				m.DisableKeyword (keyword);
+		}
+	}
+} // namespace UnityEditor

+ 3 - 1
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExportationOptions.cs

@@ -28,6 +28,7 @@ namespace Unity3D2Babylon
         public float ShadowMapBias { get; set; }
         public float ShadowBlurScale { get; set; }
         public float ProductionVersion { get; set; }
+        public float DefaultAspectRatio { get; set; }
         public int DefaultUpdateOptions { get; set; }
         public int DefaultPreviewWindow { get; set; }
         public int DefaultLightFilter { get; set; }
@@ -70,10 +71,11 @@ namespace Unity3D2Babylon
             ShadowMapSize = 1024;
             ShadowMapBias = 0.0001f;
             ShadowBlurScale = 0;
+            DefaultAspectRatio = 1f;
             DefaultUpdateOptions = 0;
             DefaultPreviewWindow = 0;
             DefaultLightFilter = 4;
-            DefaultImageFormat = 0;
+            DefaultImageFormat = 1;
             DefaultLightmapMode = 0;
             DefaultLightmapBaking = 0;
             DefaultCoordinatesIndex = 1;

+ 8 - 4
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/ExporterWindow.cs

@@ -88,6 +88,8 @@ namespace Unity3D2Babylon
         [MenuItem("BabylonJS/Update Libraries", false, 2)]
         public static void InitUpdate()
         {
+            Tools.EnableRemoteCertificates();
+            
             string prodVersion = ExporterWindow.exportationOptions.ProductionVersion.ToString();
             if (prodVersion.IndexOf(".", StringComparison.OrdinalIgnoreCase) < 0)
             {
@@ -467,12 +469,14 @@ namespace Unity3D2Babylon
             EditorGUILayout.Space();
             exportationOptions.LightIntensityFactor = EditorGUILayout.Slider(" Light Intensity Factor", exportationOptions.LightIntensityFactor, 0, 10.0f);
             EditorGUILayout.Space();
-            exportationOptions.ReflectionDefaultLevel = EditorGUILayout.Slider(" Default Reflection Level", exportationOptions.ReflectionDefaultLevel, 0, 1.0f);
+            exportationOptions.DefaultAspectRatio = EditorGUILayout.Slider(" Viewport Camera Ratio", exportationOptions.DefaultAspectRatio, 0, 10.0f);
             EditorGUILayout.Space();
-            exportationOptions.DefaultImageFormat = (int)(BabylonImageFormat)EditorGUILayout.EnumPopup(" Prefered Texture Format", (BabylonImageFormat)exportationOptions.DefaultImageFormat, GUILayout.ExpandWidth(true));
+            exportationOptions.ReflectionDefaultLevel = EditorGUILayout.Slider(" Default Reflection Level", exportationOptions.ReflectionDefaultLevel, 0, 1.0f);
             EditorGUILayout.Space();
             exportationOptions.DefaultQualityLevel = (int)EditorGUILayout.Slider(" Texture Image Quality", exportationOptions.DefaultQualityLevel, 0, 100);
             EditorGUILayout.Space();
+            exportationOptions.DefaultImageFormat = (int)(BabylonImageFormat)EditorGUILayout.EnumPopup(" Prefered Texture Format", (BabylonImageFormat)exportationOptions.DefaultImageFormat, GUILayout.ExpandWidth(true));
+            EditorGUILayout.Space();
 
             showCollision = EditorGUILayout.Foldout(showCollision, "Scene Collision Options");
             if (showCollision)
@@ -480,6 +484,8 @@ namespace Unity3D2Babylon
                 EditorGUILayout.Space();
                 exportationOptions.ExportCollisions = EditorGUILayout.Toggle("   Enable Collisions", exportationOptions.ExportCollisions);
                 EditorGUILayout.Space();
+                exportationOptions.WorkerCollisions = EditorGUILayout.Toggle("   Worker Collisions", exportationOptions.WorkerCollisions);
+                EditorGUILayout.Space();
                 EditorGUILayout.BeginHorizontal();
                 GUILayout.Label("   Camera Ellipsoid");
                 exportationOptions.CameraEllipsoid = EditorGUILayout.Vector3Field("", exportationOptions.CameraEllipsoid, GUILayout.ExpandWidth(false));
@@ -492,8 +498,6 @@ namespace Unity3D2Babylon
                 EditorGUILayout.Space();
                 exportationOptions.DefaultColliderDetail = (int)(BabylonColliderDetail)EditorGUILayout.EnumPopup("   Default Collider Detail", (BabylonColliderDetail)exportationOptions.DefaultColliderDetail, GUILayout.ExpandWidth(true));
                 EditorGUILayout.Space();
-                exportationOptions.WorkerCollisions = EditorGUILayout.Toggle("   Enable Worker Collisions", exportationOptions.WorkerCollisions);
-                EditorGUILayout.Space();
             }
 
             showShader = EditorGUILayout.Foldout(showShader, "Shader Program Options");

+ 7 - 5
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Cameras.cs

@@ -28,6 +28,7 @@ namespace Unity3D2Babylon
             metaData.properties.Add("clearFlags", camera.clearFlags.ToString());
             metaData.properties.Add("cullingMask", camera.cullingMask);
             metaData.properties.Add("stereoEnabled", camera.stereoEnabled);
+            metaData.properties.Add("isOrthographic", camera.orthographic);
             metaData.properties.Add("useOcclusionCulling", camera.useOcclusionCulling);
             babylonCamera.tags = componentTags;
 
@@ -37,11 +38,12 @@ namespace Unity3D2Babylon
             babylonCamera.isStereoscopicSideBySide = camera.stereoEnabled;
             if (camera.orthographic)
             {
-                float size = camera.orthographicSize;
-                babylonCamera.orthoTop = size;
-                babylonCamera.orthoBottom = -size;
-                babylonCamera.orthoLeft = -size;
-                babylonCamera.orthoRight = size;
+                float vert = camera.orthographicSize;
+                float horz = vert * exportationOptions.DefaultAspectRatio;
+                babylonCamera.orthoTop = vert;
+                babylonCamera.orthoBottom = -vert;
+                babylonCamera.orthoLeft = -horz;
+                babylonCamera.orthoRight = horz;
                 babylonCamera.mode = 1;
             }
             else

+ 80 - 13
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Materials.cs

@@ -299,15 +299,19 @@ namespace Unity3D2Babylon
 
         private BabylonMaterial DumpMaterial(Material material, int lightmapIndex = -1, Vector4 lightmapScaleOffset = default(Vector4), int lightmapCoordIndex = -1)
         {
-            if (material.shader.name == "Standard")
+            if (material.shader.name == "Standard" || material.shader.name == "BabylonJS/Materials/PBR Material")
             {
                 return DumpPBRMaterial(material, lightmapIndex, lightmapScaleOffset, true, lightmapCoordIndex);
             }
-            else if (material.shader.name == "Standard (Specular setup)")
+            else if (material.shader.name == "Standard (Specular setup)" || material.shader.name == "BabylonJS/Materials/PBR Material (Specular)")
             {
                 return DumpPBRMaterial(material, lightmapIndex, lightmapScaleOffset, false, lightmapCoordIndex);
             }
-            else if (material.shader.name.Substring(0, 10) == "BabylonJS/")
+            else if (material.shader.name.StartsWith("BabylonJS/Materials/", StringComparison.OrdinalIgnoreCase))
+            {
+                return DumpStandardMaterial(material, lightmapIndex, lightmapScaleOffset, lightmapCoordIndex);
+            }
+            else if (material.shader.name.StartsWith("BabylonJS/", StringComparison.OrdinalIgnoreCase))
             {
                 return DumpShaderMaterial(material);
             }
@@ -328,11 +332,6 @@ namespace Unity3D2Babylon
                 };
 
                 ExporterWindow.ReportProgress(1, "Exporting standard material: " + material.name);
-                if (exportationOptions.DefaultLightmapMode == (int)BabylonLightmapMode.FullLightBaking)
-                {
-                    bMat.disableLighting = true;
-                    bMat.useEmissiveAsIllumination = true;
-                }
 
                 // Default diffuse
                 bMat.diffuse[0] = 1.0f;
@@ -379,6 +378,22 @@ namespace Unity3D2Babylon
                         UnityEngine.Debug.LogWarning("Material Emission Is Float Not Color: " + material.name);
                     }
                 }
+
+                if (material.HasProperty("_AlphaMode"))
+                {
+                    bMat.alphaMode = material.GetInt("_AlphaMode");
+                }
+
+                if (material.HasProperty("_DisableLighting"))
+                {
+                    bMat.disableLighting = (material.GetInt("_DisableLighting") != 0);
+                }
+                
+                if (material.HasProperty("_UseEmissiveAsIllumination"))
+                {
+                    bMat.useEmissiveAsIllumination = (material.GetInt("_UseEmissiveAsIllumination") != 0);
+                }
+
                 if (material.mainTexture && !materialNotSupported)
                 {
                     var mainTexture2D = material.mainTexture as Texture2D;
@@ -414,6 +429,13 @@ namespace Unity3D2Babylon
                 bMat.ambientTexture = DumpTextureFromMaterial(material, "_LightMap");
                 bMat.reflectionTexture = DumpTextureFromMaterial(material, "_Cube");
 
+                // Baking override
+                if (exportationOptions.DefaultLightmapMode == (int)BabylonLightmapMode.FullLightBaking)
+                {
+                    bMat.disableLighting = true;
+                    bMat.useEmissiveAsIllumination = true;
+                }
+
                 // If no ambient texture already (ambientTexture manually set for lightmaps on standard material)
                 bool hasLightmap = (exportationOptions.ExportLightmaps && lightmapIndex >= 0 && lightmapIndex != 65535 && LightmapSettings.lightmaps.Length > lightmapIndex);
                 if (hasLightmap && bMat.ambientTexture == null)
@@ -460,11 +482,6 @@ namespace Unity3D2Babylon
 
             ExporterWindow.ReportProgress(1, "Exporting physical material: " + material.name);
             babylonPbrMaterial.environmentIntensity = RenderSettings.ambientIntensity;
-            if (exportationOptions.DefaultLightmapMode == (int)BabylonLightmapMode.FullLightBaking)
-            {
-                babylonPbrMaterial.disableLighting = true;
-                babylonPbrMaterial.useEmissiveAsIllumination = true;
-            }
 
             if (material.mainTexture && material.mainTexture.GetType().FullName == "UnityEngine.ProceduralTexture")
             {
@@ -472,6 +489,36 @@ namespace Unity3D2Babylon
                 Debug.LogWarning("ProceduralTexture: " + material.mainTexture.name + " not supported by Babylon.js");
             }
 
+            if (material.HasProperty("_Roughness"))
+            {
+                babylonPbrMaterial.roughness = material.GetInt("_Roughness");
+            }
+
+            if (material.HasProperty("_UseRoughnessFromMetallicTextureAlpha"))
+            {
+                babylonPbrMaterial.useRoughnessFromMetallicTextureAlpha = (material.GetInt("_UseRoughnessFromMetallicTextureAlpha") != 0);
+            }
+
+            if (material.HasProperty("_UseRoughnessFromMetallicTextureGreen"))
+            {
+                babylonPbrMaterial.useRoughnessFromMetallicTextureGreen = (material.GetInt("_UseRoughnessFromMetallicTextureGreen") != 0);
+            }
+
+            if (material.HasProperty("_AlphaMode"))
+            {
+                babylonPbrMaterial.alphaMode = material.GetInt("_AlphaMode");
+            }
+
+            if (material.HasProperty("_DisableLighting"))
+            {
+                babylonPbrMaterial.disableLighting = (material.GetInt("_DisableLighting") != 0);
+            }
+            
+            if (material.HasProperty("_UseEmissiveAsIllumination"))
+            {
+                babylonPbrMaterial.useEmissiveAsIllumination = (material.GetInt("_UseEmissiveAsIllumination") != 0);
+            }
+
             // Albedo
             if (material.HasProperty("_Color"))
             {
@@ -517,6 +564,13 @@ namespace Unity3D2Babylon
             // Reflection
             babylonPbrMaterial.reflectionTexture = DumpReflectionTexture();
 
+            // Baking Override
+            if (exportationOptions.DefaultLightmapMode == (int)BabylonLightmapMode.FullLightBaking)
+            {
+                babylonPbrMaterial.disableLighting = true;
+                babylonPbrMaterial.useEmissiveAsIllumination = true;
+            }
+
             // Lightmapping
             bool hasLightmap = (exportationOptions.ExportLightmaps && lightmapIndex >= 0 && lightmapIndex != 65535 && LightmapSettings.lightmaps.Length > lightmapIndex);
             if (hasLightmap && babylonPbrMaterial.ambientTexture == null)
@@ -805,7 +859,20 @@ namespace Unity3D2Babylon
                 }
             }
 
+            if (material.HasProperty("_AlphaMode")) {
+                babylonShaderMaterial.alphaMode = material.GetInt("_AlphaMode");
+            }
+            bool needsAlphaBlending = false;
+            if (material.HasProperty("_NeedsAlphaBlending")) {
+                needsAlphaBlending = (material.GetInt("_NeedsAlphaBlending") != 0);
+            }
+            bool needsAlphaTesting = false;
+            if (material.HasProperty("_NeedsAlphaTesting")) {
+                needsAlphaTesting = (material.GetInt("_NeedsAlphaTesting") != 0);
+            }
             babylonShaderMaterial.options = new BabylonShaderOptions();
+            babylonShaderMaterial.options.needAlphaBlending = needsAlphaBlending;
+            babylonShaderMaterial.options.needAlphaTesting = needsAlphaTesting;
             babylonShaderMaterial.options.attributes = attributeList.ToArray();
             babylonShaderMaterial.options.uniforms = uniformList.ToArray();
             babylonShaderMaterial.options.samplers = samplerList.ToArray();

+ 11 - 3
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.Meshes.cs

@@ -294,13 +294,21 @@ namespace Unity3D2Babylon
                     if (mesh.subMeshCount > 1)
                     {
                         BabylonMultiMaterial bMultiMat;
-                        if (!multiMatDictionary.ContainsKey(renderer.sharedMaterial.name))
+
+                        string multiMatName = "";
+                        for (int i = 0; i < renderer.sharedMaterials.Length; i++)
+                        {
+                            multiMatName += renderer.sharedMaterials[i].name;
+                        }
+                    
+
+                        if (!multiMatDictionary.ContainsKey(multiMatName))
                         {
                             bMultiMat = new BabylonMultiMaterial
                             {
                                 materials = new string[mesh.subMeshCount],
                                 id = Guid.NewGuid().ToString(),
-                                name = renderer.sharedMaterial.name
+                                name = multiMatName
                             };
 
                             for (int i = 0; i < renderer.sharedMaterials.Length; i++)
@@ -319,7 +327,7 @@ namespace Unity3D2Babylon
                         }
                         else
                         {
-                            bMultiMat = multiMatDictionary[renderer.sharedMaterial.name];
+                            bMultiMat = multiMatDictionary[multiMatName];
                         }
 
                         babylonMesh.materialId = bMultiMat.id;

+ 8 - 1
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/SceneBuilder.cs

@@ -395,7 +395,14 @@ namespace Unity3D2Babylon
                                 collisionMesh = new BabylonMesh();
                                 collisionMesh.tags = "[MESHCOLLIDER]";
                                 // Generate Mesh Collider Geometry
-                                Tools.GenerateBabylonMeshData(meshCollider.sharedMesh, collisionMesh);
+                                if(!meshCollider.sharedMesh)
+                                {
+                                    UnityEngine.Debug.LogWarning(meshCollider.gameObject+" has a Mesh Collider component without a mesh");
+                                }
+                                else
+                                {
+                                    Tools.GenerateBabylonMeshData(meshCollider.sharedMesh, collisionMesh);
+                                }
                                 collisionMesh.position = Vector3.zero.ToFloat();
                                 collisionMesh.rotation = Vector3.zero.ToFloat();
                                 float factorX = 1f, factorY = 1f, factorZ = 1f;

+ 6 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Source/Tools.cs

@@ -20,6 +20,7 @@ namespace Unity3D2Babylon
     public static class Tools
     {
         public static BindingFlags FullBinding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.GetProperty | BindingFlags.SetProperty;
+        
         public static float[] ToFloat(this Color color)
         {
             var result = new float[4];
@@ -233,6 +234,11 @@ namespace Unity3D2Babylon
             return field.GetValue(instance);
         }
 
+        public static void EnableRemoteCertificates()
+        {
+            System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });
+        }
+
         public static bool DownloadFile(string url, string dest)
         {
             bool result = false;

+ 3 - 0
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Templates/Config/index.html

@@ -6,6 +6,7 @@
         html, body {
             width: 100%;
             height: 100%;
+            min-height:100%;            
             padding: 0;
             margin: 0;
             overflow: hidden;
@@ -61,6 +62,7 @@
         #cvs {
             width: 100%;
             height: 100%;
+            padding: 0;
             opacity: 0;
             z-index: 0;
             outline: none;
@@ -72,6 +74,7 @@
         #gui {
             width: 100%;
             height: 100%;
+            min-height:100%;            
             z-index: 1;
             outline: none;
             background-color: transparent;

+ 74 - 67
Exporters/Unity 5/EditorToolkit/Assets/Babylon/Templates/Shaders/amiga.template

@@ -1,92 +1,99 @@
 Shader "BabylonJS/NewShaderProgram" {
 	Properties {
 		_Color ("Color", Color) = (1,1,1,1)
+		_Brightness ("Intensity", Range(1.0, 10.0)) = 1.0
 		[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
-		_Glossiness ("Smoothness", Range(0,1)) = 0.5
-		_Metallic ("Metallic", Range(0,1)) = 0.0
 		_ScaleX ("Scale Factor X", Range (0.0, 10.0)) = 1.0
 		_ScaleY ("Scale Factor Y", Range (0.0, 10.0)) = 1.0
+		_Metallic ("Metallic", Range(0,1)) = 0.0
+		_Glossiness ("Smoothness", Range(0,1)) = 0.5
+		[ToggleOff] _NeedsAlphaTesting ("Needs Alpha Testing", Int) = 0
+		[ToggleOff] _NeedsAlphaBlending ("Needs Alpha Blending", Int) = 0
+		[Enum(Disable,0,Additive,1,Combine,2,Subtract,3,Multiply,4,Maximized,5,OneOne,6)] _AlphaMode ("Alpha Blending Mode", int) = 2
 	}
 	SubShader {
 		Tags { "RenderType"="Opaque" }
-		LOD 200
-		CGPROGRAM
+		Pass {
+			CGPROGRAM
 
-		//////////////////////////////////////////////////////////
-		// BABYLON WEBGL RUNTIME SHADER PROGRAM SECTIONS (GLSL) //
-		//////////////////////////////////////////////////////////
+			//////////////////////////////////////////////////////////
+			// BABYLON WEBGL RUNTIME SHADER PROGRAM SECTIONS (GLSL) //
+			//////////////////////////////////////////////////////////
 
-		#ifdef BABYLON
-		attributes: ["position", "normal", "uv"]
-		uniforms: ["worldViewProjection, _Color, _Glossiness, _Metallic, _ScaleX, _ScaleY"]
-		samplers: []
-		defines: []
-		#endif //BABYLON-END
+			#ifdef BABYLON
+			attributes: ["position", "normal", "uv"]
+			uniforms: ["worldViewProjection, _Color, _Brightness, _Glossiness, _Metallic, _ScaleX, _ScaleY"]
+			samplers: []
+			defines: []
+			#endif //BABYLON-END
 
 
-		#ifdef VERTEX
-		attribute vec3 position;
-		attribute vec3 normal;
-		attribute vec2 uv;
-		uniform mat4 worldViewProjection;
-		precision highp float;
+			#ifdef VERTEX
+			attribute vec3 position;
+			attribute vec3 normal;
+			attribute vec2 uv;
+			uniform mat4 worldViewProjection;
+			precision highp float;
 
-		varying vec2 vUV;
-		
-		void main(void)
-		{
-			gl_Position = worldViewProjection * vec4(position, 1.0);
-			vUV = uv;
-		}
-		#endif //VERTEX-END
+			varying vec2 vUV;
+			
+			void main(void)
+			{
+				gl_Position = worldViewProjection * vec4(position, 1.0);
+				vUV = uv;
+			}
+			#endif //VERTEX-END
 
 
-		#ifdef FRAGMENT
-		precision highp float;
+			#ifdef FRAGMENT
+			precision highp float;
 
-		varying vec2 vUV;
-		uniform vec4 _Color;
-		uniform float _Glossiness;
-		uniform float _Metallic;
-		uniform float _ScaleX;
-		uniform float _ScaleY;
-		uniform sampler2D _MainTex;
+			varying vec2 vUV;
+			uniform vec4 _Color;
+			uniform float _Brightness;
+			uniform float _Glossiness;
+			uniform float _Metallic;
+			uniform float _ScaleX;
+			uniform float _ScaleY;
+			uniform sampler2D _MainTex;
 
-		void main(void)
-		{
-			gl_FragColor = texture2D(_MainTex, vec2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color;
-		}
-		#endif //FRAGMENT-END 
+			void main(void)
+			{
+				gl_FragColor = texture2D(_MainTex, vec2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color * _Brightness;
+			}
+			#endif //FRAGMENT-END 
 
 
-		////////////////////////////////////////////////////////
-		// DEFAULT UNITY EDITOR SHADER PROGRAM SECTION (HLSL) //
-		////////////////////////////////////////////////////////
+			////////////////////////////////////////////////////////
+			// DEFAULT UNITY EDITOR SHADER PROGRAM SECTION (HLSL) //
+			////////////////////////////////////////////////////////
 
-		#pragma exclude_renderers d3d11 xbox360 gles
-		#pragma surface surf Standard fullforwardshadows
-		#pragma target 3.0
-		sampler2D _MainTex;
-		struct Input {
-			float2 uv_MainTex;
-		};
-		half _Glossiness;
-		half _Metallic;
-		half _ScaleX;
-		half _ScaleY;
-		fixed4 _Color;
-		void surf (Input IN, inout SurfaceOutputStandard o) {
-			// Albedo comes from a texture tinted by color
-			float2 vUV = IN.uv_MainTex;
-			fixed4 c = tex2D (_MainTex, float2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color;
-			o.Albedo = c.rgb;
-			// Metallic and smoothness come from slider variables
-			o.Metallic = _Metallic;
-			o.Smoothness = _Glossiness;
-			o.Alpha = c.a;
-		}
+			#pragma exclude_renderers d3d11 xbox360 gles
+			#pragma surface surf Standard fullforwardshadows
+			#pragma target 3.0
+			sampler2D _MainTex;
+			struct Input {
+				float2 uv_MainTex;
+			};
+			half _Brightness;
+			half _Glossiness;
+			half _Metallic;
+			half _ScaleX;
+			half _ScaleY;
+			fixed4 _Color;
+			void surf (Input IN, inout SurfaceOutputStandard o) {
+				// Albedo comes from a texture tinted by color
+				float2 vUV = IN.uv_MainTex;
+				fixed4 c = tex2D (_MainTex, float2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color * _Brightness;
+				o.Albedo = c.rgb;
+				// Metallic and smoothness come from slider variables
+				o.Metallic = _Metallic;
+				o.Smoothness = _Glossiness;
+				o.Alpha = c.a;
+			}
 
-		ENDCG
+			ENDCG
+		}
 	}
 	FallBack "Diffuse"
 }

BIN=BIN
Exporters/Unity 5/EditorToolkit/Redist/Asset Store-5.x/BabylonJS/BabylonJS Editor Toolkit.unitypackage


+ 3 - 1
Playground/zipContent/index.html

@@ -26,7 +26,9 @@
         </style>
     </head>
 <body>
-    <canvas id="renderCanvas"></canvas>
+    <div id="canvasZone">
+        <canvas id="renderCanvas"></canvas>
+    </div>
     <script>
         var canvas = document.getElementById("renderCanvas");
         var engine = new BABYLON.Engine(canvas, true);

+ 1 - 0
Tools/Gulp/config.json

@@ -206,6 +206,7 @@
       "../../src/PostProcess/babylon.lensRenderingPipeline.js",
       "../../src/PostProcess/babylon.colorCorrectionPostProcess.js",
       "../../src/Cameras/babylon.stereoscopicCameras.js",
+      "../../src/Cameras/Holographic/babylon.holographicCamera.js",
       "../../src/PostProcess/babylon.hdrRenderingPipeline.js",
       "../../src/Rendering/babylon.edgesRenderer.js",
       "../../src/PostProcess/babylon.tonemapPostProcess.js",

+ 14 - 4
canvas2D/src/Engine/babylon.renderablePrim2d.ts

@@ -920,7 +920,10 @@
         }
 
         private static _uV = new Vector2(1, 1);
-
+        private static _s = Vector3.Zero();
+        private static _r = Quaternion.Identity();
+        private static _t = Vector3.Zero();
+        private static _uV3 = new Vector3(1, 1, 1);
         /**
          * Update the instanceDataBase level properties of a part
          * @param part the part to update
@@ -928,7 +931,14 @@
          */
         protected updateInstanceDataPart(part: InstanceDataBase, positionOffset: Vector2 = null) {
             let t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform);    // Compute the transformation into the renderGroup's space
-            let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
+            let rgScale = this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
+
+            if (!this.applyActualScaleOnTransform() || rgScale.x!==1 || rgScale.y!==1) {
+                t.decompose(RenderablePrim2D._s, RenderablePrim2D._r, RenderablePrim2D._t);
+                t = Matrix.Compose((!this.applyActualScaleOnTransform() ? RenderablePrim2D._uV3.divide(new Vector3(rgScale.x, rgScale.y, 1)) : RenderablePrim2D._s), RenderablePrim2D._r, RenderablePrim2D._t);
+            }
+
+            //let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
             let size = (<Size>this.renderGroup.viewportSize);
             let zBias = this.actualZOffset;
 
@@ -949,8 +959,8 @@
             let w = size.width;
             let h = size.height;
             let invZBias = 1 / zBias;
-            let tx = new Vector4(t.m[0] * rgScale.x * 2 / w, t.m[4] * 2 / w, 0/*t.m[8]*/, ((t.m[12] + offX) * rgScale.x * 2 / w) - 1);
-            let ty = new Vector4(t.m[1] * 2 / h, t.m[5] * rgScale.y * 2 / h, 0/*t.m[9]*/, ((t.m[13] + offY) * rgScale.y * 2 / h) - 1);
+            let tx = new Vector4(t.m[0] * 2 / w, t.m[4] * 2 / w, 0/*t.m[8]*/, ((t.m[12] + offX) * 2 / w) - 1);
+            let ty = new Vector4(t.m[1] * 2 / h, t.m[5] * 2 / h, 0/*t.m[9]*/, ((t.m[13] + offY) * 2 / h) - 1);
 
             part.transformX = tx;
             part.transformY = ty;

+ 4 - 0
dist/preview release/canvas2D/babylon.canvas2d.d.ts

@@ -2212,6 +2212,10 @@ declare module BABYLON {
         protected applyActualScaleOnTransform(): boolean;
         protected refreshInstanceDataPart(part: InstanceDataBase): boolean;
         private static _uV;
+        private static _s;
+        private static _r;
+        private static _t;
+        private static _uV3;
         /**
          * Update the instanceDataBase level properties of a part
          * @param part the part to update

+ 12 - 3
dist/preview release/canvas2D/babylon.canvas2d.js

@@ -7336,7 +7336,12 @@ var BABYLON;
         RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
             if (positionOffset === void 0) { positionOffset = null; }
             var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
-            var rgScale = (this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D_1._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
+            var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D_1._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
+            if (!this.applyActualScaleOnTransform() || rgScale.x !== 1 || rgScale.y !== 1) {
+                t.decompose(RenderablePrim2D_1._s, RenderablePrim2D_1._r, RenderablePrim2D_1._t);
+                t = BABYLON.Matrix.Compose((!this.applyActualScaleOnTransform() ? RenderablePrim2D_1._uV3.divide(new BABYLON.Vector3(rgScale.x, rgScale.y, 1)) : RenderablePrim2D_1._s), RenderablePrim2D_1._r, RenderablePrim2D_1._t);
+            }
+            //let rgScale = (this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) || !this.applyActualScaleOnTransform()) ? RenderablePrim2D._uV : this.renderGroup.actualScale;         // We still need to apply the scale of the renderGroup to our rendering, so get it.
             var size = this.renderGroup.viewportSize;
             var zBias = this.actualZOffset;
             var offX = 0;
@@ -7355,8 +7360,8 @@ var BABYLON;
             var w = size.width;
             var h = size.height;
             var invZBias = 1 / zBias;
-            var tx = new BABYLON.Vector4(t.m[0] * rgScale.x * 2 / w, t.m[4] * 2 / w, 0 /*t.m[8]*/, ((t.m[12] + offX) * rgScale.x * 2 / w) - 1);
-            var ty = new BABYLON.Vector4(t.m[1] * 2 / h, t.m[5] * rgScale.y * 2 / h, 0 /*t.m[9]*/, ((t.m[13] + offY) * rgScale.y * 2 / h) - 1);
+            var tx = new BABYLON.Vector4(t.m[0] * 2 / w, t.m[4] * 2 / w, 0 /*t.m[8]*/, ((t.m[12] + offX) * 2 / w) - 1);
+            var ty = new BABYLON.Vector4(t.m[1] * 2 / h, t.m[5] * 2 / h, 0 /*t.m[9]*/, ((t.m[13] + offY) * 2 / h) - 1);
             part.transformX = tx;
             part.transformY = ty;
             part.opacity = this.actualOpacity;
@@ -7378,6 +7383,10 @@ var BABYLON;
     }(BABYLON.Prim2DBase));
     RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT = BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 5;
     RenderablePrim2D._uV = new BABYLON.Vector2(1, 1);
+    RenderablePrim2D._s = BABYLON.Vector3.Zero();
+    RenderablePrim2D._r = BABYLON.Quaternion.Identity();
+    RenderablePrim2D._t = BABYLON.Vector3.Zero();
+    RenderablePrim2D._uV3 = new BABYLON.Vector3(1, 1, 1);
     __decorate([
         BABYLON.dynamicLevelProperty(BABYLON.Prim2DBase.PRIM2DBASE_PROPCOUNT + 0, function (pi) { return RenderablePrim2D_1.isAlphaTestProperty = pi; })
     ], RenderablePrim2D.prototype, "isAlphaTest", null);

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 6 - 6
dist/preview release/canvas2D/babylon.canvas2d.min.js


+ 1 - 0
dist/preview release/what's new.md

@@ -4,6 +4,7 @@
  - New Unity 5 Editor Toolkit. Complete pipeline integration [Doc](TODO) - ([MackeyK24](https://github.com/MackeyK24))
  - New DebugLayer. [Doc](TODO) - ([temechon](https://github.com/temechon))
  - New `VideoTexture.CreateFromWebCam` to generate video texture using WebRTC. [Demo](https://www.babylonjs-playground.com#1R77YT#2) - (Sebastien Vandenberghe)(https://github.com/sebavanmicrosoft) / ([deltakosh](https://github.com/deltakosh))
+ - New `HolographicCamera` to support rendering on Windows Holographic. - ([sebavan](https://github.com/sebavan))
 
 ### Updates
  - `Effect.getVertexShaderSource()` and `Effect.getFragmentShaderSource()` now returns the effective shader code (including evaluation of #define) ([deltakosh](https://github.com/deltakosh))

+ 111 - 0
src/Cameras/Holographic/babylon.holographicCamera.ts

@@ -0,0 +1,111 @@
+interface Window { 
+    holographicViewMatrix: boolean;
+    getViewMatrix(): Float32Array;
+    getCameraPositionVector(): Float32Array;
+} 
+
+module BABYLON {
+    export class HolographicCamera extends Camera {
+        
+        private _identityProjection: Matrix;
+
+        private _scriptProjection: Matrix;
+        private _scriptViewProjection: Matrix;
+
+        private _holographicViewMatrix: Matrix;
+
+        private _onBeforeRenderObserver: Observer<Scene>;
+        private _onBeforeCameraRenderObserver: Observer<Camera>;
+
+        constructor(name: string, scene: Scene) {            
+            super(name, BABYLON.Vector3.Zero(), scene);
+
+            scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);
+            
+            this._holographicViewMatrix = new Matrix();            
+            this._identityProjection = BABYLON.Matrix.Identity();
+            this._scriptProjection = BABYLON.Matrix.Transpose(BABYLON.Matrix.PerspectiveFovLH(30, window.innerWidth / window.innerHeight, 1, 20));
+            this._scriptViewProjection = BABYLON.Matrix.Identity();
+
+            this.fov = 30;
+            this.minZ = 1.0;
+            this.maxZ = 20;
+            this.mode = BABYLON.Camera.PERSPECTIVE_CAMERA;
+            this.isIntermediate = false;
+            this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
+            this.layerMask = 0x0FFFFFFF;
+            this.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED;
+            this.cameraRigMode = BABYLON.Camera.RIG_MODE_NONE;
+
+            var self = this;
+            this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(function (scene) {
+                self._holographicViewMatrix.m = window.getViewMatrix();
+                self.setViewMatrix(self._holographicViewMatrix);
+
+                var position = window.getCameraPositionVector();
+                self.position.copyFromFloats(-position[0], position[1], -position[2]);
+            })
+            this._onBeforeCameraRenderObserver = scene.onBeforeCameraRenderObservable.add(function() {
+                if (scene.frustumPlanes) {
+                    self.getFrustumPlanesToRef(scene.frustumPlanes);
+                }
+            })
+
+            scene.addCamera(this);
+            if (!scene.activeCamera) {
+                scene.activeCamera = this;
+            }
+        }
+
+        public getTypeName(): string {
+            return "HolographicCamera";
+        };        
+
+
+        public getProjectionMatrix(): Matrix {
+            return this._identityProjection;
+        };
+        
+        public getViewMatrix(): Matrix {
+            return this._holographicViewMatrix;
+        };
+
+        public setViewMatrix(view: Matrix) : void {
+            this._holographicViewMatrix = view;
+
+            view.m[0] = -view.m[0];
+            view.m[1] = -view.m[1];
+            view.m[2] = -view.m[2];
+            view.m[3] = -view.m[3];
+
+            view.m[8] = -view.m[8];
+            view.m[9] = -view.m[9];
+            view.m[10] = -view.m[10];
+            view.m[11] = -view.m[11];
+        };
+        
+        public _initCache(): void { };
+        public _updateCache(): void { };
+        public _updateFromScene(): void { };
+
+        // Synchronized
+        public _isSynchronizedViewMatrix() : boolean {
+            return true;
+        };
+        public _isSynchronizedProjectionMatrix() : boolean {
+            return true;
+        };
+
+        private getFrustumPlanesToRef(result: Plane[]): Plane[] {
+            this._holographicViewMatrix.multiplyToRef(this._scriptProjection, this._scriptViewProjection);
+            BABYLON.Frustum.GetPlanesToRef(this._scriptViewProjection, result);
+            return result;
+        };
+
+        public dispose(): void {
+            this.getScene().onBeforeRenderObservable.remove(this._onBeforeRenderObserver);
+            this.getScene().onBeforeCameraRenderObservable.remove(this._onBeforeCameraRenderObserver);
+            super.dispose();
+        }
+    }
+}

+ 13 - 3
src/babylon.engine.ts

@@ -3132,11 +3132,21 @@
         }
 
         private _canRenderToFloatTexture(): boolean {
-            return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
+            try {
+                return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_FLOAT, 'OES_texture_float');
+            }
+            catch (e) {
+                return false;
+            }
         }
 
-        private _canRenderToHalfFloatTexture(): boolean {
-            return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
+        private _canRenderToHalfFloatTexture(): boolean {            
+            try {
+                return this._canRenderToTextureOfType(BABYLON.Engine.TEXTURETYPE_HALF_FLOAT, 'OES_texture_half_float');
+            }
+            catch (e) {
+                return false;
+            }
         }
 
         // Thank you : http://stackoverflow.com/questions/28827511/webgl-ios-render-to-floating-point-texture

+ 4 - 1
src/babylon.scene.ts

@@ -543,7 +543,11 @@
 
         private _viewMatrix: Matrix;
         private _projectionMatrix: Matrix;
+        
         private _frustumPlanes: Plane[];
+        public get frustumPlanes(): Plane[] {
+            return this._frustumPlanes;
+        }
 
         private _selectionOctree: Octree<AbstractMesh>;
 
@@ -561,7 +565,6 @@
         private _externalData: StringDictionary<Object>;
         private _uid: string;
 
-
         /**
          * @constructor
          * @param {BABYLON.Engine} engine - the engine to be used to render this scene.