Skip to content

Commit

Permalink
displacement shader
Browse files Browse the repository at this point in the history
  • Loading branch information
nomand committed Jun 18, 2018
1 parent 5e246d6 commit 5c3432b
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 6 deletions.
89 changes: 89 additions & 0 deletions Assets/Runningtap/Reveal/Materials/Displacement.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
%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: Displacement
m_Shader: {fileID: 4800000, guid: 3f813ef63d6c1ef4ab60b3c391d9990d, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DispTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: d00dc0188602a864c8716d3c78d72645, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Splat:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _Displacement: -0.339
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Tess: 4
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color2: {r: 0.39061943, g: 0.50041425, b: 0.6226415, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SplatLocation: {r: 0, g: 0, b: 0, a: 0}
- _SplatRemap: {r: 0, g: 0, b: 0, a: 0}
10 changes: 10 additions & 0 deletions Assets/Runningtap/Reveal/Materials/Displacement.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions Assets/Runningtap/Reveal/Scenes/RevealShader.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
Expand All @@ -39,6 +39,7 @@ RenderSettings:
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand All @@ -54,11 +55,10 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
Expand Down Expand Up @@ -144,8 +144,9 @@ MeshRenderer:
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: fc6c9097488e0734bbc8da974cd62ff1, type: 2}
- {fileID: 2100000, guid: 70f4b7e2e6537ab4c88f1196a6a30210, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
Expand Down Expand Up @@ -403,6 +404,7 @@ MeshRenderer:
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 2100000, guid: 61b5e6802a134c1449f3cf61c0294acd, type: 2}
m_StaticBatchInfo:
Expand Down Expand Up @@ -528,6 +530,7 @@ MeshRenderer:
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 4294967295
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
Expand Down
48 changes: 48 additions & 0 deletions Assets/Runningtap/Reveal/Shaders/NewSurfaceShader.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Shader "Custom/NewSurfaceShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

sampler2D _MainTex;

struct Input {
float2 uv_MainTex;
};

half _Glossiness;
half _Metallic;
fixed4 _Color;

// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)

void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
9 changes: 9 additions & 0 deletions Assets/Runningtap/Reveal/Shaders/NewSurfaceShader.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions Assets/Runningtap/Reveal/Shaders/RevealDisplacement.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'

Shader "Runningtap/Reveal/Displacement" {
Properties
{
_Tess ("Tessellation", Range(1,32)) = 4
_Displacement ("Displacement", Range(-1.0, 1.0)) = 0.3
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Color2 ("Color2", Color) = (1,1,1,1)
_Splat ("SplatMap", 2D) = "black" {}
_SplatRemap ("SplatOffset", Vector) = (0,0,0,0)
}

SubShader
{
Tags { "RenderType"="Opaque" }
LOD 300

CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:disp tessellate:tessDistance
#pragma target 4.6
#include "Tessellation.cginc"

struct appdata
{
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
};

struct Input
{
float2 uv_MainTex;
float3 worldPos;
};

UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(sampler2D, _MainTex)
UNITY_DEFINE_INSTANCED_PROP(sampler2D, _Splat)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color2)
UNITY_DEFINE_INSTANCED_PROP(float4, _SplatRemap)
UNITY_DEFINE_INSTANCED_PROP(half, _Tess)
UNITY_DEFINE_INSTANCED_PROP(half, _Displacement )
UNITY_INSTANCING_BUFFER_END(Props)

void disp (inout appdata v)
{
float2 WUV = (mul (unity_ObjectToWorld, v.vertex).xz - _SplatRemap.xy)/ _SplatRemap.zw;

float d = tex2Dlod(_Splat, float4(WUV, 0, 0)).r * _Displacement;
v.vertex.xyz += v.normal * d;
}

float4 tessDistance (appdata v0, appdata v1, appdata v2)
{
float minDist = 10.0;
float maxDist = 50.0;
return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, minDist, maxDist, _Tess);
}

void surf (Input IN, inout SurfaceOutputStandard o)
{
float2 WUV = (IN.worldPos.xz - _SplatRemap.xy)/ _SplatRemap.zw;

half mask = tex2Dlod(_Splat, float4(WUV, 0, 0)).r;
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed4 c2 = tex2D(_MainTex, IN.uv_MainTex) * _Color2;

float4 mix = lerp(c, c2, mask);
//o.Alpha = saturate(mix);
o.Albedo = mix.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added PREVIEW/02.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dependencies": {
}
}
6 changes: 6 additions & 0 deletions ProjectSettings/PresetManager.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1386491679 &1
PresetManager:
m_ObjectHideFlags: 0
m_DefaultList: []
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2017.3.0f3
m_EditorVersion: 2018.1.1f1
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ This is a set of shaders for Unity3D. It maps worldspace position of a gameObjec
### Features:
* Black and White to RGB texture reveal shader
* Transparent to Opaque RGB Texture reveal shader
* Displacement Tesselation shader
* Auto and Manual world bounds lookup
* Fading over time
* Adaptive RenderTexture aspect ratio
* Custom inpspector

The RenderTexture mask generation and re-projection happens separately from the surface shaders, so any combination of them is possible and adding new shaders is trivial without affecting the setup.

<img src='/PREVIEW/02.gif'/>

### Download
Download the `UnityPackage` from [Releases](/Releases) to get a clean import.

Expand Down

0 comments on commit 5c3432b

Please sign in to comment.