Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Update supporting scripts - 0.11.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
kircher1 committed Jun 2, 2021
1 parent 745823a commit e591843
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 49 deletions.
12 changes: 8 additions & 4 deletions SupportingScripts/Editor/Scripts/MapRendererEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ internal class MapRendererEditor : Editor
private SerializedProperty _mapEdgeColorProperty;
private SerializedProperty _mapEdgeColorFadeDistanceProperty;
private SerializedProperty _clippingVolumeMaterialProperty;
private SerializedProperty _clippingVolumeDistanceTextureResolution;
private SerializedProperty _clippingVolumeDistanceTextureResolutionProperty;
private SerializedProperty _clippingDistanceLayerProperty;

private static bool _showQualityOptions = true;
private SerializedProperty _detailOffsetProperty;
Expand Down Expand Up @@ -127,7 +128,8 @@ private void OnEnable()
_terrainMaterialProperty = serializedObject.FindProperty("_terrainMaterial");
_isClippingVolumeWallEnabledProperty = serializedObject.FindProperty("_isClippingVolumeWallEnabled");
_clippingVolumeMaterialProperty = serializedObject.FindProperty("_clippingVolumeMaterial");
_clippingVolumeDistanceTextureResolution = serializedObject.FindProperty("_clippingVolumeDistanceTextureResolution");
_clippingVolumeDistanceTextureResolutionProperty = serializedObject.FindProperty("_clippingVolumeDistanceTextureResolution");
_clippingDistanceLayerProperty = serializedObject.FindProperty("_clippingDistanceLayer");
_mapEdgeColorProperty = serializedObject.FindProperty("_mapEdgeColor");
_mapEdgeColorFadeDistanceProperty = serializedObject.FindProperty("_mapEdgeColorFadeDistance");
_detailOffsetProperty = serializedObject.FindProperty("_detailOffset");
Expand Down Expand Up @@ -403,10 +405,12 @@ public override void OnInspectorGUI()
// Texture Camera Resolution
GUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Clipping Edge Resolution");
_clippingVolumeDistanceTextureResolution.enumValueIndex = GUILayout.Toolbar(
_clippingVolumeDistanceTextureResolution.enumValueIndex, _clippingVolumeDistanceTextureResolutionOptions);
_clippingVolumeDistanceTextureResolutionProperty.enumValueIndex = GUILayout.Toolbar(
_clippingVolumeDistanceTextureResolutionProperty.enumValueIndex, _clippingVolumeDistanceTextureResolutionOptions);
GUILayout.EndHorizontal();

EditorGUILayout.PropertyField(_clippingDistanceLayerProperty);

EditorGUI.indentLevel--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ Shader "Maps SDK/Clipping Distance"
}

// Writes the linear, normalized depth of the pixel to the render texture.
#if SHADER_API_GLES
// Cannot return float directly in GLES API because float to fixed4 conversion fails.
fixed4 frag(v2f i) : SV_Target
#if SHADER_API_GLES || SHADER_API_METAL
// Cannot return float directly in GLES API because float to float4 conversion fails.
float4 frag(v2f i) : SV_Target
{
#if UNITY_REVERSED_Z
return 1 - i.pos.zzzz;
return float4(1, 1, 1, 1) - i.pos.zzzz;
#else
return i.pos.zzzz;
#endif
Expand All @@ -77,4 +77,4 @@ Shader "Maps SDK/Clipping Distance"
ENDCG
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
float3 _ClippingVolumePosition;
float4 _ClippingVolumeNormals[2];
float3 _ClippingVolumeUp;
fixed4 _ClippingVolumeColor;
float4 _ClippingVolumeColor;
float3 _ClippingVolumeSize;
float _ClippingVolumeFadeDistance;

Expand Down
6 changes: 3 additions & 3 deletions SupportingScripts/Runtime/Shaders/ContourLines-MapsSDK.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#if ENABLE_CONTOUR_LINES

// Assumes premultiplied alpha for colors.
fixed4 _MajorContourLineColor;
fixed4 _MinorContourLineColor;
half4 _MajorContourLineColor;
half4 _MinorContourLineColor;
float _HalfMajorContourLinePixelSize;
float _HalfMinorContourLinePixelSize;
float _NumMinorContourIntervalSections;
float _MinorContourLineIntervalInMeters;

fixed4 ApplyContourLines(fixed4 color, float elevation /* in meters */)
half4 ApplyContourLines(half4 color, float elevation /* in meters */)
{
// Compute the opacity of the contour line.
float changeInIntervalForOnePixel = fwidth(elevation / _MinorContourLineIntervalInMeters);
Expand Down
12 changes: 6 additions & 6 deletions SupportingScripts/Runtime/Shaders/MRTKIntegration-MapsSDK.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ inline float HoverLight(float4 hoverLight, float inverseRadius, float3 worldPosi
return (1.0 - saturate(length(hoverLight.xyz - worldPosition) * inverseRadius)) * hoverLight.w;
}

inline fixed4 ApplyHoverLight(float3 worldPosition, fixed4 color)
inline half4 ApplyHoverLight(float3 worldPosition, half4 color)
{
fixed pointToLight = 0.0;
fixed3 fluentLightColor = fixed3(0.0, 0.0, 0.0);
half pointToLight = 0.0;
half3 fluentLightColor = half3(0.0, 0.0, 0.0);

[unroll]
for (int hoverLightIndex = 0; hoverLightIndex < HOVER_LIGHT_COUNT; ++hoverLightIndex)
{
int dataIndex = hoverLightIndex * HOVER_LIGHT_DATA_SIZE;
fixed hoverValue = HoverLight(_HoverLightData[dataIndex], _HoverLightData[dataIndex + 1].w, worldPosition);
half hoverValue = HoverLight(_HoverLightData[dataIndex], _HoverLightData[dataIndex + 1].w, worldPosition);
pointToLight += hoverValue;
fluentLightColor += lerp(fixed3(0.0, 0.0, 0.0), _HoverLightData[dataIndex + 1].rgb, hoverValue);
fluentLightColor += lerp(half3(0.0, 0.0, 0.0), _HoverLightData[dataIndex + 1].rgb, hoverValue);
}

color.rgb += fluentLightColor * pointToLight;
Expand All @@ -34,7 +34,7 @@ inline fixed4 ApplyHoverLight(float3 worldPosition, fixed4 color)

#else

inline fixed4 ApplyHoverLight(float3 worldPosition, fixed4 color)
inline half4 ApplyHoverLight(float3 worldPosition, half4 color)
{
return color;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ Shader "Maps SDK/Standard Clipping Volume"
#include "ClippingVolume-MapsSDK.cginc"
#include "MRTKIntegration-MapsSDK.cginc"

sampler2D _TerrainDistanceTex;
float2 _MapDimension;
float4x4 _WorldToDistanceCameraMatrix;
float _MapCurrentHeight;

struct appdata
{
float3 vertex : POSITION;
Expand All @@ -49,7 +44,6 @@ Shader "Maps SDK/Standard Clipping Volume"
#if ENABLE_MRTK_INTEGRATION
float3 worldPosition : POSITION2;
#endif
float2 texcoord : TEXCOORD0;
float3 normal : NORMAL;

SHADOW_COORDS(1)
Expand All @@ -58,6 +52,11 @@ Shader "Maps SDK/Standard Clipping Volume"
UNITY_VERTEX_OUTPUT_STEREO
};

sampler2D _TerrainDistanceTex;
float2 _MapDimension;
float4x4 _WorldToDistanceCameraMatrix;
float _MapCurrentHeight;

v2f vert(appdata v)
{
UNITY_SETUP_INSTANCE_ID(v);
Expand All @@ -72,10 +71,10 @@ Shader "Maps SDK/Standard Clipping Volume"
#if ENABLE_MRTK_INTEGRATION
o.worldPosition = worldPosition;
#endif
o.cameraPosition = mul(_WorldToDistanceCameraMatrix, float4(worldPosition, 1.0));
o.cameraPosition = mul(_WorldToDistanceCameraMatrix, float4(worldPosition, 1.0)).xyz;

o.normal = UnityObjectToWorldNormal(v.normal);

TRANSFER_SHADOW(o);
UNITY_TRANSFER_FOG(o, o.pos);

Expand Down Expand Up @@ -140,7 +139,6 @@ Shader "Maps SDK/Standard Clipping Volume"
struct appdata
{
float4 vertex : POSITION;
float2 uv: TEXCOORD;
float3 normal : NORMAL;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Expand Down Expand Up @@ -184,4 +182,4 @@ Shader "Maps SDK/Standard Clipping Volume"
ENDCG
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

Shader "Maps SDK/Standard Terrain"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex0("Albedo (RGB)", 2D) = "white" {}
_MainTex1("Color", Color) = (1,1,1,1)
_MainTex2("Color", Color) = (1,1,1,1)
_MainTex3("Color", Color) = (1,1,1,1)
}

SubShader
{
Pass
Expand Down Expand Up @@ -83,7 +74,6 @@ Shader "Maps SDK/Standard Terrain"
UNITY_SETUP_INSTANCE_ID(v);

v2f o;

UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

Expand All @@ -104,10 +94,10 @@ Shader "Maps SDK/Standard Terrain"
#endif

o.pos = UnityObjectToClipPos(v.vertex);
if (_MainTexCount > 0) { o.uv = _TexScaleAndOffset[0].x * v.uv + _TexScaleAndOffset[0].yz; }
if (_MainTexCount > 1) { o.uv2 = _TexScaleAndOffset[1].x * v.uv + _TexScaleAndOffset[1].yz; }
if (_MainTexCount > 2) { o.uv3 = _TexScaleAndOffset[2].x * v.uv + _TexScaleAndOffset[2].yz; }
if (_MainTexCount > 3) { o.uv4 = _TexScaleAndOffset[3].x * v.uv + _TexScaleAndOffset[3].yz; }
if (_MainTexCount > 0) { o.uv = _TexScaleAndOffset[0].x * v.uv.xy + _TexScaleAndOffset[0].yz; }
if (_MainTexCount > 1) { o.uv2 = _TexScaleAndOffset[1].x * v.uv.xy + _TexScaleAndOffset[1].yz; }
if (_MainTexCount > 2) { o.uv3 = _TexScaleAndOffset[2].x * v.uv.xy + _TexScaleAndOffset[2].yz; }
if (_MainTexCount > 3) { o.uv4 = _TexScaleAndOffset[3].x * v.uv.xy + _TexScaleAndOffset[3].yz; }

float3 worldPosition = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1.0)).xyz;
o.worldPosition = worldPosition;
Expand Down Expand Up @@ -136,7 +126,6 @@ Shader "Maps SDK/Standard Terrain"
if (_MainTexCount > 1) { color = blend(color, tex2D(_MainTex1, i.uv2)); }
if (_MainTexCount > 2) { color = blend(color, tex2D(_MainTex2, i.uv3)); }
if (_MainTexCount > 3) { color = blend(color, tex2D(_MainTex3, i.uv4)); }
color *= _Color;

// Apply contours.
#if ENABLE_ELEVATION_TEXTURE && ENABLE_CONTOUR_LINES
Expand Down Expand Up @@ -204,6 +193,13 @@ Shader "Maps SDK/Standard Terrain"
{
UNITY_SETUP_INSTANCE_ID(v);

v2f o;
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

// Extract skirt indicator from the third item in uv
o.isSkirt = v.uv.z;

#if ENABLE_ELEVATION_TEXTURE
float elevationOffset =
CalculateElevationOffset(
Expand All @@ -214,12 +210,8 @@ Shader "Maps SDK/Standard Terrain"
v.vertex.y += elevationOffset;
#endif

v2f o;
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);

float3 worldPosition = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1.0)).xyz;
o.worldPosition = worldPosition;
o.isSkirt = v.uv.z;

TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)

Expand Down
2 changes: 1 addition & 1 deletion SupportingScripts/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.2
0.11.0

0 comments on commit e591843

Please sign in to comment.