Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from pinkwerks/master
Add HoloShell like shader for rendering spatial mesh on air tap #335
- Loading branch information
Showing
7 changed files
with
691 additions
and
0 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
Assets/HoloToolkit/SpatialMapping/Materials/SpatialMappingTap.mat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 6 | ||
m_ObjectHideFlags: 0 | ||
m_PrefabParentObject: {fileID: 0} | ||
m_PrefabInternal: {fileID: 0} | ||
m_Name: SpatialMappingTap | ||
m_Shader: {fileID: 4800000, guid: 23beda61782381042848d512379b9e11, type: 3} | ||
m_ShaderKeywords: _EMISSION _USEWIREFRAME_ON | ||
m_LightmapFlags: 1 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
m_SavedProperties: | ||
serializedVersion: 2 | ||
m_TexEnvs: | ||
- first: | ||
name: _BumpMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _DetailAlbedoMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _DetailMask | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _DetailNormalMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _EmissionMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _MainTex | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _MetallicGlossMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _OcclusionMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- first: | ||
name: _ParallaxMap | ||
second: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Floats: | ||
- first: | ||
name: _BumpScale | ||
second: 1 | ||
- first: | ||
name: _Cutoff | ||
second: 0.5 | ||
- first: | ||
name: _DetailNormalMapScale | ||
second: 1 | ||
- first: | ||
name: _DstBlend | ||
second: 0 | ||
- first: | ||
name: _GlossMapScale | ||
second: 1 | ||
- first: | ||
name: _Glossiness | ||
second: 0.5 | ||
- first: | ||
name: _GlossyReflections | ||
second: 1 | ||
- first: | ||
name: _Metallic | ||
second: 0 | ||
- first: | ||
name: _Mode | ||
second: 0 | ||
- first: | ||
name: _OcclusionStrength | ||
second: 1 | ||
- first: | ||
name: _Parallax | ||
second: 0.02 | ||
- first: | ||
name: _PulseWidth | ||
second: 0.99 | ||
- first: | ||
name: _Radius | ||
second: 4.55 | ||
- first: | ||
name: _SmoothnessTextureChannel | ||
second: 0 | ||
- first: | ||
name: _SpecularHighlights | ||
second: 1 | ||
- first: | ||
name: _SrcBlend | ||
second: 1 | ||
- first: | ||
name: _UVSec | ||
second: 0 | ||
- first: | ||
name: _UseWireframe | ||
second: 1 | ||
- first: | ||
name: _WireframeFill | ||
second: 0.13 | ||
- first: | ||
name: _WireframeThick | ||
second: 0 | ||
- first: | ||
name: _ZWrite | ||
second: 1 | ||
m_Colors: | ||
- first: | ||
name: _Center | ||
second: {r: 0, g: 0, b: 0, a: -1} | ||
- first: | ||
name: _Color | ||
second: {r: 1, g: 1, b: 1, a: 1} | ||
- first: | ||
name: _EmissionColor | ||
second: {r: 0, g: 0, b: 0, a: 1} | ||
- first: | ||
name: _PulseColor | ||
second: {r: 0.6544118, g: 0.7887331, b: 1, a: 1} | ||
- first: | ||
name: _WireframeColor | ||
second: {r: 0.5514706, g: 0.20274653, b: 0.20274653, a: 1} |
8 changes: 8 additions & 0 deletions
8
Assets/HoloToolkit/SpatialMapping/Materials/SpatialMappingTap.mat.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
Assets/HoloToolkit/SpatialMapping/Shaders/SpatialMappingTap.shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
Shader "Spatial Mapping/Spatial Mappping Tap" | ||
{ | ||
Properties | ||
{ | ||
// Main knobs | ||
_Center ("Center", Vector) = (0, 0, 0, -1) // world space position | ||
_Radius ("Radius", Range(0, 10)) = 1 // grows the pulse | ||
|
||
// Pulse knobs | ||
_PulseColor ("Pulse Color", Color) = (.145, .447, .922) | ||
_PulseWidth ("Pulse Width", Float) = 1 | ||
|
||
// Wireframe knobs | ||
[MaterialToggle] _UseWireframe ("Use Wireframe", Int) = 1 | ||
_WireframeColor ("Wireframe Color", Color) = (.5, .5, .5) | ||
_WireframeFill ("Wireframe Fill", Range(0, 1)) = .1 | ||
} | ||
|
||
SubShader | ||
{ | ||
Tags { "RenderType" = "Opaque" } | ||
|
||
Pass | ||
{ | ||
Offset 50, 100 | ||
|
||
CGPROGRAM | ||
|
||
#pragma vertex vert | ||
#pragma geometry geom | ||
#pragma fragment frag | ||
|
||
#include "UnityCG.cginc" | ||
|
||
half _Radius; | ||
half3 _Center; | ||
half3 _PulseColor; | ||
half _PulseWidth; | ||
half3 _WireframeColor; | ||
half _WireframeFill; | ||
int _UseWireframe; | ||
|
||
// http://www.iquilezles.org/www/articles/functions/functions.htm | ||
half cubicPulse(half c, half w, half x) | ||
{ | ||
x = abs(x - c); | ||
if ( x > w ) | ||
return 0; | ||
x /= w; | ||
return 1 - x * x * (3 - 2 * x); | ||
} | ||
|
||
struct v2g | ||
{ | ||
half4 viewPos : SV_POSITION; | ||
half pulse : COLOR; | ||
}; | ||
|
||
v2g vert(appdata_base v) | ||
{ | ||
v2g o; | ||
|
||
o.viewPos = mul(UNITY_MATRIX_MVP, v.vertex); | ||
|
||
float4 worldPos = mul(unity_ObjectToWorld, v.vertex); | ||
half distToCenter = distance(_Center, worldPos.xyz); | ||
half pulse = cubicPulse(_Radius, _PulseWidth, distToCenter); | ||
|
||
o.pulse = pulse; | ||
|
||
return o; | ||
} | ||
|
||
struct g2f | ||
{ | ||
float4 viewPos : SV_POSITION; | ||
half3 bary : COLOR; | ||
half pulse : COLOR1; | ||
}; | ||
|
||
[maxvertexcount(3)] | ||
void geom(triangle v2g i[3], inout TriangleStream<g2f> triStream) | ||
{ | ||
// For wireframe | ||
half3 barys[3] = { | ||
half3(1, 0, 0), | ||
half3(0, 1, 0), | ||
half3(0, 0, 1) | ||
}; | ||
|
||
g2f o; | ||
|
||
[unroll] | ||
for (uint idx = 0; idx < 3; ++idx) | ||
{ | ||
o.viewPos = i[idx].viewPos; | ||
o.bary = barys[idx]; | ||
o.pulse = i[idx].pulse; | ||
triStream.Append(o); | ||
} | ||
} | ||
|
||
half4 frag(g2f i) : COLOR | ||
{ | ||
half3 result = i.pulse * _PulseColor; | ||
|
||
if (!_UseWireframe) | ||
return half4(result, 1); | ||
|
||
half triBary = min( min(i.bary.x, i.bary.y), i.bary.z) * 3; | ||
half fwt = fwidth(triBary); | ||
half w = smoothstep(fwt, 0, triBary - _WireframeFill); | ||
|
||
result += w * _WireframeColor * i.pulse; | ||
|
||
return half4(result, 1); | ||
} | ||
|
||
ENDCG | ||
} | ||
} | ||
|
||
FallBack "Diffuse" | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
Assets/HoloToolkit/SpatialMapping/Shaders/SpatialMappingTap.shader.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.