Bläddra i källkod

Gizmo rendering now prepopulates all uniform buffers before rendering

BearishSun 9 år sedan
förälder
incheckning
6711f9de01

+ 17 - 6
Data/Raw/Editor/Includes/LineGizmo.bslinc

@@ -1,6 +1,12 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
+	mat4x4		gMatViewProj;
+	float4		gViewDir;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique : base("LineGizmo") =
 Technique : base("LineGizmo") =
@@ -11,7 +17,11 @@ Technique : base("LineGizmo") =
 	{
 	{
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -19,7 +29,7 @@ Technique : base("LineGizmo") =
 				out float4 oPosition : SV_Position,
 				out float4 oPosition : SV_Position,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oColor = color;
 				oColor = color;
 			}
 			}
 		};
 		};
@@ -52,14 +62,15 @@ Technique : base("LineGizmo") =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
 
 
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}
 			}
 		};
 		};

+ 42 - 34
Data/Raw/Editor/Includes/PickingAlphaCull.bslinc

@@ -1,12 +1,16 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matWorldViewProj;
+	mat4x4		gMatWorldViewProj;
+	float4		gColorIndex;
+	float		gAlphaCutoff;
 	
 	
-	float		alphaCutoff;
-	float4		colorIndex;
-	
-	Sampler2D 	mainTexSamp : alias("mainTexture");
-	Texture2D 	mainTexture;	
+	Sampler2D 	gMainTexSamp : alias("gMainTexture");
+	Texture2D 	gMainTexture;	
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique : base("PickingAlphaCull") =
 Technique : base("PickingAlphaCull") =
@@ -17,10 +21,18 @@ Technique : base("PickingAlphaCull") =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
 
 
+		Common =
+		{
+			cbuffer Uniforms
+			{
+				float4x4 	gMatWorldViewProj;
+				float4		gColorIndex;
+				float		gAlphaCutoff;
+			}
+		};			
+		
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matWorldViewProj;
-
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
 				in float3 inNorm : NORMAL,
 				in float3 inNorm : NORMAL,
@@ -29,7 +41,7 @@ Technique : base("PickingAlphaCull") =
 				out float4 oNorm : NORMAL,
 				out float4 oNorm : NORMAL,
 				out float2 oUv : TEXCOORD0)
 				out float2 oUv : TEXCOORD0)
 			{
 			{
-				oPosition = mul(matWorldViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatWorldViewProj, float4(inPos.xyz, 1));
 				oNorm = float4(inNorm, 0);
 				oNorm = float4(inNorm, 0);
 				oUv = uv;
 				oUv = uv;
 			}
 			}
@@ -37,11 +49,8 @@ Technique : base("PickingAlphaCull") =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			SamplerState mainTexSamp : register(s0);
-			Texture2D mainTexture : register(t0);
-
-			float4 colorIndex;
-			float alphaCutoff;
+			SamplerState gMainTexSamp : register(s0);
+			Texture2D gMainTexture : register(t0);
 
 
 			float4 main(
 			float4 main(
 				in float4 inPos : SV_Position,
 				in float4 inPos : SV_Position,
@@ -49,12 +58,12 @@ Technique : base("PickingAlphaCull") =
 				in float2 uv : TEXCOORD0,
 				in float2 uv : TEXCOORD0,
 				out float4 oNorm : SV_Target1) : SV_Target0
 				out float4 oNorm : SV_Target1) : SV_Target0
 			{
 			{
-				float4 color = mainTexture.Sample(mainTexSamp, uv);
+				float4 color = gMainTexture.Sample(gMainTexSamp, uv);
 				oNorm = (inNorm + float4(1,1,1,0)) / 2;
 				oNorm = (inNorm + float4(1,1,1,0)) / 2;
-				if(color.a < alphaCutoff)
+				if(color.a < gAlphaCutoff)
 					discard;
 					discard;
 				
 				
-				return colorIndex;
+				return gColorIndex;
 			}
 			}
 		};
 		};
 	};
 	};
@@ -68,6 +77,16 @@ Technique : base("PickingAlphaCull") =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
 
 
+		Common =
+		{
+			layout(binding = 0, std140) uniform Uniforms
+			{
+				mat4 	gMatWorldViewProj;
+				vec4	gColorIndex;
+				float	gAlphaCutoff;
+			};
+		};		
+		
 		Vertex =
 		Vertex =
 		{		
 		{		
 			layout(location = 0) in vec3 bs_position;
 			layout(location = 0) in vec3 bs_position;
@@ -81,15 +100,10 @@ Technique : base("PickingAlphaCull") =
 			{
 			{
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
-			
-			layout(binding = 0) uniform VertUBO
-			{
-				mat4 matWorldViewProj;
-			};			
-			
+						
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matWorldViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatWorldViewProj * vec4(bs_position.xyz, 1);
 				texcoord0 = bs_texcoord0;
 				texcoord0 = bs_texcoord0;
 				normal = vec4(bs_normal, 0);
 				normal = vec4(bs_normal, 0);
 			}
 			}
@@ -102,21 +116,15 @@ Technique : base("PickingAlphaCull") =
 		
 		
 			layout(location = 0) out vec4[2] outColor;
 			layout(location = 0) out vec4[2] outColor;
 
 
-			layout(binding = 1) uniform FragUBO
-			{
-				vec4 colorIndex;
-				float alphaCutoff;
-			};	
-			
-			layout(binding = 2) uniform sampler2D mainTexture;
+			layout(binding = 2) uniform sampler2D gMainTexture;
 
 
 			void main()
 			void main()
 			{
 			{
-				vec4 color = texture2D(mainTexture, texcoord0);
-				if(color.a < alphaCutoff)
+				vec4 color = texture2D(gMainTexture, texcoord0);
+				if(color.a < gAlphaCutoff)
 					discard;
 					discard;
 					
 					
-				outColor[0] = colorIndex;
+				outColor[0] = gColorIndex;
 				outColor[1] = (normal + vec4(1,1,1,0)) / 2;	
 				outColor[1] = (normal + vec4(1,1,1,0)) / 2;	
 			}
 			}
 		};
 		};

+ 32 - 21
Data/Raw/Editor/Includes/PickingCull.bslinc

@@ -1,8 +1,13 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matWorldViewProj;
-	
-	float4		colorIndex;	
+	mat4x4		gMatWorldViewProj;
+	float4		gColorIndex;
+	float		gAlphaCutoff;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique : base("PickingCull") =
 Technique : base("PickingCull") =
@@ -12,26 +17,32 @@ Technique : base("PickingCull") =
 	Pass =
 	Pass =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
+		
+		Common =
+		{
+			cbuffer Uniforms
+			{
+				float4x4 	gMatWorldViewProj;
+				float4		gColorIndex;
+				float		gAlphaCutoff;
+			}
+		};		
 
 
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matWorldViewProj;
-
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
 				in float3 inNorm : NORMAL,
 				in float3 inNorm : NORMAL,
 				out float4 oPosition : SV_Position,
 				out float4 oPosition : SV_Position,
 				out float4 oNorm : NORMAL)
 				out float4 oNorm : NORMAL)
 			{
 			{
-				oPosition = mul(matWorldViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatWorldViewProj, float4(inPos.xyz, 1));
 				oNorm = float4(inNorm, 0);
 				oNorm = float4(inNorm, 0);
 			}
 			}
 		};
 		};
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			float4 colorIndex;
-
 			float4 main(
 			float4 main(
 				in float4 inPos : SV_Position,
 				in float4 inPos : SV_Position,
 				in float4 inNorm : NORMAL,	
 				in float4 inNorm : NORMAL,	
@@ -39,7 +50,7 @@ Technique : base("PickingCull") =
 			) : SV_Target0
 			) : SV_Target0
 			{
 			{
 				oNorm = (inNorm + float4(1,1,1,0)) / 2;
 				oNorm = (inNorm + float4(1,1,1,0)) / 2;
-				return colorIndex;
+				return gColorIndex;
 			}
 			}
 		};
 		};
 	};
 	};
@@ -52,6 +63,16 @@ Technique : base("PickingCull") =
 	Pass =
 	Pass =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
+		
+		Common =
+		{
+			layout(binding = 0, std140) uniform Uniforms
+			{
+				mat4 	gMatWorldViewProj;
+				vec4	gColorIndex;
+				float	gAlphaCutoff;
+			};
+		};
 
 
 		Vertex =
 		Vertex =
 		{
 		{
@@ -65,15 +86,10 @@ Technique : base("PickingCull") =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
 			
 			
-			layout(binding = 0) uniform VertUBO
-			{
-				mat4 matWorldViewProj;
-			};	
-			
 			void main()
 			void main()
 			{
 			{
 				normal = vec4(bs_normal,0);
 				normal = vec4(bs_normal,0);
-				gl_Position = matWorldViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatWorldViewProj * vec4(bs_position.xyz, 1);
 			}
 			}
 		};
 		};
 		
 		
@@ -81,15 +97,10 @@ Technique : base("PickingCull") =
 		{
 		{
 			layout(location = 0) in vec4 normal;
 			layout(location = 0) in vec4 normal;
 			layout(location = 0) out vec4[2] outColor;
 			layout(location = 0) out vec4[2] outColor;
-			
-			layout(binding = 1) uniform FragUBO
-			{
-				vec4 colorIndex;
-			};	
 
 
 			void main()
 			void main()
 			{
 			{
-				outColor[0] = colorIndex;
+				outColor[0] = gColorIndex;
 				outColor[1] = (normal + vec4(1,1,1,0)) / 2;
 				outColor[1] = (normal + vec4(1,1,1,0)) / 2;
 			}
 			}
 		};
 		};

+ 29 - 20
Data/Raw/Editor/Includes/SolidGizmo.bslinc

@@ -1,7 +1,12 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
-	float4		viewDir;
+	mat4x4		gMatViewProj;
+	float4		gViewDir;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique : base("SolidGizmo") =
 Technique : base("SolidGizmo") =
@@ -10,10 +15,17 @@ Technique : base("SolidGizmo") =
 	
 	
 	Pass =
 	Pass =
 	{
 	{
+		Common =
+		{
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
+		};
+	
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
-
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
 				in float3 inNormal : NORMAL,
 				in float3 inNormal : NORMAL,
@@ -22,7 +34,7 @@ Technique : base("SolidGizmo") =
 				out float3 oNormal : NORMAL,
 				out float3 oNormal : NORMAL,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oNormal = inNormal;
 				oNormal = inNormal;
 				oColor = color;
 				oColor = color;
 			}
 			}
@@ -30,11 +42,9 @@ Technique : base("SolidGizmo") =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			float4 viewDir;
-		
 			float4 main(in float4 inPos : SV_Position, in float3 normal : NORMAL, in float4 color : COLOR0) : SV_Target
 			float4 main(in float4 inPos : SV_Position, in float3 normal : NORMAL, in float4 color : COLOR0) : SV_Target
 			{
 			{
-				float4 outColor = color * dot(normalize(normal), -viewDir);
+				float4 outColor = color * dot(normalize(normal), -gViewDir);
 				outColor.a = color.a;
 				outColor.a = color.a;
 				
 				
 				return outColor;
 				return outColor;
@@ -49,6 +59,15 @@ Technique : base("SolidGizmo") =
 	
 	
 	Pass =
 	Pass =
 	{
 	{
+		Common =
+		{
+			layout(binding = 0, std140) uniform Uniforms
+			{
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
+			};
+		}
+	
 		Vertex =
 		Vertex =
 		{
 		{
 			layout(location = 0) in vec3 bs_position;
 			layout(location = 0) in vec3 bs_position;
@@ -63,14 +82,9 @@ Technique : base("SolidGizmo") =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};		
 			};		
 		
 		
-			layout(binding = 0) uniform VertUBO
-			{
-				mat4 matViewProj;
-			};
-			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				normal = bs_normal;
 				normal = bs_normal;
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}
 			}
@@ -83,14 +97,9 @@ Technique : base("SolidGizmo") =
 			
 			
 			layout(location = 0) out vec4 fragColor;
 			layout(location = 0) out vec4 fragColor;
 
 
-			layout(binding = 1) uniform FragUBO
-			{
-				vec4 viewDir;
-			};
-			
 			void main()
 			void main()
 			{
 			{
-				fragColor = color0 * dot(normalize(normal), -viewDir.xyz);
+				fragColor = color0 * dot(normalize(normal), -gViewDir.xyz);
 				fragColor.a = color0.a;
 				fragColor.a = color0.a;
 			}
 			}
 		};
 		};

+ 17 - 6
Data/Raw/Editor/Shaders/GizmoPicking.bsl

@@ -1,6 +1,12 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;	
+	mat4x4		gMatViewProj;
+	float		gAlphaCutoff;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique =
 Technique =
@@ -13,7 +19,11 @@ Technique =
 
 
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float		gAlphaCutoff;
+			}
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -21,7 +31,7 @@ Technique =
 				out float4 oPosition : SV_Position,
 				out float4 oPosition : SV_Position,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oColor = inColor;
 				oColor = inColor;
 			}
 			}
 		};
 		};
@@ -56,14 +66,15 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
 			
 			
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				float	gAlphaCutoff;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}
 			}
 		};
 		};

+ 37 - 26
Data/Raw/Editor/Shaders/GizmoPickingAlpha.bsl

@@ -1,10 +1,15 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
-	float		alphaCutoff;
+	mat4x4		gMatViewProj;
+	float		gAlphaCutoff;
 	
 	
-	Sampler2D 	mainTexSamp : alias("mainTexture");
-	Texture2D 	mainTexture;	
+	Sampler2D 	gMainTexSamp : alias("gMainTexture");
+	Texture2D 	gMainTexture;	
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique =
 Technique =
@@ -15,9 +20,18 @@ Technique =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
 
 
+		Common =
+		{
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float		gAlphaCutoff;
+			}
+		};		
+		
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			float4x4 gMatViewProj;
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -27,7 +41,7 @@ Technique =
 				out float2 oUv : TEXCOORD0,
 				out float2 oUv : TEXCOORD0,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oUv = uv;
 				oUv = uv;
 				oColor = color;
 				oColor = color;
 			}
 			}
@@ -35,17 +49,15 @@ Technique =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			SamplerState mainTexSamp : register(s0);
-			Texture2D mainTexture : register(t0);
-
-			float alphaCutoff;
+			SamplerState gMainTexSamp : register(s0);
+			Texture2D gMainTexture : register(t0);
 
 
 			float4 main(in float4 inPos : SV_Position, 
 			float4 main(in float4 inPos : SV_Position, 
 						   in float2 uv : TEXCOORD0,
 						   in float2 uv : TEXCOORD0,
 						   in float4 inColor : COLOR0) : SV_Target
 						   in float4 inColor : COLOR0) : SV_Target
 			{
 			{
-				float4 color = mainTexture.Sample(mainTexSamp, uv);
-				if(color.a < alphaCutoff)
+				float4 color = gMainTexture.Sample(gMainTexSamp, uv);
+				if(color.a < gAlphaCutoff)
 					discard;
 					discard;
 				
 				
 				return inColor;
 				return inColor;
@@ -62,6 +74,15 @@ Technique =
 	{
 	{
 		Scissor = true;
 		Scissor = true;
 
 
+		Common =
+		{
+			layout(binding = 0, std140) uniform Uniforms
+			{
+				mat4 	gMatViewProj;
+				float	gAlphaCutoff;
+			};
+		};
+		
 		Vertex =
 		Vertex =
 		{
 		{
 			layout(location = 0) in vec3 bs_position;
 			layout(location = 0) in vec3 bs_position;
@@ -76,14 +97,9 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
 			
 			
-			layout(binding = 0) uniform VertUBO
-			{
-				mat4 matViewProj;
-			};
-			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				texcoord0 = bs_texcoord0;
 				texcoord0 = bs_texcoord0;
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}
 			}
@@ -95,18 +111,13 @@ Technique =
 			layout(location = 1) in vec4 color0;
 			layout(location = 1) in vec4 color0;
 			
 			
 			layout(location = 0) out vec4 fragColor;
 			layout(location = 0) out vec4 fragColor;
-
-			layout(binding = 1) uniform FragUBO
-			{
-				float alphaCutoff;
-			};
 			
 			
-			layout(binding = 2) uniform sampler2D mainTexture;
+			layout(binding = 1) uniform sampler2D gMainTexture;
 			
 			
 			void main()
 			void main()
 			{
 			{
-				vec4 texColor = texture2D(mainTexture, texcoord0);
-				if(texColor.a < alphaCutoff)
+				vec4 texColor = texture2D(gMainTexture, texcoord0);
+				if(texColor.a < gAlphaCutoff)
 					discard;
 					discard;
 				
 				
 				fragColor = color0;
 				fragColor = color0;

+ 40 - 23
Data/Raw/Editor/Shaders/IconGizmo.bsl

@@ -1,8 +1,15 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
-	Sampler2D 	mainTexSamp : alias("mainTexture");
-	Texture2D 	mainTexture;
+	mat4x4		gMatViewProj;
+	float4		gViewDir;
+	
+	Sampler2D 	gMainTexSamp : alias("gMainTexture");
+	Texture2D 	gMainTexture;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique =
 Technique =
@@ -22,7 +29,11 @@ Technique =
 		
 		
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -32,7 +43,7 @@ Technique =
 				out float2 oUv : TEXCOORD0,
 				out float2 oUv : TEXCOORD0,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oUv = uv;
 				oUv = uv;
 				oColor = color;
 				oColor = color;
 			}		
 			}		
@@ -40,15 +51,15 @@ Technique =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			SamplerState mainTexSamp : register(s0);
-			Texture2D mainTexture : register(t0);
+			SamplerState gMainTexSamp : register(s0);
+			Texture2D gMainTexture : register(t0);
 
 
 			float4 main(
 			float4 main(
 				in float4 inPos : SV_Position, 
 				in float4 inPos : SV_Position, 
 				float2 uv : TEXCOORD0, 
 				float2 uv : TEXCOORD0, 
 				float4 color : COLOR0) : SV_Target
 				float4 color : COLOR0) : SV_Target
 			{
 			{
-				return color * mainTexture.Sample(mainTexSamp, uv);
+				return color * gMainTexture.Sample(gMainTexSamp, uv);
 			}		
 			}		
 		};
 		};
 	};
 	};
@@ -66,7 +77,11 @@ Technique =
 		
 		
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -76,7 +91,7 @@ Technique =
 				out float2 oUv : TEXCOORD0,
 				out float2 oUv : TEXCOORD0,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oUv = uv;
 				oUv = uv;
 				oColor = color;
 				oColor = color;
 			}		
 			}		
@@ -84,15 +99,15 @@ Technique =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			SamplerState mainTexSamp : register(s0);
-			Texture2D mainTexture : register(t0);
+			SamplerState gMainTexSamp : register(s0);
+			Texture2D gMainTexture : register(t0);
 
 
 			float4 main(
 			float4 main(
 				in float4 inPos : SV_Position, 
 				in float4 inPos : SV_Position, 
 				float2 uv : TEXCOORD0, 
 				float2 uv : TEXCOORD0, 
 				float4 color : COLOR0) : SV_Target
 				float4 color : COLOR0) : SV_Target
 			{
 			{
-				return color * mainTexture.Sample(mainTexSamp, uv);
+				return color * gMainTexture.Sample(gMainTexSamp, uv);
 			}		
 			}		
 		};
 		};
 	};	
 	};	
@@ -127,14 +142,15 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};		
 			};		
 		
 		
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				texcoord0 = bs_texcoord0;
 				texcoord0 = bs_texcoord0;
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}		
 			}		
@@ -146,11 +162,11 @@ Technique =
 			layout(location = 1) in vec2 texcoord0;
 			layout(location = 1) in vec2 texcoord0;
 			layout(location = 0) out vec4 fragColor;
 			layout(location = 0) out vec4 fragColor;
 
 
-			layout(binding = 1) uniform sampler2D mainTexture;
+			layout(binding = 1) uniform sampler2D gMainTexture;
 			
 			
 			void main()
 			void main()
 			{
 			{
-				vec4 texColor = texture2D(mainTexture, texcoord0.st);
+				vec4 texColor = texture2D(gMainTexture, texcoord0.st);
 				fragColor = color0 * texColor;
 				fragColor = color0 * texColor;
 			}		
 			}		
 		};
 		};
@@ -181,14 +197,15 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};
 			};
 
 
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				texcoord0 = bs_texcoord0;
 				texcoord0 = bs_texcoord0;
 				color0 = bs_color1;
 				color0 = bs_color1;
 			}		
 			}		
@@ -200,11 +217,11 @@ Technique =
 			layout(location = 1) in vec2 texcoord0;
 			layout(location = 1) in vec2 texcoord0;
 			layout(location = 0) out vec4 fragColor;
 			layout(location = 0) out vec4 fragColor;
 
 
-			layout(binding = 1) uniform sampler2D mainTexture;
+			layout(binding = 1) uniform sampler2D gMainTexture;
 			
 			
 			void main()
 			void main()
 			{
 			{
-				vec4 texColor = texture2D(mainTexture, texcoord0.st);
+				vec4 texColor = texture2D(gMainTexture, texcoord0.st);
 				fragColor = color0 * texColor;
 				fragColor = color0 * texColor;
 			}		
 			}		
 		};
 		};

+ 25 - 13
Data/Raw/Editor/Shaders/TextGizmo.bsl

@@ -1,8 +1,15 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
-	Sampler2D 	mainTexSamp : alias("mainTexture");
-	Texture2D 	mainTexture;
+	mat4x4		gMatViewProj;
+	float4		gViewDir;
+	
+	Sampler2D 	gMainTexSamp : alias("gMainTexture");
+	Texture2D 	gMainTexture;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique =
 Technique =
@@ -21,7 +28,11 @@ Technique =
 		
 		
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
 
 
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
@@ -31,7 +42,7 @@ Technique =
 				out float2 oUv : TEXCOORD0,
 				out float2 oUv : TEXCOORD0,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oUv = uv;
 				oUv = uv;
 				oColor = color;
 				oColor = color;
 			}		
 			}		
@@ -39,15 +50,15 @@ Technique =
 		
 		
 		Fragment =
 		Fragment =
 		{
 		{
-			SamplerState mainTexSamp : register(s0);
-			Texture2D mainTexture : register(t0);
+			SamplerState gMainTexSamp : register(s0);
+			Texture2D gMainTexture : register(t0);
 
 
 			float4 main(
 			float4 main(
 				in float4 inPos : SV_Position, 
 				in float4 inPos : SV_Position, 
 				float2 uv : TEXCOORD0, 
 				float2 uv : TEXCOORD0, 
 				float4 color : COLOR0) : SV_Target
 				float4 color : COLOR0) : SV_Target
 			{
 			{
-				return float4(color.rgb, mainTexture.Sample(mainTexSamp, uv).r * color.a);
+				return float4(color.rgb, gMainTexture.Sample(gMainTexSamp, uv).r * color.a);
 			}		
 			}		
 		};
 		};
 	};
 	};
@@ -81,14 +92,15 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};		
 			};		
 		
 		
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				texcoord0 = bs_texcoord0;
 				texcoord0 = bs_texcoord0;
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}		
 			}		
@@ -101,11 +113,11 @@ Technique =
 			
 			
 			layout(location = 0) out vec4 fragColor;
 			layout(location = 0) out vec4 fragColor;
 
 
-			layout(binding = 1) uniform sampler2D mainTexture;
+			layout(binding = 1) uniform sampler2D gMainTexture;
 			
 			
 			void main()
 			void main()
 			{
 			{
-				fragColor = vec4(color0.rgb, texture2D(mainTexture, texcoord0.st).r * color0.a);
+				fragColor = vec4(color0.rgb, texture2D(gMainTexture, texcoord0.st).r * color0.a);
 			}		
 			}		
 		};
 		};
 	};
 	};

+ 18 - 7
Data/Raw/Editor/Shaders/WireGizmo.bsl

@@ -1,6 +1,12 @@
 Parameters =
 Parameters =
 {
 {
-	mat4x4		matViewProj;
+	mat4x4		gMatViewProj;
+	float4		gViewDir;
+};
+
+Blocks =
+{
+	Block Uniforms : auto("GizmoUniforms");
 };
 };
 
 
 Technique =
 Technique =
@@ -13,15 +19,19 @@ Technique =
 	
 	
 		Vertex =
 		Vertex =
 		{
 		{
-			float4x4 matViewProj;
-
+			cbuffer Uniforms
+			{
+				float4x4 	gMatViewProj;
+				float4		gViewDir;
+			}
+			
 			void main(
 			void main(
 				in float3 inPos : POSITION,
 				in float3 inPos : POSITION,
 				in float4 color : COLOR0,
 				in float4 color : COLOR0,
 				out float4 oPosition : SV_Position,
 				out float4 oPosition : SV_Position,
 				out float4 oColor : COLOR0)
 				out float4 oColor : COLOR0)
 			{
 			{
-				oPosition = mul(matViewProj, float4(inPos.xyz, 1));
+				oPosition = mul(gMatViewProj, float4(inPos.xyz, 1));
 				oColor = color;
 				oColor = color;
 			}
 			}
 		};
 		};
@@ -55,14 +65,15 @@ Technique =
 				vec4 gl_Position;
 				vec4 gl_Position;
 			};		
 			};		
 		
 		
-			layout(binding = 0) uniform VertUBO
+			layout(binding = 0, std140) uniform Uniforms
 			{
 			{
-				mat4 matViewProj;
+				mat4 	gMatViewProj;
+				vec4	gViewDir;
 			};
 			};
 			
 			
 			void main()
 			void main()
 			{
 			{
-				gl_Position = matViewProj * vec4(bs_position.xyz, 1);
+				gl_Position = gMatViewProj * vec4(bs_position.xyz, 1);
 				color0 = bs_color0;
 				color0 = bs_color0;
 			}
 			}
 		};
 		};

+ 72 - 91
Source/BansheeEditor/Include/BsGizmoManager.h

@@ -9,6 +9,7 @@
 #include "BsMatrix4.h"
 #include "BsMatrix4.h"
 #include "BsGpuParam.h"
 #include "BsGpuParam.h"
 #include "BsDrawHelper.h"
 #include "BsDrawHelper.h"
+#include "BsParamBlocks.h"
 
 
 namespace bs
 namespace bs
 {
 {
@@ -18,6 +19,12 @@ namespace bs
 
 
 	class GizmoManagerCore;
 	class GizmoManagerCore;
 
 
+	/** Type of mesh that can be drawn by the gizmo renderer. */
+	enum class GizmoMeshType
+	{
+		Solid, Line, Wire, Text, Count
+	};
+
 	/**
 	/**
 	 * Handles the rendering and picking of gizmo elements. Gizmos are icons and 3D objects usually rendered in scene view
 	 * Handles the rendering and picking of gizmo elements. Gizmos are icons and 3D objects usually rendered in scene view
 	 * for various visualization purposes (for example a Camera component will have a gizmo that draws a Camera icon since
 	 * for various visualization purposes (for example a Camera component will have a gizmo that draws a Camera icon since
@@ -359,6 +366,21 @@ namespace bs
 		{
 		{
 			UINT32 count;
 			UINT32 count;
 			SPtr<TextureCore> texture;
 			SPtr<TextureCore> texture;
+			UINT32 paramsIdx;
+		};
+
+		/** Data about a mesh rendered by the draw manager. */
+		struct MeshRenderData
+		{
+			MeshRenderData(const SPtr<MeshCoreBase>& mesh, SPtr<TextureCore> texture, GizmoMeshType type)
+				:mesh(mesh), texture(texture), type(type), paramsIdx(0)
+			{ }
+
+			SPtr<MeshCoreBase> mesh;
+			SPtr<TextureCore> texture;
+			GizmoMeshType type;
+
+			UINT32 paramsIdx;
 		};
 		};
 
 
 		/**	Data used for initializing the core thread equivalent of the gizmo manager. */
 		/**	Data used for initializing the core thread equivalent of the gizmo manager. */
@@ -388,11 +410,15 @@ namespace bs
 		 * @return					A mesh containing all of the visible icons. Mesh is allocated using the icon mesh heap
 		 * @return					A mesh containing all of the visible icons. Mesh is allocated using the icon mesh heap
 		 *							and should be deallocated manually.
 		 *							and should be deallocated manually.
 		 */
 		 */
-		SPtr<TransientMesh> buildIconMesh(const SPtr<Camera>& camera, const Vector<IconData>& iconData, bool forPicking, IconRenderDataVecPtr& renderData);
+		SPtr<TransientMesh> buildIconMesh(const SPtr<Camera>& camera, const Vector<IconData>& iconData, bool forPicking, 
+			IconRenderDataVecPtr& renderData);
 
 
 		/**	Resizes the icon width/height so it is always scaled to optimal size (with preserved aspect). */
 		/**	Resizes the icon width/height so it is always scaled to optimal size (with preserved aspect). */
 		void limitIconSize(UINT32& width, UINT32& height);
 		void limitIconSize(UINT32& width, UINT32& height);
 
 
+		/** Converts mesh data from DrawHelper into mesh data usable by the gizmo renderer. */
+		Vector<MeshRenderData> GizmoManager::createMeshProxyData(const Vector<DrawHelper::ShapeMeshData>& meshData);
+
 		/**
 		/**
 		 * Calculates colors for an icon based on its position in the camera. For example icons too close to too far might
 		 * Calculates colors for an icon based on its position in the camera. For example icons too close to too far might
 		 * be faded.
 		 * be faded.
@@ -476,6 +502,16 @@ namespace bs
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
+	BS_PARAM_BLOCK_BEGIN(GizmoParamBuffer)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
+		BS_PARAM_BLOCK_ENTRY(Vector4, gViewDir)
+	BS_PARAM_BLOCK_END
+
+	BS_PARAM_BLOCK_BEGIN(GizmoPickingParamBuffer)
+		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
+		BS_PARAM_BLOCK_ENTRY(float, gAlphaCutoff)
+	BS_PARAM_BLOCK_END
+
 	/**
 	/**
 	 * Core thread version of the gizmo manager that handles most of the rendering of meshes provided by the gizmo manager.
 	 * Core thread version of the gizmo manager that handles most of the rendering of meshes provided by the gizmo manager.
 	 */
 	 */
@@ -483,78 +519,6 @@ namespace bs
 	{
 	{
 		friend class GizmoManager;
 		friend class GizmoManager;
 
 
-		/**	Solid gizmo material and parameter handles. */
-		struct SolidMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj;
-			GpuParamVec4Core viewDir;
-		};
-
-		/**	Wire gizmo material and parameter handles. */
-		struct WireMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj;
-		};
-
-		/**	Icon gizmo material and parameter handles. */
-		struct IconMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj[2];
-			GpuParamTextureCore texture[2];
-		};
-
-		/**	Text gizmo material and parameter handles. */
-		struct TextMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj;
-			GpuParamTextureCore texture;
-		};
-
-		/**	Gizmo material and parameter handles used for picking. */
-		struct PickingMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj;
-		};
-
-		/**
-		 * Gizmo material and parameter handles used for picking, with blending support (generally used for icon picking).
-		 */
-		struct AlphaPickingMaterialData
-		{
-			SPtr<MaterialCore> mat;
-			SPtr<GpuParamsSetCore> params;
-			GpuParamMat4Core viewProj;
-			GpuParamTextureCore texture;
-		};
-
-		/** Type of mesh that can be drawn. */
-		enum class MeshType
-		{
-			Solid, Line, Wire, Text
-		};
-
-		/** Data about a mesh rendered by the draw manager. */
-		struct MeshData
-		{
-			MeshData(const SPtr<MeshCoreBase>& mesh, SPtr<TextureCore> texture, MeshType type)
-				:mesh(mesh), texture(texture), type(type)
-			{ }
-
-			SPtr<MeshCoreBase> mesh;
-			SPtr<TextureCore> texture;
-			MeshType type;
-		};
-
 		struct PrivatelyConstuct { };
 		struct PrivatelyConstuct { };
 
 
 	public:
 	public:
@@ -568,18 +532,30 @@ namespace bs
 		/**	Renders all gizmos in the parent camera. */
 		/**	Renders all gizmos in the parent camera. */
 		void render();
 		void render();
 
 
+		/**	
+		 * Renders all provided meshes using the provided camera. 
+		 *
+		 * @param[in]	camera				Sets the camera all rendering will be performed to.
+		 * @param[in]	meshes				Meshes to render.
+		 * @param[in]	iconMesh			Mesh containing icon meshes.
+		 * @param[in]	iconRenderData		Icon render data outlining which parts of the icon mesh use which textures.
+		 * @param[in]	usePickingMaterial	If true, meshes will be rendered using a special picking materials, otherwise
+		 *									they'll be rendered using normal drawing materials.
+		 */
+		void renderData(const SPtr<CameraCore>& camera, Vector<GizmoManager::MeshRenderData>& meshes, 
+			const SPtr<MeshCoreBase>& iconMesh, const GizmoManager::IconRenderDataVecPtr& iconRenderData, 
+			bool usePickingMaterial);
+
 		/**
 		/**
-		 * Renders a non-icon gizmo mesh using the provided parameters.
+		 * Renders a non-icon gizmo mesh using the provided material. Relevant material parameters are expected to be
+		 * assigned before this is called.
 		 *
 		 *
-		 * @param[in]	viewMatrix	View matrix of the camera we are rendering with.
-		 * @param[in]	projMatrix	Projection matrix of the camera we are rendering with.
-		 * @param[in]	viewDir		View direction of the camera we are rendering with.
 		 * @param[in]	mesh		Mesh to render. This is normally the solid or wireframe gizmo mesh.
 		 * @param[in]	mesh		Mesh to render. This is normally the solid or wireframe gizmo mesh.
 		 * @param[in]	texture		Texture to apply to the material, if the material supports a texture.
 		 * @param[in]	texture		Texture to apply to the material, if the material supports a texture.
 		 * @param[in]	material	Material to use for rendering. This is normally the solid, wireframe or picking material.
 		 * @param[in]	material	Material to use for rendering. This is normally the solid, wireframe or picking material.
 		 */
 		 */
-		void renderGizmos(const Matrix4& viewMatrix, const Matrix4& projMatrix, const Vector3& viewDir, 
-			const SPtr<MeshCoreBase>& mesh, const SPtr<TextureCore>& texture, GizmoManager::GizmoMaterial material);
+		void renderGizmoMesh(const SPtr<MeshCoreBase>& mesh, const SPtr<TextureCore>& texture, 
+			GizmoManager::GizmoMaterial material);
 
 
 		/**
 		/**
 		 * Renders the icon gizmo mesh using the provided parameters.
 		 * Renders the icon gizmo mesh using the provided parameters.
@@ -589,7 +565,8 @@ namespace bs
 		 * @param[in]	renderData			Icon render data outlining which parts of the icon mesh use which textures.
 		 * @param[in]	renderData			Icon render data outlining which parts of the icon mesh use which textures.
 		 * @param[in]	usePickingMaterial	Should the icons be rendered normally or for picking.
 		 * @param[in]	usePickingMaterial	Should the icons be rendered normally or for picking.
 		 */
 		 */
-		void renderIconGizmos(Rect2I screenArea, SPtr<MeshCoreBase> mesh, GizmoManager::IconRenderDataVecPtr renderData, bool usePickingMaterial);
+		void renderIconGizmos(Rect2I screenArea, SPtr<MeshCoreBase> mesh, GizmoManager::IconRenderDataVecPtr renderData, 
+			bool usePickingMaterial);
 
 
 		/**
 		/**
 		 * Updates the internal data that is used for rendering. Normally you would call this after updating the camera or
 		 * Updates the internal data that is used for rendering. Normally you would call this after updating the camera or
@@ -600,26 +577,30 @@ namespace bs
 		 * @param[in]	iconMesh		Mesh containing icon meshes.
 		 * @param[in]	iconMesh		Mesh containing icon meshes.
 		 * @param[in]	iconRenderData	Icon render data outlining which parts of the icon mesh use which textures.
 		 * @param[in]	iconRenderData	Icon render data outlining which parts of the icon mesh use which textures.
 		 */
 		 */
-		void updateData(const SPtr<CameraCore>& camera, const Vector<MeshData>& meshes, const SPtr<MeshCoreBase>& iconMesh, 
-			const GizmoManager::IconRenderDataVecPtr& iconRenderData);
+		void updateData(const SPtr<CameraCore>& camera, const Vector<GizmoManager::MeshRenderData>& meshes, 
+			const SPtr<MeshCoreBase>& iconMesh,  const GizmoManager::IconRenderDataVecPtr& iconRenderData);
 
 
 		static const float PICKING_ALPHA_CUTOFF;
 		static const float PICKING_ALPHA_CUTOFF;
 
 
 		SPtr<CameraCore> mCamera;
 		SPtr<CameraCore> mCamera;
 
 
-		Vector<MeshData> mMeshes;
+		Vector<GizmoManager::MeshRenderData> mMeshes;
 		SPtr<MeshCoreBase> mIconMesh;
 		SPtr<MeshCoreBase> mIconMesh;
 		GizmoManager::IconRenderDataVecPtr mIconRenderData;
 		GizmoManager::IconRenderDataVecPtr mIconRenderData;
 
 
+		Vector<SPtr<GpuParamsSetCore>> mMeshParamSets[(UINT32)GizmoMeshType::Count];
+		Vector<SPtr<GpuParamsSetCore>> mIconParamSets;
+		Vector<SPtr<GpuParamsSetCore>> mPickingParamSets[2];
+
+		GizmoParamBuffer mMeshGizmoBuffer;
+		GizmoParamBuffer mIconGizmoBuffer;
+		GizmoPickingParamBuffer mMeshPickingParamBuffer;
+		GizmoPickingParamBuffer mIconPickingParamBuffer;
+
 		// Immutable
 		// Immutable
-		SolidMaterialData mSolidMaterial;
-		SolidMaterialData mWireMaterial;
-		WireMaterialData mLineMaterial;
-		IconMaterialData mIconMaterial;
-		TextMaterialData mTextMaterial;
-
-		PickingMaterialData mPickingMaterial;
-		AlphaPickingMaterialData mAlphaPickingMaterial;
+		SPtr<MaterialCore> mMeshMaterials[(UINT32)GizmoMeshType::Count];
+		SPtr<MaterialCore> mIconMaterial;
+		SPtr<MaterialCore> mPickingMaterials[2];
 	};
 	};
 
 
 	/** @} */
 	/** @} */

+ 177 - 207
Source/BansheeEditor/Source/BsGizmoManager.cpp

@@ -424,6 +424,28 @@ namespace bs
 		mIdxToSceneObjectMap[textData.idx] = mActiveSO;
 		mIdxToSceneObjectMap[textData.idx] = mActiveSO;
 	}
 	}
 
 
+	Vector<GizmoManager::MeshRenderData> GizmoManager::createMeshProxyData(const Vector<DrawHelper::ShapeMeshData>& meshData)
+	{
+		Vector<MeshRenderData> proxyData;
+		for (auto& entry : meshData)
+		{
+			SPtr<TextureCore> tex;
+			if (entry.texture.isLoaded())
+				tex = entry.texture->getCore();
+
+			if (entry.type == DrawHelper::MeshType::Solid)
+				proxyData.push_back(MeshRenderData(entry.mesh->getCore(), tex, GizmoMeshType::Solid));
+			else if (entry.type == DrawHelper::MeshType::Wire)
+				proxyData.push_back(MeshRenderData(entry.mesh->getCore(), tex, GizmoMeshType::Wire));
+			else if (entry.type == DrawHelper::MeshType::Line)
+				proxyData.push_back(MeshRenderData(entry.mesh->getCore(), tex, GizmoMeshType::Line));
+			else // Text
+				proxyData.push_back(MeshRenderData(entry.mesh->getCore(), tex, GizmoMeshType::Text));
+		}
+
+		return proxyData;
+	}
+
 	void GizmoManager::update(const SPtr<Camera>& camera)
 	void GizmoManager::update(const SPtr<Camera>& camera)
 	{
 	{
 		mDrawHelper->clearMeshes(mActiveMeshes);
 		mDrawHelper->clearMeshes(mActiveMeshes);
@@ -437,34 +459,7 @@ namespace bs
 		mDrawHelper->buildMeshes(DrawHelper::SortType::BackToFront, camera->getPosition());
 		mDrawHelper->buildMeshes(DrawHelper::SortType::BackToFront, camera->getPosition());
 		mActiveMeshes = mDrawHelper->getMeshes();
 		mActiveMeshes = mDrawHelper->getMeshes();
 
 
-		Vector<GizmoManagerCore::MeshData> proxyData;
-		for (auto& meshData : mActiveMeshes)
-		{
-			SPtr<TextureCore> tex;
-			if (meshData.texture.isLoaded())
-				tex = meshData.texture->getCore();
-
-			if (meshData.type == DrawHelper::MeshType::Solid)
-			{
-				proxyData.push_back(GizmoManagerCore::MeshData(
-					meshData.mesh->getCore(), tex, GizmoManagerCore::MeshType::Solid));
-			}
-			else if(meshData.type == DrawHelper::MeshType::Wire)
-			{
-				proxyData.push_back(GizmoManagerCore::MeshData(
-					meshData.mesh->getCore(), tex, GizmoManagerCore::MeshType::Wire));
-			}
-			else if (meshData.type == DrawHelper::MeshType::Line)
-			{
-				proxyData.push_back(GizmoManagerCore::MeshData(
-					meshData.mesh->getCore(), tex, GizmoManagerCore::MeshType::Line));
-			}
-			else // Text
-			{
-				proxyData.push_back(GizmoManagerCore::MeshData(
-					meshData.mesh->getCore(), tex, GizmoManagerCore::MeshType::Text));
-			}
-		}
+		Vector<MeshRenderData> proxyData = createMeshProxyData(mActiveMeshes);
 
 
 		mIconMesh = buildIconMesh(camera, mIconData, false, iconRenderData);
 		mIconMesh = buildIconMesh(camera, mIconData, false, iconRenderData);
 		SPtr<MeshCoreBase> iconMesh = mIconMesh->getCore();
 		SPtr<MeshCoreBase> iconMesh = mIconMesh->getCore();
@@ -645,34 +640,11 @@ namespace bs
 		SPtr<TransientMesh> iconMesh = buildIconMesh(camera, iconData, true, iconRenderData);
 		SPtr<TransientMesh> iconMesh = buildIconMesh(camera, iconData, true, iconRenderData);
 
 
 		// Note: This must be rendered while Scene view is being rendered
 		// Note: This must be rendered while Scene view is being rendered
-		Matrix4 viewMat = camera->getViewMatrix();
-		Matrix4 projMat = camera->getProjectionMatrixRS();
-		SPtr<Viewport> viewport = camera->getViewport();
-
 		GizmoManagerCore* core = mCore.load(std::memory_order_relaxed);
 		GizmoManagerCore* core = mCore.load(std::memory_order_relaxed);
 
 
-		for (auto& meshData : meshes)
-		{
-			SPtr<TextureCore> tex;
-			if (meshData.texture.isLoaded())
-				tex = meshData.texture->getCore();
-
-			if(meshData.type == DrawHelper::MeshType::Text)
-			{
-				gCoreThread().queueCommand(std::bind(&GizmoManagerCore::renderGizmos, core, viewMat, projMat,
-					camera->getForward(), meshData.mesh->getCore(), tex, GizmoMaterial::PickingAlpha));
-			}
-			else
-			{
-				gCoreThread().queueCommand(std::bind(&GizmoManagerCore::renderGizmos, core, viewMat, projMat,
-					camera->getForward(), meshData.mesh->getCore(), tex, GizmoMaterial::Picking));
-			}
-		}
-
-		Rect2I screenArea = camera->getViewport()->getArea();
-
-		gCoreThread().queueCommand(std::bind(&GizmoManagerCore::renderIconGizmos,
-			core, screenArea, iconMesh->getCore(), iconRenderData, true));
+		Vector<MeshRenderData> proxyData = createMeshProxyData(meshes);
+		gCoreThread().queueCommand(std::bind(&GizmoManagerCore::renderData, core, camera->getCore(),
+											 proxyData, iconMesh->getCore(), iconRenderData, true));
 
 
 		mPickingDrawHelper->clearMeshes(meshes);
 		mPickingDrawHelper->clearMeshes(meshes);
 		mIconMeshHeap->dealloc(iconMesh);
 		mIconMeshHeap->dealloc(iconMesh);
@@ -715,7 +687,7 @@ namespace bs
 		IconRenderDataVecPtr iconRenderData = bs_shared_ptr_new<IconRenderDataVec>();
 		IconRenderDataVecPtr iconRenderData = bs_shared_ptr_new<IconRenderDataVec>();
 		
 		
 		gCoreThread().queueCommand(std::bind(&GizmoManagerCore::updateData, core,
 		gCoreThread().queueCommand(std::bind(&GizmoManagerCore::updateData, core,
-			nullptr, Vector<GizmoManagerCore::MeshData>(), nullptr, iconRenderData));
+			nullptr, Vector<MeshRenderData>(), nullptr, iconRenderData));
 	}
 	}
 
 
 	SPtr<TransientMesh> GizmoManager::buildIconMesh(const SPtr<Camera>& camera, const Vector<IconData>& iconData,
 	SPtr<TransientMesh> GizmoManager::buildIconMesh(const SPtr<Camera>& camera, const Vector<IconData>& iconData,
@@ -952,187 +924,182 @@ namespace bs
 	{
 	{
 		THROW_IF_NOT_CORE_THREAD;
 		THROW_IF_NOT_CORE_THREAD;
 
 
-		mSolidMaterial.mat = initData.solidMat;
-		mWireMaterial.mat = initData.wireMat;
-		mLineMaterial.mat = initData.lineMat;
-		mTextMaterial.mat = initData.textMat;
-		mIconMaterial.mat = initData.iconMat;
-		mPickingMaterial.mat = initData.pickingMat;
-		mAlphaPickingMaterial.mat = initData.alphaPickingMat;
+		mMeshMaterials[(UINT32)GizmoMeshType::Solid] = initData.solidMat;
+		mMeshMaterials[(UINT32)GizmoMeshType::Wire] = initData.wireMat;
+		mMeshMaterials[(UINT32)GizmoMeshType::Line] = initData.lineMat;
+		mMeshMaterials[(UINT32)GizmoMeshType::Text] = initData.textMat;
+		mIconMaterial = initData.iconMat;
+		mPickingMaterials[0] = initData.pickingMat;
+		mPickingMaterials[1] = initData.alphaPickingMat;
+	}
 
 
+	void GizmoManagerCore::updateData(const SPtr<CameraCore>& camera, const Vector<GizmoManager::MeshRenderData>& meshes,
+		const SPtr<MeshCoreBase>& iconMesh, const GizmoManager::IconRenderDataVecPtr& iconRenderData)
+	{
+		if (mCamera != camera)
 		{
 		{
-			mLineMaterial.params = mLineMaterial.mat->createParamsSet();
+			SPtr<CoreRenderer> activeRenderer = RendererManager::instance().getActive();
+			if (mCamera != nullptr)
+				activeRenderer->unregisterRenderCallback(mCamera.get(), 0);
 
 
-			SPtr<GpuParamsCore> params = mLineMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mLineMaterial.viewProj);
+			if (camera != nullptr)
+				activeRenderer->registerRenderCallback(camera.get(), 0, std::bind(&GizmoManagerCore::render, this));
 		}
 		}
 
 
-		{
-			mSolidMaterial.params = mSolidMaterial.mat->createParamsSet();
+		mCamera = camera;
+		mMeshes = meshes;
+		mIconMesh = iconMesh;
+		mIconRenderData = iconRenderData;
 
 
-			SPtr<GpuParamsCore> params = mSolidMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mSolidMaterial.viewProj);
-			params->getParam(GPT_FRAGMENT_PROGRAM, "viewDir", mSolidMaterial.viewDir);
-		}
+		// Allocate and assign GPU program parameter objects
+		UINT32 meshCounters[(UINT32)GizmoMeshType::Count];
+		bs_zero_out(meshCounters);
 
 
+		for (auto& meshData : mMeshes)
 		{
 		{
-			mWireMaterial.params = mWireMaterial.mat->createParamsSet();
+			UINT32 typeIdx = (UINT32)meshData.type;
+			UINT32 paramsIdx = meshCounters[typeIdx];
 
 
-			SPtr<GpuParamsCore> params = mWireMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mWireMaterial.viewProj);
-		}
+			meshData.paramsIdx = paramsIdx;
 
 
-		{
-			mIconMaterial.params = mIconMaterial.mat->createParamsSet();
+			if (paramsIdx >= mMeshParamSets[typeIdx].size())
+			{
+				SPtr<GpuParamsSetCore> paramsSet = mMeshMaterials[typeIdx]->createParamsSet();
+				paramsSet->setParamBlockBuffer("Uniforms", mMeshGizmoBuffer.getBuffer(), true);
 
 
-			SPtr<GpuParamsCore> params0 = mIconMaterial.params->getGpuParams(0);
-			params0->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mIconMaterial.viewProj[0]);
-			params0->getTextureParam(GPT_FRAGMENT_PROGRAM, "mainTexture", mIconMaterial.texture[0]);
+				mMeshParamSets[typeIdx].push_back(paramsSet);
+			}
 
 
-			SPtr<GpuParamsCore> params1 = mIconMaterial.params->getGpuParams(1);
-			params1->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mIconMaterial.viewProj[1]);
-			params1->getTextureParam(GPT_FRAGMENT_PROGRAM, "mainTexture", mIconMaterial.texture[1]);
+			meshCounters[typeIdx]++;
 		}
 		}
 
 
+		UINT32 iconMeshIdx = 0;
+		for(auto& iconData : *mIconRenderData)
 		{
 		{
-			mPickingMaterial.params = mPickingMaterial.mat->createParamsSet();
+			iconData.paramsIdx = iconMeshIdx;
 
 
-			SPtr<GpuParamsCore> params = mPickingMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mPickingMaterial.viewProj);
-		}
+			SPtr<GpuParamsSetCore> paramsSet;
+			if (iconMeshIdx >= mIconParamSets.size())
+			{
+				mIconMaterial->createParamsSet();
+				paramsSet->setParamBlockBuffer("Uniforms", mIconGizmoBuffer.getBuffer(), true);
 
 
-		{
-			mAlphaPickingMaterial.params = mAlphaPickingMaterial.mat->createParamsSet();
+				mIconParamSets.push_back(paramsSet);
+			}
+			else
+				paramsSet = mIconParamSets[iconMeshIdx];
 
 
-			SPtr<GpuParamsCore> params = mAlphaPickingMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mAlphaPickingMaterial.viewProj);
-			params->getTextureParam(GPT_FRAGMENT_PROGRAM, "mainTexture", mAlphaPickingMaterial.texture);
+			SPtr<GpuParamsCore> params0 = paramsSet->getGpuParams(0);
+			SPtr<GpuParamsCore> params1 = paramsSet->getGpuParams(1);
 
 
-			GpuParamFloatCore alphaCutoffParam;
-			params->getParam(GPT_FRAGMENT_PROGRAM, "alphaCutoff", alphaCutoffParam);
-			alphaCutoffParam.set(PICKING_ALPHA_CUTOFF);
-		}
+			GpuParamTextureCore textureParam0;
+			GpuParamTextureCore textureParam1;
 
 
-		{
-			mTextMaterial.params = mTextMaterial.mat->createParamsSet();
+			params0->getTextureParam(GPT_FRAGMENT_PROGRAM, "gMainTexture", textureParam0);
+			params1->getTextureParam(GPT_FRAGMENT_PROGRAM, "gMainTexture", textureParam1);
+
+			textureParam0.set(iconData.texture);
+			textureParam1.set(iconData.texture);
 
 
-			SPtr<GpuParamsCore> params = mTextMaterial.params->getGpuParams();
-			params->getParam(GPT_VERTEX_PROGRAM, "matViewProj", mTextMaterial.viewProj);
-			params->getTextureParam(GPT_FRAGMENT_PROGRAM, "mainTexture", mTextMaterial.texture);
+			iconMeshIdx++;
 		}
 		}
 	}
 	}
 
 
-	void GizmoManagerCore::updateData(const SPtr<CameraCore>& camera, const Vector<MeshData>& meshes, 
-		const SPtr<MeshCoreBase>& iconMesh, const GizmoManager::IconRenderDataVecPtr& iconRenderData)
+	void GizmoManagerCore::render()
 	{
 	{
-		if (mCamera != camera)
-		{
-			SPtr<CoreRenderer> activeRenderer = RendererManager::instance().getActive();
-			if (mCamera != nullptr)
-				activeRenderer->unregisterRenderCallback(mCamera.get(), 0);
-
-			if (camera != nullptr)
-				activeRenderer->registerRenderCallback(camera.get(), 0, std::bind(&GizmoManagerCore::render, this));
-		}
-
-		mCamera = camera;
-		mMeshes = meshes;
-		mIconMesh = iconMesh;
-		mIconRenderData = iconRenderData;
+		renderData(mCamera, mMeshes, mIconMesh, mIconRenderData, false);
 	}
 	}
 
 
-	void GizmoManagerCore::render()
+	void GizmoManagerCore::renderData(const SPtr<CameraCore>& camera, Vector<GizmoManager::MeshRenderData>& meshes,
+		const SPtr<MeshCoreBase>& iconMesh, const GizmoManager::IconRenderDataVecPtr& iconRenderData, bool usePickingMaterial)
 	{
 	{
-		if (mCamera == nullptr)
+		if (camera == nullptr)
 			return;
 			return;
 
 
-		SPtr<RenderTargetCore> renderTarget = mCamera->getViewport()->getTarget();
+		SPtr<RenderTargetCore> renderTarget = camera->getViewport()->getTarget();
 
 
 		float width = (float)renderTarget->getProperties().getWidth();
 		float width = (float)renderTarget->getProperties().getWidth();
 		float height = (float)renderTarget->getProperties().getHeight();
 		float height = (float)renderTarget->getProperties().getHeight();
 
 
-		Rect2 normArea = mCamera->getViewport()->getNormArea();
+		Rect2I screenArea = camera->getViewport()->getArea();
+		Matrix4 viewMatrix = camera->getViewMatrix();
+		Matrix4 projMatrix = camera->getProjectionMatrixRS();
+		Matrix4 viewProjMat = projMatrix * viewMatrix;
+
+		if (!usePickingMaterial)
+		{
+			mMeshGizmoBuffer.gMatViewProj.set(viewProjMat);
+			mMeshGizmoBuffer.gViewDir.set((Vector4)camera->getForward());
 
 
-		Rect2I screenArea;
-		screenArea.x = (int)(normArea.x * width);
-		screenArea.y = (int)(normArea.y * height);
-		screenArea.width = (int)(normArea.width * width);
-		screenArea.height = (int)(normArea.height * height);
+			for (auto& entry : meshes)
+			{
+				UINT32 typeIdx = (UINT32)entry.type;
 
 
-		for (auto& meshData : mMeshes)
+				gRendererUtility().setPass(mMeshMaterials[typeIdx]);
+				gRendererUtility().setPassParams(mMeshParamSets[typeIdx][entry.paramsIdx]);
+
+				gRendererUtility().draw(entry.mesh, entry.mesh->getProperties().getSubMesh(0));
+			}
+		}
+		else
 		{
 		{
-			GizmoManager::GizmoMaterial material = GizmoManager::GizmoMaterial::Solid;
-			switch(meshData.type)
+			// Allocate and assign GPU program parameter objects
+			UINT32 pickingCounters[2];
+			bs_zero_out(pickingCounters);
+
+			for (auto& entry : meshes)
 			{
 			{
-			case MeshType::Solid:
-				material = GizmoManager::GizmoMaterial::Solid;
-				break;
-			case MeshType::Wire:
-				material = GizmoManager::GizmoMaterial::Wire;
-				break;
-			case MeshType::Line:
-				material = GizmoManager::GizmoMaterial::Line;
-				break;
-			case MeshType::Text:
-				material = GizmoManager::GizmoMaterial::Text;
-				break;
+				UINT32 typeIdx = entry.type == GizmoMeshType::Text ? 1 : 0;
+				UINT32 paramsIdx = pickingCounters[typeIdx];
+
+				entry.paramsIdx = paramsIdx;
+
+				if (paramsIdx >= mPickingParamSets[typeIdx].size())
+				{
+					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[typeIdx]->createParamsSet();
+					paramsSet->setParamBlockBuffer("Uniforms", mMeshPickingParamBuffer.getBuffer(), true);
+
+					mPickingParamSets[typeIdx].push_back(paramsSet);
+				}
+
+				pickingCounters[typeIdx]++;
 			}
 			}
 
 
-			renderGizmos(mCamera->getViewMatrix(), mCamera->getProjectionMatrixRS(), mCamera->getForward(), 
-				meshData.mesh, meshData.texture, material);
-		}
+			for (auto& iconData : *iconRenderData)
+			{
+				iconData.paramsIdx = pickingCounters[1];
 
 
-		if (mIconMesh != nullptr)
-			renderIconGizmos(screenArea, mIconMesh, mIconRenderData, false);
-	}
+				if (iconData.paramsIdx >= mPickingParamSets[1].size())
+				{
+					SPtr<GpuParamsSetCore> paramsSet = mPickingMaterials[1]->createParamsSet();
+					paramsSet->setParamBlockBuffer("Uniforms", mIconPickingParamBuffer.getBuffer(), true);
 
 
-	void GizmoManagerCore::renderGizmos(const Matrix4& viewMatrix, const Matrix4& projMatrix, const Vector3& viewDir, 
-		const SPtr<MeshCoreBase>& mesh, const SPtr<TextureCore>& texture, GizmoManager::GizmoMaterial material)
-	{
-		THROW_IF_NOT_CORE_THREAD;
+					mPickingParamSets[1].push_back(paramsSet);
+				}
 
 
-		Matrix4 viewProjMat = projMatrix * viewMatrix;
+				pickingCounters[1]++;
+			}
 
 
-		switch (material)
-		{
-		case GizmoManager::GizmoMaterial::Solid:
-			mSolidMaterial.viewProj.set(viewProjMat);
-			mSolidMaterial.viewDir.set((Vector4)viewDir);
-			gRendererUtility().setPass(mSolidMaterial.mat);
-			gRendererUtility().setPassParams(mSolidMaterial.params);
-			break;
-		case GizmoManager::GizmoMaterial::Wire:
-			mWireMaterial.viewProj.set(viewProjMat);
-			gRendererUtility().setPass(mWireMaterial.mat);
-			gRendererUtility().setPassParams(mWireMaterial.params);
-			break;
-		case GizmoManager::GizmoMaterial::Line:
-			mLineMaterial.viewProj.set(viewProjMat);
-			gRendererUtility().setPass(mLineMaterial.mat);
-			gRendererUtility().setPassParams(mLineMaterial.params);
-			break;
-		case GizmoManager::GizmoMaterial::Picking:
-			mPickingMaterial.viewProj.set(viewProjMat);
-			gRendererUtility().setPass(mPickingMaterial.mat);
-			gRendererUtility().setPassParams(mPickingMaterial.params);
-			break;
-		case GizmoManager::GizmoMaterial::PickingAlpha:
-			mAlphaPickingMaterial.viewProj.set(viewProjMat);
-			mAlphaPickingMaterial.texture.set(texture);
-			gRendererUtility().setPass(mAlphaPickingMaterial.mat);
-			gRendererUtility().setPassParams(mAlphaPickingMaterial.params);
-			break;
-		case GizmoManager::GizmoMaterial::Text:
-			mTextMaterial.viewProj.set(viewProjMat);
-			mTextMaterial.texture.set(texture);
-			gRendererUtility().setPass(mTextMaterial.mat);
-			gRendererUtility().setPassParams(mTextMaterial.params);
-			break;
+			mMeshPickingParamBuffer.gMatViewProj.set(viewProjMat);
+			mMeshPickingParamBuffer.gAlphaCutoff.set(PICKING_ALPHA_CUTOFF);
+
+			for (auto& entry : meshes)
+			{
+				UINT32 typeIdx = entry.type == GizmoMeshType::Text ? 1 : 0;
+
+				gRendererUtility().setPass(mPickingMaterials[typeIdx]);
+				gRendererUtility().setPassParams(mPickingParamSets[typeIdx][entry.paramsIdx]);
+
+				gRendererUtility().draw(entry.mesh, entry.mesh->getProperties().getSubMesh(0));
+			}
 		}
 		}
-		gRendererUtility().draw(mesh, mesh->getProperties().getSubMesh(0));
+
+		if (iconMesh != nullptr)
+			renderIconGizmos(screenArea, iconMesh, iconRenderData, usePickingMaterial);
 	}
 	}
 
 
-	void GizmoManagerCore::renderIconGizmos(Rect2I screenArea, SPtr<MeshCoreBase> mesh, GizmoManager::IconRenderDataVecPtr renderData, bool usePickingMaterial)
+	void GizmoManagerCore::renderIconGizmos(Rect2I screenArea, SPtr<MeshCoreBase> mesh, 
+		GizmoManager::IconRenderDataVecPtr renderData, bool usePickingMaterial)
 	{
 	{
 		RenderAPICore& rapi = RenderAPICore::instance();
 		RenderAPICore& rapi = RenderAPICore::instance();
 		SPtr<VertexData> vertexData = mesh->getVertexData();
 		SPtr<VertexData> vertexData = mesh->getVertexData();
@@ -1167,21 +1134,17 @@ namespace bs
 
 
 		if (!usePickingMaterial)
 		if (!usePickingMaterial)
 		{
 		{
-			mIconMaterial.viewProj[0].set(projMat);
-			mIconMaterial.viewProj[1].set(projMat);
+			mIconGizmoBuffer.gMatViewProj.set(projMat);
+			mIconGizmoBuffer.gViewDir.set(Vector4::ZERO);
 
 
 			for (UINT32 passIdx = 0; passIdx < 2; passIdx++)
 			for (UINT32 passIdx = 0; passIdx < 2; passIdx++)
 			{
 			{
-				gRendererUtility().setPass(mIconMaterial.mat, passIdx);
-				gRendererUtility().setPassParams(mIconMaterial.params, passIdx);
-
+				gRendererUtility().setPass(mIconMaterial, passIdx);
+				
 				UINT32 curIndexOffset = mesh->getIndexOffset();
 				UINT32 curIndexOffset = mesh->getIndexOffset();
 				for (auto curRenderData : *renderData)
 				for (auto curRenderData : *renderData)
 				{
 				{
-					mIconMaterial.texture[passIdx].set(curRenderData.texture);
-
-					SPtr<GpuParamsCore> params = mIconMaterial.params->getGpuParams(passIdx);
-					rapi.setGpuParams(params);
+					gRendererUtility().setPassParams(mIconParamSets[curRenderData.paramsIdx], passIdx);
 
 
 					rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 					rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 					curIndexOffset += curRenderData.count * 6;
 					curIndexOffset += curRenderData.count * 6;
@@ -1190,22 +1153,29 @@ namespace bs
 		}
 		}
 		else
 		else
 		{
 		{
-			mAlphaPickingMaterial.viewProj.set(projMat);
+			mMeshPickingParamBuffer.gMatViewProj.set(projMat);
+			mMeshPickingParamBuffer.gAlphaCutoff.set(PICKING_ALPHA_CUTOFF);
 
 
-			gRendererUtility().setPass(mAlphaPickingMaterial.mat);
-			gRendererUtility().setPassParams(mAlphaPickingMaterial.params);
+			for (auto& iconData : *renderData)
+			{
+				SPtr<GpuParamsSetCore> paramsSet = mPickingParamSets[1][iconData.paramsIdx];
+				SPtr<GpuParamsCore> params = paramsSet->getGpuParams();
+
+				GpuParamTextureCore textureParam;
+				params->getTextureParam(GPT_FRAGMENT_PROGRAM, "gMainTexture", textureParam);
+
+				textureParam.set(iconData.texture);
+			}
 
 
-			UINT32 curIndexOffset = 0;
+			gRendererUtility().setPass(mPickingMaterials[1]);
+
+			UINT32 curIndexOffset = mesh->getIndexOffset();
 			for (auto curRenderData : *renderData)
 			for (auto curRenderData : *renderData)
 			{
 			{
-				mAlphaPickingMaterial.texture.set(curRenderData.texture);
-
-				SPtr<GpuParamsCore> params = mAlphaPickingMaterial.params->getGpuParams();
-				rapi.setGpuParams(params);
+				gRendererUtility().setPassParams(mPickingParamSets[1][curRenderData.paramsIdx]);
 
 
 				rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 				rapi.drawIndexed(curIndexOffset, curRenderData.count * 6, mesh->getVertexOffset(), curRenderData.count * 4);
 				curIndexOffset += curRenderData.count * 6;
 				curIndexOffset += curRenderData.count * 6;
-
 			}
 			}
 		}
 		}