Skip to content

Commit 0def91a

Browse files
Magnifier Material Polish (#206)
1 parent 4497602 commit 0def91a

7 files changed

Lines changed: 113 additions & 110 deletions

File tree

com.microsoft.mrtk.graphicstools.unity/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [0.6.7] - 2024-01-18
8+
9+
### Changed
10+
11+
- Added rounder corner support to the magnifier shader and sample.
12+
713
## [0.6.6] - 2023-12-01
814

915
### Added

com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Acrylic/Shaders/CanvasBackplateAcrylic.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SubShader {
117117
#pragma multi_compile_local _ _UI_CLIP_RECT_ROUNDED _UI_CLIP_RECT_ROUNDED_INDEPENDENT
118118

119119
#include "UnityCG.cginc"
120-
#include "../../../Shaders/GraphicsToolsCommon.hlsl"
120+
#include "Packages/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsCommon.hlsl"
121121

122122
CBUFFER_START(UnityPerMaterial)
123123
half4 _Base_Color_;

com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Materials/Magnifier.mat

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ MonoBehaviour:
1515
version: 4
1616
--- !u!21 &2100000
1717
Material:
18-
serializedVersion: 6
18+
serializedVersion: 8
1919
m_ObjectHideFlags: 0
2020
m_CorrespondingSourceObject: {fileID: 0}
2121
m_PrefabInstance: {fileID: 0}
2222
m_PrefabAsset: {fileID: 0}
2323
m_Name: Magnifier
2424
m_Shader: {fileID: 4800000, guid: 708bca655443cdd41b94ee29b5572b6e, type: 3}
25-
m_ShaderKeywords:
25+
m_ValidKeywords:
26+
- _ROUND_CORNERS
27+
m_InvalidKeywords: []
2628
m_LightmapFlags: 4
2729
m_EnableInstancingVariants: 0
2830
m_DoubleSidedGI: 0
@@ -31,96 +33,11 @@ Material:
3133
disabledShaderPasses: []
3234
m_SavedProperties:
3335
serializedVersion: 3
34-
m_TexEnvs:
35-
- _BaseMap:
36-
m_Texture: {fileID: 0}
37-
m_Scale: {x: 1, y: 1}
38-
m_Offset: {x: 0, y: 0}
39-
- _BumpMap:
40-
m_Texture: {fileID: 0}
41-
m_Scale: {x: 1, y: 1}
42-
m_Offset: {x: 0, y: 0}
43-
- _DetailAlbedoMap:
44-
m_Texture: {fileID: 0}
45-
m_Scale: {x: 1, y: 1}
46-
m_Offset: {x: 0, y: 0}
47-
- _DetailMask:
48-
m_Texture: {fileID: 0}
49-
m_Scale: {x: 1, y: 1}
50-
m_Offset: {x: 0, y: 0}
51-
- _DetailNormalMap:
52-
m_Texture: {fileID: 0}
53-
m_Scale: {x: 1, y: 1}
54-
m_Offset: {x: 0, y: 0}
55-
- _EmissionMap:
56-
m_Texture: {fileID: 0}
57-
m_Scale: {x: 1, y: 1}
58-
m_Offset: {x: 0, y: 0}
59-
- _MainTex:
60-
m_Texture: {fileID: 0}
61-
m_Scale: {x: 1, y: 1}
62-
m_Offset: {x: 0, y: 0}
63-
- _MetallicGlossMap:
64-
m_Texture: {fileID: 0}
65-
m_Scale: {x: 1, y: 1}
66-
m_Offset: {x: 0, y: 0}
67-
- _OcclusionMap:
68-
m_Texture: {fileID: 0}
69-
m_Scale: {x: 1, y: 1}
70-
m_Offset: {x: 0, y: 0}
71-
- _ParallaxMap:
72-
m_Texture: {fileID: 0}
73-
m_Scale: {x: 1, y: 1}
74-
m_Offset: {x: 0, y: 0}
75-
- _SpecGlossMap:
76-
m_Texture: {fileID: 0}
77-
m_Scale: {x: 1, y: 1}
78-
m_Offset: {x: 0, y: 0}
79-
- unity_Lightmaps:
80-
m_Texture: {fileID: 0}
81-
m_Scale: {x: 1, y: 1}
82-
m_Offset: {x: 0, y: 0}
83-
- unity_LightmapsInd:
84-
m_Texture: {fileID: 0}
85-
m_Scale: {x: 1, y: 1}
86-
m_Offset: {x: 0, y: 0}
87-
- unity_ShadowMasks:
88-
m_Texture: {fileID: 0}
89-
m_Scale: {x: 1, y: 1}
90-
m_Offset: {x: 0, y: 0}
36+
m_TexEnvs: []
37+
m_Ints: []
9138
m_Floats:
92-
- Magnification: 0.5
93-
- _AlphaClip: 0
94-
- _Blend: 0
95-
- _BumpScale: 1
96-
- _ClearCoatMask: 0
97-
- _ClearCoatSmoothness: 0
98-
- _Cull: 2
99-
- _Cutoff: 0.5
100-
- _DetailAlbedoMapScale: 1
101-
- _DetailNormalMapScale: 1
102-
- _DstBlend: 0
103-
- _EnvironmentReflections: 1
104-
- _GlossMapScale: 0
105-
- _Glossiness: 0
106-
- _GlossyReflections: 0
107-
- _Magnification: 0.5
108-
- _Metallic: 0
109-
- _OcclusionStrength: 1
110-
- _Parallax: 0.005
111-
- _QueueOffset: 0
112-
- _ReceiveShadows: 1
113-
- _Smoothness: 0.5
114-
- _SmoothnessTextureChannel: 0
115-
- _SpecularHighlights: 1
116-
- _SrcBlend: 1
117-
- _Surface: 0
118-
- _WorkflowMode: 1
119-
- _ZWrite: 1
120-
m_Colors:
121-
- Center: {r: 0.5, g: 0.5, b: 0, a: 0}
122-
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
123-
- _Color: {r: 1, g: 1, b: 1, a: 1}
124-
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
125-
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
39+
- _RoundCornerMargin: 0.05
40+
- _RoundCornerRadius: 0.05
41+
- _RoundCorners: 1
42+
m_Colors: []
12643
m_BuildTextureStacks: []

com.microsoft.mrtk.graphicstools.unity/Runtime/Experimental/Magnifier/Shaders/Magnifier.shader

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Shader "Graphics Tools/Magnifier"
55
{
66
Properties
77
{
8+
[Toggle(_ROUND_CORNERS)] _RoundCorners("Round Corners", Float) = 1.0
9+
_RoundCornerRadius("Round Corner Radius", Float) = 0.05
10+
_RoundCornerMargin("Round Corner Margin", Float) = 0.005
811
}
912
SubShader
1013
{
@@ -17,30 +20,47 @@ Shader "Graphics Tools/Magnifier"
1720
{
1821
"RenderType" = "Transparent"
1922
"Queue" = "Transparent"
23+
"DisableBatching" = "True"
2024
}
2125

2226
Pass
2327
{
2428
ZTest Always
2529
Cull Off
2630
ZWrite Off
31+
Blend SrcAlpha OneMinusSrcAlpha, One One
2732

2833
HLSLPROGRAM
2934
#pragma vertex vert
3035
#pragma fragment frag
3136

37+
#define _URP
38+
#define _TRANSPARENT
39+
#define _EDGE_SMOOTHING_AUTOMATIC
40+
41+
#pragma shader_feature_local _ROUND_CORNERS
42+
3243
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
44+
#include "Packages/com.microsoft.mrtk.graphicstools.unity/Runtime/Shaders/GraphicsToolsCommon.hlsl"
45+
46+
CBUFFER_START(UnityPerMaterial)
47+
float _RoundCornerRadius;
48+
float _RoundCornerMargin;
49+
CBUFFER_END
3350

3451
struct appdata
3552
{
3653
float4 vertex : POSITION;
54+
float2 uv0 : TEXCOORD0;
3755

3856
UNITY_VERTEX_INPUT_INSTANCE_ID
3957
};
4058

4159
struct v2f
4260
{
4361
float4 vertex : SV_POSITION;
62+
float2 uv0 : TEXCOORD0;
63+
float3 scale : TEXCOORD3;
4464

4565
UNITY_VERTEX_OUTPUT_STEREO
4666
};
@@ -63,17 +83,38 @@ Shader "Graphics Tools/Magnifier"
6383
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
6484

6585
o.vertex = TransformObjectToHClip(v.vertex.xyz);
86+
o.uv0 = v.uv0;
87+
o.scale = GTGetWorldScale();
6688

6789
return o;
6890
}
6991

7092
half4 frag(v2f i) : SV_Target
7193
{
94+
// Rounded corner clipping.
95+
#if defined(_ROUND_CORNERS)
96+
half2 distanceToEdge;
97+
distanceToEdge.x = abs(i.uv0.x - 0.5h) * 2.0h;
98+
distanceToEdge.y = abs(i.uv0.y - 0.5h) * 2.0h;
99+
100+
float2 halfScale = i.scale.xy * 0.5;
101+
float2 cornerPosition = distanceToEdge * halfScale;
102+
float cornerCircleRadius = max(_RoundCornerRadius, GT_MIN_CORNER_VALUE);
103+
float2 cornerCircleDistance = halfScale - _RoundCornerMargin - cornerCircleRadius;
104+
float roundCornerClip = GTRoundCorners(cornerPosition, cornerCircleDistance, cornerCircleRadius, 0.0);
105+
#endif // _ROUND_CORNERS
106+
72107
float2 normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(i.vertex);
73108
float2 normalizedScreenSpaceUVStereo = UnityStereoTransformScreenSpaceTex(normalizedScreenSpaceUV);
74109
float2 zoomedUv = ZoomIn(normalizedScreenSpaceUVStereo, MagnifierMagnification, MagnifierCenter.xy);
75110

76-
return SAMPLE_TEXTURE2D_X(MagnifierTexture, samplerMagnifierTexture, zoomedUv);
111+
half4 output = SAMPLE_TEXTURE2D_X(MagnifierTexture, samplerMagnifierTexture, zoomedUv);
112+
113+
#if defined(_ROUND_CORNERS)
114+
output.a = roundCornerClip;
115+
#endif // _ROUND_CORNERS
116+
117+
return output;
77118
}
78119
ENDHLSL
79120
}

com.microsoft.mrtk.graphicstools.unity/Samples~/Magnifier/Magnifier.unity

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ PrefabInstance:
178178
propertyPath: m_Name
179179
value: FlyCamera
180180
objectReference: {fileID: 0}
181+
- target: {fileID: 2605718042319707034, guid: d2eb3a9405371294bb1453b4af85960e, type: 3}
182+
propertyPath: m_ClearFlags
183+
value: 1
184+
objectReference: {fileID: 0}
181185
m_RemovedComponents: []
182186
m_SourcePrefab: {fileID: 100100000, guid: d2eb3a9405371294bb1453b4af85960e, type: 3}
183187
--- !u!20 &473039062 stripped
@@ -228,6 +232,7 @@ MonoBehaviour:
228232
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
229233
m_Name:
230234
m_EditorClassIdentifier:
235+
m_SendPointerHoverToParent: 1
231236
m_MoveRepeatDelay: 0.5
232237
m_MoveRepeatRate: 0.1
233238
m_XRTrackingOrigin: {fileID: 0}
@@ -244,6 +249,7 @@ MonoBehaviour:
244249
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
245250
m_DeselectOnBackgroundClick: 1
246251
m_PointerBehavior: 0
252+
m_CursorLockBehavior: 0
247253
--- !u!114 &551594404
248254
MonoBehaviour:
249255
m_ObjectHideFlags: 0
@@ -269,6 +275,7 @@ Transform:
269275
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
270276
m_LocalPosition: {x: 0, y: 0, z: 0}
271277
m_LocalScale: {x: 1, y: 1, z: 1}
278+
m_ConstrainProportionsScale: 0
272279
m_Children: []
273280
m_Father: {fileID: 0}
274281
m_RootOrder: 2
@@ -299,6 +306,7 @@ Transform:
299306
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
300307
m_LocalPosition: {x: 0, y: 1, z: 0}
301308
m_LocalScale: {x: 1, y: 1, z: 1}
309+
m_ConstrainProportionsScale: 0
302310
m_Children:
303311
- {fileID: 1298507361}
304312
- {fileID: 1522697104}
@@ -341,7 +349,14 @@ MonoBehaviour:
341349
m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3}
342350
m_Name:
343351
m_EditorClassIdentifier:
352+
m_Version: 1
344353
m_UsePipelineSettings: 1
354+
m_AdditionalLightsShadowResolutionTier: 2
355+
m_LightLayerMask: 1
356+
m_CustomShadowLayers: 0
357+
m_ShadowLayerMask: 1
358+
m_LightCookieSize: {x: 1, y: 1}
359+
m_LightCookieOffset: {x: 0, y: 0}
345360
--- !u!108 &957735293
346361
Light:
347362
m_ObjectHideFlags: 0
@@ -414,6 +429,7 @@ Transform:
414429
m_LocalRotation: {x: 0.40821788, y: 0.23456976, z: -0.10938167, w: 0.8754261}
415430
m_LocalPosition: {x: 0, y: 3, z: 0}
416431
m_LocalScale: {x: 1, y: 1, z: 1}
432+
m_ConstrainProportionsScale: 0
417433
m_Children: []
418434
m_Father: {fileID: 0}
419435
m_RootOrder: 3
@@ -582,6 +598,7 @@ MeshRenderer:
582598
m_CastShadows: 1
583599
m_ReceiveShadows: 1
584600
m_DynamicOccludee: 1
601+
m_StaticShadowCaster: 0
585602
m_MotionVectors: 1
586603
m_LightProbeUsage: 1
587604
m_ReflectionProbeUsage: 1
@@ -630,6 +647,7 @@ Transform:
630647
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
631648
m_LocalPosition: {x: 0, y: 0, z: 1}
632649
m_LocalScale: {x: 0.44704, y: 0.5588, z: 1}
650+
m_ConstrainProportionsScale: 0
633651
m_Children: []
634652
m_Father: {fileID: 656687269}
635653
m_RootOrder: 1
@@ -727,7 +745,8 @@ Transform:
727745
m_GameObject: {fileID: 1837192617}
728746
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
729747
m_LocalPosition: {x: 0, y: 0, z: 0}
730-
m_LocalScale: {x: 1.05, y: 1.1, z: 1}
748+
m_LocalScale: {x: 1, y: 1, z: 1}
749+
m_ConstrainProportionsScale: 0
731750
m_Children: []
732751
m_Father: {fileID: 2055136616}
733752
m_RootOrder: 0
@@ -743,6 +762,7 @@ MeshRenderer:
743762
m_CastShadows: 1
744763
m_ReceiveShadows: 1
745764
m_DynamicOccludee: 1
765+
m_StaticShadowCaster: 0
746766
m_MotionVectors: 1
747767
m_LightProbeUsage: 1
748768
m_ReflectionProbeUsage: 1
@@ -808,8 +828,9 @@ Transform:
808828
m_PrefabAsset: {fileID: 0}
809829
m_GameObject: {fileID: 2055136615}
810830
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
811-
m_LocalPosition: {x: 0, y: -0.2, z: 1.3}
812-
m_LocalScale: {x: 0.8, y: 0.4, z: 1}
831+
m_LocalPosition: {x: 0, y: 0, z: 1.3}
832+
m_LocalScale: {x: 1, y: 0.6, z: 1}
833+
m_ConstrainProportionsScale: 0
813834
m_Children:
814835
- {fileID: 1837192618}
815836
m_Father: {fileID: 691126601}
@@ -830,6 +851,10 @@ MonoBehaviour:
830851
magnification: 0.7
831852
magnificationPropertyName: MagnifierMagnification
832853
rendererIndex: 0
854+
AutoAddDrawFullscreenFeature: 1
855+
inLensMode: 0
856+
targetDrawFullscreenFeatureName:
857+
targetDrawFullscreenFeatureAddMode: 0
833858
drawFullscreenSettings:
834859
renderPassEvent: 500
835860
BlitMaterial: {fileID: 2100000, guid: aee43c1cf28a72e48ae850053692e23e, type: 2}
@@ -839,7 +864,11 @@ MonoBehaviour:
839864
DestinationType: 1
840865
SourceTextureId:
841866
DestinationTextureId: MagnifierTexture
867+
FilterMode: 1
842868
RestoreCameraColorTarget: 1
869+
AutoAddRenderObjectsFeature: 1
870+
targetDrawObjectsFeatureName:
871+
targetDrawObjectsFeatureAddMode: 0
843872
renderObjectsSettings:
844873
passTag:
845874
Event: 500
@@ -878,6 +907,7 @@ MeshRenderer:
878907
m_CastShadows: 1
879908
m_ReceiveShadows: 1
880909
m_DynamicOccludee: 1
910+
m_StaticShadowCaster: 0
881911
m_MotionVectors: 1
882912
m_LightProbeUsage: 1
883913
m_ReflectionProbeUsage: 1

0 commit comments

Comments
 (0)