This commit is contained in:
2025-09-17 18:56:28 +08:00
commit 54c72710a5
5244 changed files with 5717609 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/ColorCorrectionCurves" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
_ZCurve ("_ZCurve (RGB)", 2D) = "" {}
_RgbDepthTex ("_RgbDepthTex (RGB)", 2D) = "" {}
}
// note: also have a look at ColorCorrectionCurvesSimple
// for a much simpler color correction without use of
// depth texture lookups
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
sampler2D _MainTex;
sampler2D_float _CameraDepthTexture;
float4 _CameraDepthTexture_ST;
uniform float4 _MainTex_TexelSize;
sampler2D _RgbTex;
sampler2D _ZCurve;
sampler2D _RgbDepthTex;
fixed _Saturation;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
o.uv2 = TRANSFORM_TEX(v.texcoord, _CameraDepthTexture);
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
o.uv2.y = 1-o.uv2.y;
#endif
return o;
}
half4 frag(v2f i) : SV_Target
{
half4 color = tex2D(_MainTex, i.uv);
half3 ycoords = half3(0.5,1.5,2.5) * 0.25;
half3 red = tex2D(_RgbTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
half3 green = tex2D(_RgbTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
half3 blue = tex2D(_RgbTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
half theDepth = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, i.uv2) ;
half zval = tex2D(_ZCurve, half2( Linear01Depth (theDepth), 0.5));
half3 depthRed = tex2D(_RgbDepthTex, half2(color.r, ycoords.x)).rgb * half3(1,0,0);
half3 depthGreen = tex2D(_RgbDepthTex, half2(color.g, ycoords.y)).rgb * half3(0,1,0);
half3 depthBlue = tex2D(_RgbDepthTex, half2(color.b, ycoords.z)).rgb * half3(0,0,1);
color = half4( lerp(red+green+blue, depthRed+depthBlue+depthGreen, zval), color.a);
half lum = Luminance(color.rgb);
color.rgb = lerp(half3(lum,lum,lum), color.rgb, _Saturation);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 17cf6c37245c91f4c8558d41a5d036f6
ShaderImporter:
userData:

View File

@@ -0,0 +1,61 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/ColorCorrectionCurvesSimple" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
_RgbTex ("_RgbTex (RGB)", 2D) = "" {}
}
// Shader code pasted into all further CGPROGRAM blocks
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _RgbTex;
fixed _Saturation;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 color = tex2D(_MainTex, i.uv);
fixed3 red = tex2D(_RgbTex, half2(color.r, 0.5/4.0)).rgb * fixed3(1,0,0);
fixed3 green = tex2D(_RgbTex, half2(color.g, 1.5/4.0)).rgb * fixed3(0,1,0);
fixed3 blue = tex2D(_RgbTex, half2(color.b, 2.5/4.0)).rgb * fixed3(0,0,1);
color = fixed4(red+green+blue, color.a);
fixed lum = Luminance(color.rgb);
color.rgb = lerp(fixed3(lum,lum,lum), color.rgb, _Saturation);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: ffe57cb28bfde20438c139cf8e0fbb74
ShaderImporter:
userData:

View File

@@ -0,0 +1,54 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/ColorCorrectionSelective" {
Properties {
_MainTex ("Base (RGB)", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 selColor;
float4 targetColor;
v2f vert( appdata_img v ) {
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = v.texcoord.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target {
fixed4 color = tex2D (_MainTex, i.uv);
fixed diff = saturate (2.0 * length (color.rgb - selColor.rgb));
color = lerp (targetColor, color, diff);
return color;
}
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 7c0c05f3dac46df4697e06f7ff7b16ce
ShaderImporter:
userData:

View File

@@ -0,0 +1,233 @@
// Shader created with Shader Forge v1.38
// Shader Forge (c) Freya Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:Legacy Shaders/Bumped Diffuse,iptp:0,cusa:False,bamd:0,cgin:,lico:0,lgpr:1,limd:1,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:True,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:True,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.4705882,fgcg:0.4509804,fgcb:0.3490196,fgca:1,fgde:0.005,fgrn:0,fgrf:0.01,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:4013,x:33720,y:32841,varname:node_4013,prsc:2|diff-9285-OUT,normal-7351-OUT;n:type:ShaderForge.SFN_Tex2d,id:8555,x:32419,y:32886,ptovrint:False,ptlb:DetailAlbedo,ptin:_DetailAlbedo,varname:_DetailAlbedo,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:c9f56c646bacaf94fa7cbb00c69f0c2a,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:24,x:32417,y:33068,ptovrint:False,ptlb:DetailNormal,ptin:_DetailNormal,varname:_DetailNormal,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:2c3560939cb013f479c187b25ab669f0,ntxv:3,isnm:True;n:type:ShaderForge.SFN_Tex2d,id:4206,x:32417,y:33253,ptovrint:False,ptlb:DetailMask,ptin:_DetailMask,varname:_DetailMask,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:3490e62b39635344fa005d902a24d679,ntxv:2,isnm:False;n:type:ShaderForge.SFN_Tex2d,id:3249,x:32416,y:32523,ptovrint:False,ptlb:MainTex,ptin:_MainTex,varname:_MainTex,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:b7e106a25ba8c7c4198888b4ed65fdc7,ntxv:0,isnm:False;n:type:ShaderForge.SFN_OneMinus,id:6715,x:32608,y:32886,varname:node_6715,prsc:2|IN-8555-RGB;n:type:ShaderForge.SFN_Vector1,id:6250,x:32417,y:33411,varname:node_6250,prsc:2,v1:1;n:type:ShaderForge.SFN_Vector1,id:9515,x:32417,y:33467,varname:node_9515,prsc:2,v1:0.5;n:type:ShaderForge.SFN_OneMinus,id:4699,x:32596,y:33253,varname:node_4699,prsc:2|IN-4206-RGB;n:type:ShaderForge.SFN_Vector1,id:9328,x:32417,y:33519,varname:node_9328,prsc:2,v1:0;n:type:ShaderForge.SFN_Append,id:6034,x:33171,y:33270,varname:node_6034,prsc:2|A-3519-OUT,B-6250-OUT;n:type:ShaderForge.SFN_ComponentMask,id:3519,x:32982,y:33270,varname:node_3519,prsc:2,cc1:0,cc2:1,cc3:-1,cc4:-1|IN-4569-OUT;n:type:ShaderForge.SFN_Lerp,id:4569,x:32803,y:33270,varname:node_4569,prsc:2|A-24-RGB,B-9328-OUT,T-4699-OUT;n:type:ShaderForge.SFN_Tex2d,id:7352,x:32416,y:32704,ptovrint:False,ptlb:BumpMap,ptin:_BumpMap,varname:_BumpMap,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,tex:d01c515efeed30b4cb7b6a631164cbb2,ntxv:3,isnm:True;n:type:ShaderForge.SFN_NormalBlend,id:7351,x:33373,y:33250,varname:node_7351,prsc:2|BSE-7352-RGB,DTL-6034-OUT;n:type:ShaderForge.SFN_RemapRange,id:5482,x:32778,y:32886,varname:node_5482,prsc:2,frmn:0.5,frmx:1,tomn:-1,tomx:1|IN-6715-OUT;n:type:ShaderForge.SFN_OneMinus,id:5086,x:32955,y:32886,varname:node_5086,prsc:2|IN-5482-OUT;n:type:ShaderForge.SFN_Blend,id:8019,x:33156,y:32804,varname:node_8019,prsc:2,blmd:0,clmp:True|SRC-5086-OUT,DST-3249-RGB;n:type:ShaderForge.SFN_Lerp,id:9285,x:33396,y:32867,varname:node_9285,prsc:2|A-8019-OUT,B-3249-RGB,T-4699-OUT;proporder:3249-7352-8555-24-4206;pass:END;sub:END;*/
Shader "Shader Forge/DestroyIt Mobile" {
Properties {
_MainTex ("MainTex", 2D) = "white" {}
_BumpMap ("BumpMap", 2D) = "bump" {}
_DetailAlbedo ("DetailAlbedo", 2D) = "white" {}
_DetailNormal ("DetailNormal", 2D) = "bump" {}
_DetailMask ("DetailMask", 2D) = "black" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
}
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles ps4
#pragma target 3.0
uniform sampler2D _DetailAlbedo; uniform float4 _DetailAlbedo_ST;
uniform sampler2D _DetailNormal; uniform float4 _DetailNormal_ST;
uniform sampler2D _DetailMask; uniform float4 _DetailMask_ST;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform sampler2D _BumpMap; uniform float4 _BumpMap_ST;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float3 normalDir : TEXCOORD4;
float3 tangentDir : TEXCOORD5;
float3 bitangentDir : TEXCOORD6;
LIGHTING_COORDS(7,8)
UNITY_FOG_COORDS(9)
#if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
float4 ambientOrLightmapUV : TEXCOORD10;
#endif
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
#ifdef LIGHTMAP_ON
o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.ambientOrLightmapUV.zw = 0;
#elif UNITY_SHOULD_SAMPLE_SH
#endif
#ifdef DYNAMICLIGHTMAP_ON
o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = UnityObjectToClipPos( v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float3 _BumpMap_var = UnpackNormal(tex2D(_BumpMap,TRANSFORM_TEX(i.uv0, _BumpMap)));
float3 _DetailNormal_var = UnpackNormal(tex2D(_DetailNormal,TRANSFORM_TEX(i.uv0, _DetailNormal)));
float node_9328 = 0.0;
float4 _DetailMask_var = tex2D(_DetailMask,TRANSFORM_TEX(i.uv0, _DetailMask));
float3 node_4699 = (1.0 - _DetailMask_var.rgb);
float node_6250 = 1.0;
float3 node_7351_nrm_base = _BumpMap_var.rgb + float3(0,0,1);
float3 node_7351_nrm_detail = float3(lerp(_DetailNormal_var.rgb,float3(node_9328,node_9328,node_9328),node_4699).rg,node_6250) * float3(-1,-1,1);
float3 node_7351_nrm_combined = node_7351_nrm_base*dot(node_7351_nrm_base, node_7351_nrm_detail)/node_7351_nrm_base.z - node_7351_nrm_detail;
float3 node_7351 = node_7351_nrm_combined;
float3 normalLocal = node_7351;
float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 lightColor = _LightColor0.rgb;
////// Lighting:
UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
float3 attenColor = attenuation * _LightColor0.xyz;
/////// GI Data:
UnityLight light;
#ifdef LIGHTMAP_OFF
light.color = lightColor;
light.dir = lightDirection;
light.ndotl = LambertTerm (normalDirection, light.dir);
#else
light.color = half3(0.f, 0.f, 0.f);
light.ndotl = 0.0f;
light.dir = half3(0.f, 0.f, 0.f);
#endif
UnityGIInput d;
d.light = light;
d.worldPos = i.posWorld.xyz;
d.worldViewDir = viewDirection;
d.atten = attenuation;
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
d.ambient = 0;
d.lightmapUV = i.ambientOrLightmapUV;
#else
d.ambient = i.ambientOrLightmapUV;
#endif
Unity_GlossyEnvironmentData ugls_en_data;
ugls_en_data.roughness = 1.0 - 0;
ugls_en_data.reflUVW = viewReflectDirection;
UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
lightDirection = gi.light.dir;
lightColor = gi.light.color;
/////// Diffuse:
float NdotL = max(0.0,dot( normalDirection, lightDirection ));
float3 directDiffuse = max( 0.0, NdotL) * attenColor;
float3 indirectDiffuse = float3(0,0,0);
indirectDiffuse += gi.indirect.diffuse;
float4 _DetailAlbedo_var = tex2D(_DetailAlbedo,TRANSFORM_TEX(i.uv0, _DetailAlbedo));
float3 node_6715 = (1.0 - _DetailAlbedo_var.rgb);
float3 node_5086 = (1.0 - (node_6715*4.0+-3.0));
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
float3 diffuseColor = lerp(saturate(min(node_5086,_MainTex_var.rgb)),_MainTex_var.rgb,node_4699);
float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
/// Final Color:
float3 finalColor = diffuse;
fixed4 finalRGBA = fixed4(finalColor,1);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "Meta"
Tags {
"LightMode"="Meta"
}
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#include "UnityMetaPass.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles ps4
#pragma target 3.0
uniform sampler2D _DetailAlbedo; uniform float4 _DetailAlbedo_ST;
uniform sampler2D _DetailMask; uniform float4 _DetailMask_ST;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
return o;
}
float4 frag(VertexOutput i) : SV_Target {
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
o.Emission = 0;
float4 _DetailAlbedo_var = tex2D(_DetailAlbedo,TRANSFORM_TEX(i.uv0, _DetailAlbedo));
float3 node_6715 = (1.0 - _DetailAlbedo_var.rgb);
float3 node_5086 = (1.0 - (node_6715*4.0+-3.0));
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
float4 _DetailMask_var = tex2D(_DetailMask,TRANSFORM_TEX(i.uv0, _DetailMask));
float3 node_4699 = (1.0 - _DetailMask_var.rgb);
float3 diffColor = lerp(saturate(min(node_5086,_MainTex_var.rgb)),_MainTex_var.rgb,node_4699);
o.Albedo = diffColor;
return UnityMetaFragment( o );
}
ENDCG
}
}
FallBack "Legacy Shaders/Bumped Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 412ef3e042fff9b4e8b5acfc84b2d415
timeCreated: 1497312166
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,213 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!200 &20000000
ShaderVariantCollection:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: DestroyItShaderVariants
m_Shaders:
data:
first: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: FOG_EXP2
passType: 0
data:
first: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 66, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: DIRECTIONAL FOG_EXP2
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _EMISSION
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _EMISSION _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _DETAIL_MULX2 _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _DETAIL_MULX2 _EMISSION _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _METALLICGLOSSMAP _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _EMISSION _METALLICGLOSSMAP _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _DETAIL_MULX2 _METALLICGLOSSMAP _NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _DETAIL_MULX2 _EMISSION _METALLICGLOSSMAP
_NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _ALPHAPREMULTIPLY_ON _DETAIL_MULX2 _EMISSION
_NORMALMAP
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _EMISSION _GLOSSYREFLECTIONS_OFF _NORMALMAP
_SPECULARHIGHLIGHTS_OFF
passType: 4
- keywords: DIRECTIONAL FOG_EXP2 _DETAIL_MULX2 _EMISSION _GLOSSYREFLECTIONS_OFF
_NORMALMAP _SPECULARHIGHLIGHTS_OFF
passType: 4
- keywords: FOG_EXP2 SPOT
passType: 5
- keywords: FOG_EXP2 POINT
passType: 5
- keywords: FOG_EXP2 SPOT _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _DETAIL_MULX2 _NORMALMAP
passType: 5
- keywords: FOG_EXP2 SPOT _METALLICGLOSSMAP _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _METALLICGLOSSMAP _NORMALMAP
passType: 5
- keywords: FOG_EXP2 SPOT _DETAIL_MULX2 _METALLICGLOSSMAP _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _DETAIL_MULX2 _METALLICGLOSSMAP _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _ALPHAPREMULTIPLY_ON _DETAIL_MULX2 _NORMALMAP
passType: 5
- keywords: FOG_EXP2 POINT _NORMALMAP _SPECULARHIGHLIGHTS_OFF
passType: 5
- keywords: FOG_EXP2 POINT _DETAIL_MULX2 _NORMALMAP _SPECULARHIGHLIGHTS_OFF
passType: 5
- keywords: SHADOWS_DEPTH
passType: 8
- keywords: SHADOWS_DEPTH _METALLICGLOSSMAP
passType: 8
- keywords: SHADOWS_DEPTH _ALPHAPREMULTIPLY_ON
passType: 8
data:
first: {fileID: 4, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: DIRECTIONAL FOG_EXP2
passType: 4
data:
first: {fileID: 200, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: FOG_EXP2
passType: 0
data:
first: {fileID: 203, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: FOG_EXP2
passType: 0
data:
first: {fileID: 207, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 10501, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: SHADOWS_DEPTH
passType: 8
data:
first: {fileID: 10502, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: SHADOWS_DEPTH
passType: 8
data:
first: {fileID: 9000, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 9001, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 10623, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: DIRECTIONAL FOG_EXP2 _TERRAIN_NORMAL_MAP
passType: 4
- keywords: FOG_EXP2 SPOT _TERRAIN_NORMAL_MAP
passType: 5
- keywords: FOG_EXP2 POINT _TERRAIN_NORMAL_MAP
passType: 5
- keywords: SHADOWS_DEPTH
passType: 8
data:
first: {fileID: 10624, guid: 0000000000000000f000000000000000, type: 0}
second:
variants:
- keywords: DIRECTIONAL FOG_EXP2 _TERRAIN_NORMAL_MAP
passType: 4
- keywords: FOG_EXP2 SPOT _TERRAIN_NORMAL_MAP
passType: 5
- keywords: FOG_EXP2 POINT _TERRAIN_NORMAL_MAP
passType: 5
data:
first: {fileID: 4800000, guid: 438ddd58d82c84d9eb1fdc56111702e1, type: 3}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 4800000, guid: 43ca18288c424f645aaa1e9e07f04c50, type: 3}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 4800000, guid: 003377fc2620a44939dadde6fe3f8190, type: 3}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 4800000, guid: 056e97cf96d14c840b829cc6f5e1310c, type: 3}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 4800000, guid: 1c42de2381dbc7b4caf1df9ae594474f, type: 3}
second:
variants:
- keywords:
passType: 0
data:
first: {fileID: 4800000, guid: 8f0a4bd05ac7f7c4f8606b69c8e87e42, type: 3}
second:
variants:
- keywords: DIRECTIONAL FOG_EXP2
passType: 4
- keywords: FOG_EXP2 POINT
passType: 5
- keywords: SHADOWS_DEPTH
passType: 8

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2714e9a1f66a72c4bb13c477f634a360
timeCreated: 1496077730
licenseType: Store
NativeFormatImporter:
mainObjectFileID: 20000000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,269 @@
Shader "DestroyIt/DestroyItSpeedTree" {
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_HueVariation ("Hue Variation", Color) = (1.0,0.5,0.0,0.1)
_HueVariationPos ("Hue Variation Position Override", Vector) = (0,0,0,0)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_DetailTex ("Detail", 2D) = "black" {}
_BumpMap ("Normal Map", 2D) = "bump" {}
_Cutoff ("Alpha Cutoff", Range(0,1)) = 0.333
[MaterialEnum(Off,0,Front,1,Back,2)] _Cull ("Cull", Int) = 2
[MaterialEnum(None,0,Fastest,1,Fast,2,Better,3,Best,4,Palm,5)] _WindQuality ("Wind Quality", Range(0,5)) = 0
}
// targeting SM3.0+
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="True"
"RenderType"="Opaque"
"DisableBatching"="LODFading"
}
LOD 400
Cull [_Cull]
CGPROGRAM
#pragma surface surf Lambert vertex:DestroyItSpeedTreeVert nodirlightmap nodynlightmap fullforwardshadows
#pragma target 3.0
#pragma instancing_options assumeuniformscaling maxcount:50
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#pragma shader_feature EFFECT_BUMP
#pragma shader_feature EFFECT_HUE_VARIATION
#define ENABLE_WIND
#include "DestroyItSpeedTreeCommon.cginc"
void surf(Input IN, inout SurfaceOutput OUT)
{
SpeedTreeFragOut o;
SpeedTreeFrag(IN, o);
SPEEDTREE_COPY_FRAG(OUT, o)
}
ENDCG
Pass
{
Tags { "LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma instancing_options assumeuniformscaling maxcount:50
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
#pragma multi_compile_fragment __ LOD_FADE_CROSSFADE
#pragma multi_compile_instancing
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#pragma multi_compile_shadowcaster
#define ENABLE_WIND
#include "DestroyItSpeedTreeCommon.cginc"
struct v2f
{
V2F_SHADOW_CASTER;
#ifdef SPEEDTREE_ALPHATEST
float2 uv : TEXCOORD1;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(SpeedTreeVB v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
#ifdef SPEEDTREE_ALPHATEST
o.uv = v.texcoord.xy;
#endif
OffsetSpeedTreeVertex(v, unity_LODFade.x);
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag(v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
#ifdef SPEEDTREE_ALPHATEST
clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
#endif
UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
Pass
{
Tags { "LightMode" = "Vertex" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma instancing_options assumeuniformscaling maxcount:50
#pragma multi_compile_fog
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
#pragma multi_compile_fragment __ LOD_FADE_CROSSFADE
#pragma multi_compile_instancing
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#pragma shader_feature EFFECT_HUE_VARIATION
#define ENABLE_WIND
#include "DestroyItSpeedTreeCommon.cginc"
struct v2f
{
UNITY_POSITION(vertex);
UNITY_FOG_COORDS(0)
Input data : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(SpeedTreeVB v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
DestroyItSpeedTreeVert(v, o.data);
o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 4, true);
o.vertex = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
SpeedTreeFragOut o;
SpeedTreeFrag(i.data, o);
UNITY_APPLY_DITHER_CROSSFADE(i.vertex.xy);
fixed4 c = fixed4(o.Albedo, o.Alpha);
UNITY_APPLY_FOG(i.fogCoord, c);
return c;
}
ENDCG
}
}
// targeting SM2.0: Normal-mapping, Hue variation and Wind animation are turned off for less instructions
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="True"
"RenderType"="Opaque"
"DisableBatching"="LODFading"
}
LOD 400
Cull [_Cull]
CGPROGRAM
#pragma surface surf Lambert vertex:DestroyItSpeedTreeVert nodirlightmap nodynlightmap fullforwardshadows noinstancing
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#include "DestroyItSpeedTreeCommon.cginc"
void surf(Input IN, inout SurfaceOutput OUT)
{
SpeedTreeFragOut o;
SpeedTreeFrag(IN, o);
SPEEDTREE_COPY_FRAG(OUT, o)
}
ENDCG
Pass
{
Tags { "LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#pragma multi_compile_shadowcaster
#include "DestroyItSpeedTreeCommon.cginc"
struct v2f
{
V2F_SHADOW_CASTER;
#ifdef SPEEDTREE_ALPHATEST
float2 uv : TEXCOORD1;
#endif
};
v2f vert(SpeedTreeVB v)
{
v2f o;
#ifdef SPEEDTREE_ALPHATEST
o.uv = v.texcoord.xy;
#endif
OffsetSpeedTreeVertex(v, unity_LODFade.x);
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
float4 frag(v2f i) : SV_Target
{
#ifdef SPEEDTREE_ALPHATEST
clip(tex2D(_MainTex, i.uv).a * _Color.a - _Cutoff);
#endif
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
Pass
{
Tags { "LightMode" = "Vertex" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH
#include "DestroyItSpeedTreeCommon.cginc"
struct v2f
{
UNITY_POSITION(vertex);
UNITY_FOG_COORDS(0)
Input data : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(SpeedTreeVB v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
DestroyItSpeedTreeVert(v, o.data);
o.data.color.rgb *= ShadeVertexLightsFull(v.vertex, v.normal, 2, false);
o.vertex = UnityObjectToClipPos(v.vertex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
SpeedTreeFragOut o;
SpeedTreeFrag(i.data, o);
fixed4 c = fixed4(o.Albedo, o.Alpha);
UNITY_APPLY_FOG(i.fogCoord, c);
return c;
}
ENDCG
}
}
FallBack "Transparent/Cutout/VertexLit"
CustomEditor "SpeedTreeMaterialInspector"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1eae39ea6b25c9f4bbc3fbfb3340163e
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,153 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
#ifndef SPEEDTREE_COMMON_INCLUDED
#define SPEEDTREE_COMMON_INCLUDED
#include "UnityCG.cginc"
#define SPEEDTREE_Y_UP
#ifdef GEOM_TYPE_BRANCH_DETAIL
#define GEOM_TYPE_BRANCH
#endif
#include "DestroyItSpeedTreeVertex.cginc"
// Define Input structure
struct Input
{
fixed4 color;
half3 interpolator1;
#ifdef GEOM_TYPE_BRANCH_DETAIL
half3 interpolator2;
#endif
};
// Define uniforms
#define mainTexUV interpolator1.xy
sampler2D _MainTex;
#ifdef GEOM_TYPE_BRANCH_DETAIL
#define Detail interpolator2
sampler2D _DetailTex;
#endif
#if defined(GEOM_TYPE_FROND) || defined(GEOM_TYPE_LEAF) || defined(GEOM_TYPE_FACING_LEAF)
#define SPEEDTREE_ALPHATEST
fixed _Cutoff;
#endif
#ifdef EFFECT_HUE_VARIATION
#define HueVariationAmount interpolator1.z
half4 _HueVariation;
float4 _HueVariationPos;
#endif
#if defined(EFFECT_BUMP) && !defined(LIGHTMAP_ON)
sampler2D _BumpMap;
#endif
fixed4 _Color;
// Vertex processing
void DestroyItSpeedTreeVert(inout SpeedTreeVB IN, out Input OUT)
{
UNITY_INITIALIZE_OUTPUT(Input, OUT);
OUT.mainTexUV = IN.texcoord.xy;
OUT.color = _Color;
OUT.color.rgb *= IN.color.r; // ambient occlusion factor
#ifdef EFFECT_HUE_VARIATION
if (!any(_HueVariationPos))
{
float hueVariationAmount = frac(unity_ObjectToWorld[0].w + unity_ObjectToWorld[1].w + unity_ObjectToWorld[2].w);
hueVariationAmount += frac(IN.vertex.x + IN.normal.y + IN.normal.x) * 0.5 - 0.3;
OUT.HueVariationAmount = saturate(hueVariationAmount * _HueVariation.a);
}
else
{
float hueVariationAmount = frac(_HueVariationPos.x + _HueVariationPos.y + _HueVariationPos.z);
hueVariationAmount += frac(IN.vertex.x + IN.normal.y + IN.normal.x) * 0.5 - 0.3;
OUT.HueVariationAmount = saturate(hueVariationAmount * _HueVariation.a);
}
#endif
#ifdef GEOM_TYPE_BRANCH_DETAIL
// The two types are always in different sub-range of the mesh so no interpolation (between detail and blend) problem.
OUT.Detail.xy = IN.texcoord2.xy;
if (IN.color.a == 0) // Blend
OUT.Detail.z = IN.texcoord2.z;
else // Detail texture
OUT.Detail.z = 2.5f; // stay out of Blend's .z range
#endif
OffsetSpeedTreeVertex(IN, unity_LODFade.x);
}
// Fragment processing
#if defined(EFFECT_BUMP)
#define SPEEDTREE_DATA_NORMAL fixed3 Normal;
#define SPEEDTREE_COPY_NORMAL(to, from) to.Normal = from.Normal;
#else
#define SPEEDTREE_DATA_NORMAL
#define SPEEDTREE_COPY_NORMAL(to, from)
#endif
#define SPEEDTREE_COPY_FRAG(to, from) \
to.Albedo = from.Albedo; \
to.Alpha = from.Alpha; \
SPEEDTREE_COPY_NORMAL(to, from)
struct SpeedTreeFragOut
{
fixed3 Albedo;
fixed Alpha;
SPEEDTREE_DATA_NORMAL
};
void SpeedTreeFrag(Input IN, out SpeedTreeFragOut OUT)
{
half4 diffuseColor = tex2D(_MainTex, IN.mainTexUV);
OUT.Alpha = diffuseColor.a * _Color.a;
#ifdef SPEEDTREE_ALPHATEST
clip(OUT.Alpha - _Cutoff);
#endif
#ifdef GEOM_TYPE_BRANCH_DETAIL
half4 detailColor = tex2D(_DetailTex, IN.Detail.xy);
diffuseColor.rgb = lerp(diffuseColor.rgb, detailColor.rgb, IN.Detail.z < 2.0f ? saturate(IN.Detail.z) : detailColor.a);
#endif
#ifdef EFFECT_HUE_VARIATION
half3 shiftedColor = lerp(diffuseColor.rgb, _HueVariation.rgb, IN.HueVariationAmount);
half maxBase = max(diffuseColor.r, max(diffuseColor.g, diffuseColor.b));
half newMaxBase = max(shiftedColor.r, max(shiftedColor.g, shiftedColor.b));
maxBase /= newMaxBase;
maxBase = maxBase * 0.5f + 0.5f;
// preserve vibrance
shiftedColor.rgb *= maxBase;
diffuseColor.rgb = saturate(shiftedColor);
#endif
OUT.Albedo = diffuseColor.rgb * IN.color.rgb;
#if defined(EFFECT_BUMP)
#if defined(LIGHTMAP_ON)
OUT.Normal = fixed3(0,0,1);
#else
OUT.Normal = UnpackNormal(tex2D(_BumpMap, IN.mainTexUV));
#ifdef GEOM_TYPE_BRANCH_DETAIL
half3 detailNormal = UnpackNormal(tex2D(_BumpMap, IN.Detail.xy));
OUT.Normal = lerp(OUT.Normal, detailNormal, IN.Detail.z < 2.0f ? saturate(IN.Detail.z) : detailColor.a);
#endif
#endif
#endif
}
#endif // SPEEDTREE_COMMON_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3f1d3e6403e97ec40b6462e131d8e240
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,148 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
#ifndef SPEEDTREE_VERTEX_INCLUDED
#define SPEEDTREE_VERTEX_INCLUDED
///////////////////////////////////////////////////////////////////////
// SpeedTree v6 Vertex Processing
///////////////////////////////////////////////////////////////////////
// struct SpeedTreeVB
// texcoord setup
//
// BRANCHES FRONDS LEAVES
// 0 diffuse uv, branch wind xy " "
// 1 lod xyz, 0 lod xyz, 0 anchor xyz, lod scalar
// 2 detail/seam uv, seam amount, 0 frond wind xyz, 0 leaf wind xyz, leaf group
struct SpeedTreeVB
{
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
float2 texcoord3 : TEXCOORD3;
half4 color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
///////////////////////////////////////////////////////////////////////
// SpeedTree winds
#ifdef ENABLE_WIND
#define WIND_QUALITY_NONE 0
#define WIND_QUALITY_FASTEST 1
#define WIND_QUALITY_FAST 2
#define WIND_QUALITY_BETTER 3
#define WIND_QUALITY_BEST 4
#define WIND_QUALITY_PALM 5
uniform half _WindQuality;
uniform half _WindEnabled;
#include "DestroyItSpeedTreeWind.cginc"
#endif
///////////////////////////////////////////////////////////////////////
// OffsetSpeedTreeVertex
void OffsetSpeedTreeVertex(inout SpeedTreeVB data, float lodValue)
{
float3 finalPosition = data.vertex.xyz;
#ifdef ENABLE_WIND
half windQuality = _WindQuality * _WindEnabled;
float3 rotatedWindVector, rotatedBranchAnchor;
if (windQuality <= WIND_QUALITY_NONE)
{
rotatedWindVector = float3(0.0f, 0.0f, 0.0f);
rotatedBranchAnchor = float3(0.0f, 0.0f, 0.0f);
}
else
{
// compute rotated wind parameters
rotatedWindVector = normalize(mul(_ST_WindVector.xyz, (float3x3)unity_ObjectToWorld));
rotatedBranchAnchor = normalize(mul(_ST_WindBranchAnchor.xyz, (float3x3)unity_ObjectToWorld)) * _ST_WindBranchAnchor.w;
}
#endif
#if defined(GEOM_TYPE_BRANCH) || defined(GEOM_TYPE_FROND)
// smooth LOD
#ifdef LOD_FADE_PERCENTAGE
finalPosition = lerp(finalPosition, data.texcoord1.xyz, lodValue);
#endif
// frond wind, if needed
#if defined(ENABLE_WIND) && defined(GEOM_TYPE_FROND)
if (windQuality == WIND_QUALITY_PALM)
finalPosition = RippleFrond(finalPosition, data.normal, data.texcoord.x, data.texcoord.y, data.texcoord2.x, data.texcoord2.y, data.texcoord2.z);
#endif
#elif defined(GEOM_TYPE_LEAF)
// remove anchor position
finalPosition -= data.texcoord1.xyz;
bool isFacingLeaf = data.color.a == 0;
if (isFacingLeaf)
{
#ifdef LOD_FADE_PERCENTAGE
finalPosition *= lerp(1.0, data.texcoord1.w, lodValue);
#endif
// face camera-facing leaf to camera
float offsetLen = length(finalPosition);
finalPosition = mul(finalPosition.xyz, (float3x3)UNITY_MATRIX_IT_MV); // inv(MV) * finalPosition
finalPosition = normalize(finalPosition) * offsetLen; // make sure the offset vector is still scaled
}
else
{
#ifdef LOD_FADE_PERCENTAGE
float3 lodPosition = float3(data.texcoord1.w, data.texcoord3.x, data.texcoord3.y);
finalPosition = lerp(finalPosition, lodPosition, lodValue);
#endif
}
#ifdef ENABLE_WIND
// leaf wind
if (windQuality > WIND_QUALITY_FASTEST && windQuality < WIND_QUALITY_PALM)
{
float leafWindTrigOffset = data.texcoord1.x + data.texcoord1.y;
finalPosition = LeafWind(windQuality == WIND_QUALITY_BEST, data.texcoord2.w > 0.0, finalPosition, data.normal, data.texcoord2.x, float3(0,0,0), data.texcoord2.y, data.texcoord2.z, leafWindTrigOffset, rotatedWindVector);
}
#endif
// move back out to anchor
finalPosition += data.texcoord1.xyz;
#endif
#ifdef ENABLE_WIND
float3 treePos = float3(unity_ObjectToWorld[0].w, unity_ObjectToWorld[1].w, unity_ObjectToWorld[2].w);
#ifndef GEOM_TYPE_MESH
if (windQuality >= WIND_QUALITY_BETTER)
{
// branch wind (applies to all 3D geometry)
finalPosition = BranchWind(windQuality == WIND_QUALITY_PALM, finalPosition, treePos, float4(data.texcoord.zw, 0, 0), rotatedWindVector, rotatedBranchAnchor);
}
#endif
if (windQuality > WIND_QUALITY_NONE)
{
// global wind
finalPosition = GlobalWind(finalPosition, treePos, true, rotatedWindVector, _ST_WindGlobal.x);
}
#endif
data.vertex.xyz = finalPosition;
}
#endif // SPEEDTREE_VERTEX_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 035bef16b41bc784bad623b895433d19
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,682 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
#ifndef SPEEDTREE_WIND_INCLUDED
#define SPEEDTREE_WIND_INCLUDED
///////////////////////////////////////////////////////////////////////
// Wind Info
CBUFFER_START(SpeedTreeWind)
float4 _ST_WindVector;
float4 _ST_WindGlobal;
float4 _ST_WindBranch;
float4 _ST_WindBranchTwitch;
float4 _ST_WindBranchWhip;
float4 _ST_WindBranchAnchor;
float4 _ST_WindBranchAdherences;
float4 _ST_WindTurbulences;
float4 _ST_WindLeaf1Ripple;
float4 _ST_WindLeaf1Tumble;
float4 _ST_WindLeaf1Twitch;
float4 _ST_WindLeaf2Ripple;
float4 _ST_WindLeaf2Tumble;
float4 _ST_WindLeaf2Twitch;
float4 _ST_WindFrondRipple;
float4 _ST_WindAnimation;
CBUFFER_END
///////////////////////////////////////////////////////////////////////
// UnpackNormalFromFloat
float3 UnpackNormalFromFloat(float fValue)
{
float3 vDecodeKey = float3(16.0, 1.0, 0.0625);
// decode into [0,1] range
float3 vDecodedValue = frac(fValue / vDecodeKey);
// move back into [-1,1] range & normalize
return (vDecodedValue * 2.0 - 1.0);
}
///////////////////////////////////////////////////////////////////////
// CubicSmooth
float4 CubicSmooth(float4 vData)
{
return vData * vData * (3.0 - 2.0 * vData);
}
///////////////////////////////////////////////////////////////////////
// TriangleWave
float4 TriangleWave(float4 vData)
{
return abs((frac(vData + 0.5) * 2.0) - 1.0);
}
///////////////////////////////////////////////////////////////////////
// TrigApproximate
float4 TrigApproximate(float4 vData)
{
return (CubicSmooth(TriangleWave(vData)) - 0.5) * 2.0;
}
///////////////////////////////////////////////////////////////////////
// RotationMatrix
//
// Constructs an arbitrary axis rotation matrix
float3x3 RotationMatrix(float3 vAxis, float fAngle)
{
// compute sin/cos of fAngle
float2 vSinCos;
#ifdef OPENGL
vSinCos.x = sin(fAngle);
vSinCos.y = cos(fAngle);
#else
sincos(fAngle, vSinCos.x, vSinCos.y);
#endif
const float c = vSinCos.y;
const float s = vSinCos.x;
const float t = 1.0 - c;
const float x = vAxis.x;
const float y = vAxis.y;
const float z = vAxis.z;
return float3x3(t * x * x + c, t * x * y - s * z, t * x * z + s * y,
t * x * y + s * z, t * y * y + c, t * y * z - s * x,
t * x * z - s * y, t * y * z + s * x, t * z * z + c);
}
///////////////////////////////////////////////////////////////////////
// mul_float3x3_float3x3
float3x3 mul_float3x3_float3x3(float3x3 mMatrixA, float3x3 mMatrixB)
{
return mul(mMatrixA, mMatrixB);
}
///////////////////////////////////////////////////////////////////////
// mul_float3x3_float3
float3 mul_float3x3_float3(float3x3 mMatrix, float3 vVector)
{
return mul(mMatrix, vVector);
}
///////////////////////////////////////////////////////////////////////
// cross()'s parameters are backwards in GLSL
#define wind_cross(a, b) cross((a), (b))
///////////////////////////////////////////////////////////////////////
// Roll
float Roll(float fCurrent,
float fMaxScale,
float fMinScale,
float fSpeed,
float fRipple,
float3 vPos,
float fTime,
float3 vRotatedWindVector)
{
float fWindAngle = dot(vPos, -vRotatedWindVector) * fRipple;
float fAdjust = TrigApproximate(float4(fWindAngle + fTime * fSpeed, 0.0, 0.0, 0.0)).x;
fAdjust = (fAdjust + 1.0) * 0.5;
return lerp(fCurrent * fMinScale, fCurrent * fMaxScale, fAdjust);
}
///////////////////////////////////////////////////////////////////////
// Twitch
float Twitch(float3 vPos, float fAmount, float fSharpness, float fTime)
{
const float c_fTwitchFudge = 0.87;
float4 vOscillations = TrigApproximate(float4(fTime + (vPos.x + vPos.z), c_fTwitchFudge * fTime + vPos.y, 0.0, 0.0));
//float fTwitch = sin(fFreq1 * fTime + (vPos.x + vPos.z)) * cos(fFreq2 * fTime + vPos.y);
float fTwitch = vOscillations.x * vOscillations.y * vOscillations.y;
fTwitch = (fTwitch + 1.0) * 0.5;
return fAmount * pow(saturate(fTwitch), fSharpness);
}
///////////////////////////////////////////////////////////////////////
// Oscillate
//
// This function computes an oscillation value and whip value if necessary.
// Whip and oscillation are combined like this to minimize calls to
// TrigApproximate( ) when possible.
float Oscillate(float3 vPos,
float fTime,
float fOffset,
float fWeight,
float fWhip,
bool bWhip,
bool bRoll,
bool bComplex,
float fTwitch,
float fTwitchFreqScale,
inout float4 vOscillations,
float3 vRotatedWindVector)
{
float fOscillation = 1.0;
if (bComplex)
{
if (bWhip)
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * fTwitchFreqScale + fOffset, fTwitchFreqScale * 0.5 * (fTime + fOffset), fTime + fOffset + (1.0 - fWeight)));
else
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * fTwitchFreqScale + fOffset, fTwitchFreqScale * 0.5 * (fTime + fOffset), 0.0));
float fFineDetail = vOscillations.x;
float fBroadDetail = vOscillations.y * vOscillations.z;
float fTarget = 1.0;
float fAmount = fBroadDetail;
if (fBroadDetail < 0.0)
{
fTarget = -fTarget;
fAmount = -fAmount;
}
fBroadDetail = lerp(fBroadDetail, fTarget, fAmount);
fBroadDetail = lerp(fBroadDetail, fTarget, fAmount);
fOscillation = fBroadDetail * fTwitch * (1.0 - _ST_WindVector.w) + fFineDetail * (1.0 - fTwitch);
if (bWhip)
fOscillation *= 1.0 + (vOscillations.w * fWhip);
}
else
{
if (bWhip)
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.689 + fOffset, 0.0, fTime + fOffset + (1.0 - fWeight)));
else
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.689 + fOffset, 0.0, 0.0));
fOscillation = vOscillations.x + vOscillations.y * vOscillations.x;
if (bWhip)
fOscillation *= 1.0 + (vOscillations.w * fWhip);
}
//if (bRoll)
//{
// fOscillation = Roll(fOscillation, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
//}
return fOscillation;
}
///////////////////////////////////////////////////////////////////////
// Turbulence
float Turbulence(float fTime, float fOffset, float fGlobalTime, float fTurbulence)
{
const float c_fTurbulenceFactor = 0.1;
float4 vOscillations = TrigApproximate(float4(fTime * c_fTurbulenceFactor + fOffset, fGlobalTime * fTurbulence * c_fTurbulenceFactor + fOffset, 0.0, 0.0));
return 1.0 - (vOscillations.x * vOscillations.y * vOscillations.x * vOscillations.y * fTurbulence);
}
///////////////////////////////////////////////////////////////////////
// GlobalWind
//
// This function positions any tree geometry based on their untransformed
// position and 4 wind floats.
float3 GlobalWind(float3 vPos, float3 vInstancePos, bool bPreserveShape, float3 vRotatedWindVector, float time)
{
// WIND_LOD_GLOBAL may be on, but if the global wind effect (WIND_EFFECT_GLOBAL_ST_Wind)
// was disabled for the tree in the Modeler, we should skip it
float fLength = 1.0;
if (bPreserveShape)
fLength = length(vPos.xyz);
// compute how much the height contributes
#ifdef SPEEDTREE_Z_UP
float fAdjust = max(vPos.z - (1.0 / _ST_WindGlobal.z) * 0.25, 0.0) * _ST_WindGlobal.z;
#else
float fAdjust = max(vPos.y - (1.0 / _ST_WindGlobal.z) * 0.25, 0.0) * _ST_WindGlobal.z;
#endif
if (fAdjust != 0.0)
fAdjust = pow(fAdjust, _ST_WindGlobal.w);
// primary oscillation
float4 vOscillations = TrigApproximate(float4(vInstancePos.x + time, vInstancePos.y + time * 0.8, 0.0, 0.0));
float fOsc = vOscillations.x + (vOscillations.y * vOscillations.y);
float fMoveAmount = _ST_WindGlobal.y * fOsc;
// move a minimum amount based on direction adherence
fMoveAmount += _ST_WindBranchAdherences.x / _ST_WindGlobal.z;
// adjust based on how high up the tree this vertex is
fMoveAmount *= fAdjust;
// xy component
#ifdef SPEEDTREE_Z_UP
vPos.xy += vRotatedWindVector.xy * fMoveAmount;
#else
vPos.xz += vRotatedWindVector.xz * fMoveAmount;
#endif
if (bPreserveShape)
vPos.xyz = normalize(vPos.xyz) * fLength;
return vPos;
}
///////////////////////////////////////////////////////////////////////
// SimpleBranchWind
float3 SimpleBranchWind(float3 vPos,
float3 vInstancePos,
float fWeight,
float fOffset,
float fTime,
float fDistance,
float fTwitch,
float fTwitchScale,
float fWhip,
bool bWhip,
bool bRoll,
bool bComplex,
float3 vRotatedWindVector)
{
// turn the offset back into a nearly normalized vector
float3 vWindVector = UnpackNormalFromFloat(fOffset);
vWindVector = vWindVector * fWeight;
// try to fudge time a bit so that instances aren't in sync
fTime += vInstancePos.x + vInstancePos.y;
// oscillate
float4 vOscillations;
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, bRoll, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
vPos.xyz += vWindVector * fOsc * fDistance;
return vPos;
}
///////////////////////////////////////////////////////////////////////
// DirectionalBranchWind
float3 DirectionalBranchWind(float3 vPos,
float3 vInstancePos,
float fWeight,
float fOffset,
float fTime,
float fDistance,
float fTurbulence,
float fAdherence,
float fTwitch,
float fTwitchScale,
float fWhip,
bool bWhip,
bool bRoll,
bool bComplex,
bool bTurbulence,
float3 vRotatedWindVector)
{
// turn the offset back into a nearly normalized vector
float3 vWindVector = UnpackNormalFromFloat(fOffset);
vWindVector = vWindVector * fWeight;
// try to fudge time a bit so that instances aren't in sync
fTime += vInstancePos.x + vInstancePos.y;
// oscillate
float4 vOscillations;
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, false, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
vPos.xyz += vWindVector * fOsc * fDistance;
// add in the direction, accounting for turbulence
float fAdherenceScale = 1.0;
if (bTurbulence)
fAdherenceScale = Turbulence(fTime, fOffset, _ST_WindAnimation.x, fTurbulence);
if (bWhip)
fAdherenceScale += vOscillations.w * _ST_WindVector.w * fWhip;
//if (bRoll)
// fAdherenceScale = Roll(fAdherenceScale, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
vPos.xyz += vRotatedWindVector * fAdherence * fAdherenceScale * fWeight;
return vPos;
}
///////////////////////////////////////////////////////////////////////
// DirectionalBranchWindFrondStyle
float3 DirectionalBranchWindFrondStyle(float3 vPos,
float3 vInstancePos,
float fWeight,
float fOffset,
float fTime,
float fDistance,
float fTurbulence,
float fAdherence,
float fTwitch,
float fTwitchScale,
float fWhip,
bool bWhip,
bool bRoll,
bool bComplex,
bool bTurbulence,
float3 vRotatedWindVector,
float3 vRotatedBranchAnchor)
{
// turn the offset back into a nearly normalized vector
float3 vWindVector = UnpackNormalFromFloat(fOffset);
vWindVector = vWindVector * fWeight;
// try to fudge time a bit so that instances aren't in sync
fTime += vInstancePos.x + vInstancePos.y;
// oscillate
float4 vOscillations;
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, false, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
vPos.xyz += vWindVector * fOsc * fDistance;
// add in the direction, accounting for turbulence
float fAdherenceScale = 1.0;
if (bTurbulence)
fAdherenceScale = Turbulence(fTime, fOffset, _ST_WindAnimation.x, fTurbulence);
//if (bRoll)
// fAdherenceScale = Roll(fAdherenceScale, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
if (bWhip)
fAdherenceScale += vOscillations.w * _ST_WindVector.w * fWhip;
float3 vWindAdherenceVector = vRotatedBranchAnchor - vPos.xyz;
vPos.xyz += vWindAdherenceVector * fAdherence * fAdherenceScale * fWeight;
return vPos;
}
///////////////////////////////////////////////////////////////////////
// BranchWind
// Apply only to better, best, palm winds
float3 BranchWind(bool isPalmWind, float3 vPos, float3 vInstancePos, float4 vWindData, float3 vRotatedWindVector, float3 vRotatedBranchAnchor)
{
if (isPalmWind)
{
vPos = DirectionalBranchWindFrondStyle(vPos, vInstancePos, vWindData.x, vWindData.y, _ST_WindBranch.x, _ST_WindBranch.y, _ST_WindTurbulences.x, _ST_WindBranchAdherences.y, _ST_WindBranchTwitch.x, _ST_WindBranchTwitch.y, _ST_WindBranchWhip.x, true, false, true, true, vRotatedWindVector, vRotatedBranchAnchor);
}
else
{
vPos = SimpleBranchWind(vPos, vInstancePos, vWindData.x, vWindData.y, _ST_WindBranch.x, _ST_WindBranch.y, _ST_WindBranchTwitch.x, _ST_WindBranchTwitch.y, _ST_WindBranchWhip.x, false, false, true, vRotatedWindVector);
}
return vPos;
}
///////////////////////////////////////////////////////////////////////
// LeafRipple
float3 LeafRipple(float3 vPos,
inout float3 vDirection,
float fScale,
float fPackedRippleDir,
float fTime,
float fAmount,
bool bDirectional,
float fTrigOffset)
{
// compute how much to move
float4 vInput = float4(fTime + fTrigOffset, 0.0, 0.0, 0.0);
float fMoveAmount = fAmount * TrigApproximate(vInput).x;
if (bDirectional)
{
vPos.xyz += vDirection.xyz * fMoveAmount * fScale;
}
else
{
float3 vRippleDir = UnpackNormalFromFloat(fPackedRippleDir);
vPos.xyz += vRippleDir * fMoveAmount * fScale;
}
return vPos;
}
///////////////////////////////////////////////////////////////////////
// LeafTumble
float3 LeafTumble(float3 vPos,
inout float3 vDirection,
float fScale,
float3 vAnchor,
float3 vGrowthDir,
float fTrigOffset,
float fTime,
float fFlip,
float fTwist,
float fAdherence,
float3 vTwitch,
float4 vRoll,
bool bTwitch,
bool bRoll,
float3 vRotatedWindVector)
{
// compute all oscillations up front
float3 vFracs = frac((vAnchor + fTrigOffset) * 30.3);
float fOffset = vFracs.x + vFracs.y + vFracs.z;
float4 vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.75 - fOffset, fTime * 0.01 + fOffset, fTime * 1.0 + fOffset));
// move to the origin and get the growth direction
float3 vOriginPos = vPos.xyz - vAnchor;
float fLength = length(vOriginPos);
// twist
float fOsc = vOscillations.x + vOscillations.y * vOscillations.y;
float3x3 matTumble = RotationMatrix(vGrowthDir, fScale * fTwist * fOsc);
// with wind
float3 vAxis = wind_cross(vGrowthDir, vRotatedWindVector);
float fDot = clamp(dot(vRotatedWindVector, vGrowthDir), -1.0, 1.0);
#ifdef SPEEDTREE_Z_UP
vAxis.z += fDot;
#else
vAxis.y += fDot;
#endif
vAxis = normalize(vAxis);
float fAngle = acos(fDot);
float fAdherenceScale = 1.0;
//if (bRoll)
//{
// fAdherenceScale = Roll(fAdherenceScale, vRoll.x, vRoll.y, vRoll.z, vRoll.w, vAnchor.xyz, fTime, vRotatedWindVector);
//}
fOsc = vOscillations.y - vOscillations.x * vOscillations.x;
float fTwitch = 0.0;
if (bTwitch)
fTwitch = Twitch(vAnchor.xyz, vTwitch.x, vTwitch.y, vTwitch.z + fOffset);
matTumble = mul_float3x3_float3x3(matTumble, RotationMatrix(vAxis, fScale * (fAngle * fAdherence * fAdherenceScale + fOsc * fFlip + fTwitch)));
vDirection = mul_float3x3_float3(matTumble, vDirection);
vOriginPos = mul_float3x3_float3(matTumble, vOriginPos);
vOriginPos = normalize(vOriginPos) * fLength;
return (vOriginPos + vAnchor);
}
///////////////////////////////////////////////////////////////////////
// LeafWind
// Optimized (for instruction count) version. Assumes leaf 1 and 2 have the same options
float3 LeafWind(bool isBestWind,
bool bLeaf2,
float3 vPos,
inout float3 vDirection,
float fScale,
float3 vAnchor,
float fPackedGrowthDir,
float fPackedRippleDir,
float fRippleTrigOffset,
float3 vRotatedWindVector)
{
vPos = LeafRipple(vPos, vDirection, fScale, fPackedRippleDir,
(bLeaf2 ? _ST_WindLeaf2Ripple.x : _ST_WindLeaf1Ripple.x),
(bLeaf2 ? _ST_WindLeaf2Ripple.y : _ST_WindLeaf1Ripple.y),
false, fRippleTrigOffset);
if (isBestWind)
{
float3 vGrowthDir = UnpackNormalFromFloat(fPackedGrowthDir);
vPos = LeafTumble(vPos, vDirection, fScale, vAnchor, vGrowthDir, fPackedGrowthDir,
(bLeaf2 ? _ST_WindLeaf2Tumble.x : _ST_WindLeaf1Tumble.x),
(bLeaf2 ? _ST_WindLeaf2Tumble.y : _ST_WindLeaf1Tumble.y),
(bLeaf2 ? _ST_WindLeaf2Tumble.z : _ST_WindLeaf1Tumble.z),
(bLeaf2 ? _ST_WindLeaf2Tumble.w : _ST_WindLeaf1Tumble.w),
(bLeaf2 ? _ST_WindLeaf2Twitch.xyz : _ST_WindLeaf1Twitch.xyz),
0.0f,
(bLeaf2 ? true : true),
(bLeaf2 ? true : true),
vRotatedWindVector);
}
return vPos;
}
///////////////////////////////////////////////////////////////////////
// RippleFrondOneSided
float3 RippleFrondOneSided(float3 vPos,
inout float3 vDirection,
float fU,
float fV,
float fRippleScale
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
, float3 vBinormal
, float3 vTangent
#endif
)
{
float fOffset = 0.0;
if (fU < 0.5)
fOffset = 0.75;
float4 vOscillations = TrigApproximate(float4((_ST_WindFrondRipple.x + fV) * _ST_WindFrondRipple.z + fOffset, 0.0, 0.0, 0.0));
float fAmount = fRippleScale * vOscillations.x * _ST_WindFrondRipple.y;
float3 vOffset = fAmount * vDirection;
vPos.xyz += vOffset;
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
vTangent.xyz = normalize(vTangent.xyz + vOffset * _ST_WindFrondRipple.w);
float3 vNewNormal = normalize(wind_cross(vBinormal.xyz, vTangent.xyz));
if (dot(vNewNormal, vDirection.xyz) < 0.0)
vNewNormal = -vNewNormal;
vDirection.xyz = vNewNormal;
#endif
return vPos;
}
///////////////////////////////////////////////////////////////////////
// RippleFrondTwoSided
float3 RippleFrondTwoSided(float3 vPos,
inout float3 vDirection,
float fU,
float fLengthPercent,
float fPackedRippleDir,
float fRippleScale
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
, float3 vBinormal
, float3 vTangent
#endif
)
{
float4 vOscillations = TrigApproximate(float4(_ST_WindFrondRipple.x * fLengthPercent * _ST_WindFrondRipple.z, 0.0, 0.0, 0.0));
float3 vRippleDir = UnpackNormalFromFloat(fPackedRippleDir);
float fAmount = fRippleScale * vOscillations.x * _ST_WindFrondRipple.y;
float3 vOffset = fAmount * vRippleDir;
vPos.xyz += vOffset;
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
vTangent.xyz = normalize(vTangent.xyz + vOffset * _ST_WindFrondRipple.w);
float3 vNewNormal = normalize(wind_cross(vBinormal.xyz, vTangent.xyz));
if (dot(vNewNormal, vDirection.xyz) < 0.0)
vNewNormal = -vNewNormal;
vDirection.xyz = vNewNormal;
#endif
return vPos;
}
///////////////////////////////////////////////////////////////////////
// RippleFrond
float3 RippleFrond(float3 vPos,
inout float3 vDirection,
float fU,
float fV,
float fPackedRippleDir,
float fRippleScale,
float fLenghtPercent
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
, float3 vBinormal
, float3 vTangent
#endif
)
{
return RippleFrondOneSided(vPos,
vDirection,
fU,
fV,
fRippleScale
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
, vBinormal
, vTangent
#endif
);
}
#endif // SPEEDTREE_WIND_INCLUDED

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b5d2d0a8305f7bd4ba1ef4a3a7947180
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,281 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/SSAO" {
Properties {
_MainTex ("", 2D) = "" {}
_RandomTexture ("", 2D) = "" {}
_SSAO ("", 2D) = "" {}
}
Subshader {
ZTest Always Cull Off ZWrite Off
CGINCLUDE
// Common code used by several SSAO passes below
#include "UnityCG.cginc"
struct v2f_ao {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uvr : TEXCOORD1;
};
uniform float2 _NoiseScale;
float4 _CameraDepthNormalsTexture_ST;
v2f_ao vert_ao (appdata_img v)
{
v2f_ao o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _CameraDepthNormalsTexture);
o.uvr = v.texcoord.xy * _NoiseScale;
return o;
}
sampler2D _CameraDepthNormalsTexture;
sampler2D _RandomTexture;
float4 _Params; // x=radius, y=minz, z=attenuation power, w=SSAO power
// HLSL and GLSL do not support arbitrarily sized arrays as function parameters (eg. float bla[]), whereas Cg does.
#if !defined(UNITY_COMPILER_CG)
# define INPUT_SAMPLE_COUNT 8
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 14
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 26
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
# define INPUT_SAMPLE_COUNT 34
# include "frag_ao.cginc"
# undef INPUT_SAMPLE_COUNT
#else
# define INPUT_SAMPLE_COUNT
# include "frag_ao.cginc"
#endif
ENDCG
// ---- SSAO pass, 8 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 8
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.01305719,0.5872321,-0.119337),
float3(0.3230782,0.02207272,-0.4188725),
float3(-0.310725,-0.191367,0.05613686),
float3(-0.4796457,0.09398766,-0.5802653),
float3(0.1399992,-0.3357702,0.5596789),
float3(-0.2484578,0.2555322,0.3489439),
float3(0.1871898,-0.702764,-0.2317479),
float3(0.8849149,0.2842076,0.368524),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- SSAO pass, 14 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 14
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.4010039,0.8899381,-0.01751772),
float3(0.1617837,0.1338552,-0.3530486),
float3(-0.2305296,-0.1900085,0.5025396),
float3(-0.6256684,0.1241661,0.1163932),
float3(0.3820786,-0.3241398,0.4112825),
float3(-0.08829653,0.1649759,0.1395879),
float3(0.1891677,-0.1283755,-0.09873557),
float3(0.1986142,0.1767239,0.4380491),
float3(-0.3294966,0.02684341,-0.4021836),
float3(-0.01956503,-0.3108062,-0.410663),
float3(-0.3215499,0.6832048,-0.3433446),
float3(0.7026125,0.1648249,0.02250625),
float3(0.03704464,-0.939131,0.1358765),
float3(-0.6984446,-0.6003422,-0.04016943),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- SSAO pass, 26 samples
Pass {
CGPROGRAM
#pragma vertex vert_ao
#pragma fragment frag
#pragma target 3.0
half4 frag (v2f_ao i) : SV_Target
{
#define SAMPLE_COUNT 26
const float3 RAND_SAMPLES[SAMPLE_COUNT] = {
float3(0.2196607,0.9032637,0.2254677),
float3(0.05916681,0.2201506,-0.1430302),
float3(-0.4152246,0.1320857,0.7036734),
float3(-0.3790807,0.1454145,0.100605),
float3(0.3149606,-0.1294581,0.7044517),
float3(-0.1108412,0.2162839,0.1336278),
float3(0.658012,-0.4395972,-0.2919373),
float3(0.5377914,0.3112189,0.426864),
float3(-0.2752537,0.07625949,-0.1273409),
float3(-0.1915639,-0.4973421,-0.3129629),
float3(-0.2634767,0.5277923,-0.1107446),
float3(0.8242752,0.02434147,0.06049098),
float3(0.06262707,-0.2128643,-0.03671562),
float3(-0.1795662,-0.3543862,0.07924347),
float3(0.06039629,0.24629,0.4501176),
float3(-0.7786345,-0.3814852,-0.2391262),
float3(0.2792919,0.2487278,-0.05185341),
float3(0.1841383,0.1696993,-0.8936281),
float3(-0.3479781,0.4725766,-0.719685),
float3(-0.1365018,-0.2513416,0.470937),
float3(0.1280388,-0.563242,0.3419276),
float3(-0.4800232,-0.1899473,0.2398808),
float3(0.6389147,0.1191014,-0.5271206),
float3(0.1932822,-0.3692099,-0.6060588),
float3(-0.3465451,-0.1654651,-0.6746758),
float3(0.2448421,-0.1610962,0.1289366),
};
return frag_ao (i, SAMPLE_COUNT, RAND_SAMPLES);
}
ENDCG
}
// ---- Blur pass
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _CameraDepthNormalsTexture);
return o;
}
sampler2D _SSAO;
float3 _TexelOffsetScale;
inline half CheckSame (half4 n, half4 nn)
{
// difference in normals
half2 diff = abs(n.xy - nn.xy);
half sn = (diff.x + diff.y) < 0.1;
// difference in depth
float z = DecodeFloatRG (n.zw);
float zz = DecodeFloatRG (nn.zw);
float zdiff = abs(z-zz) * _ProjectionParams.z;
half sz = zdiff < 0.2;
return sn * sz;
}
half4 frag( v2f i ) : SV_Target
{
#define NUM_BLUR_SAMPLES 4
float2 o = _TexelOffsetScale.xy;
half sum = tex2D(_SSAO, i.uv).r * (NUM_BLUR_SAMPLES + 1);
half denom = NUM_BLUR_SAMPLES + 1;
half4 geom = tex2D (_CameraDepthNormalsTexture, i.uv);
for (int s = 0; s < NUM_BLUR_SAMPLES; ++s)
{
float2 nuv = i.uv + o * (s+1);
half4 ngeom = tex2D (_CameraDepthNormalsTexture, nuv.xy);
half coef = (NUM_BLUR_SAMPLES - s) * CheckSame (geom, ngeom);
sum += tex2D (_SSAO, nuv.xy).r * coef;
denom += coef;
}
for (int s = 0; s < NUM_BLUR_SAMPLES; ++s)
{
float2 nuv = i.uv - o * (s+1);
half4 ngeom = tex2D (_CameraDepthNormalsTexture, nuv.xy);
half coef = (NUM_BLUR_SAMPLES - s) * CheckSame (geom, ngeom);
sum += tex2D (_SSAO, nuv.xy).r * coef;
denom += coef;
}
return sum / denom;
}
ENDCG
}
// ---- Composite pass
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv[2] : TEXCOORD0;
};
v2f vert (appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos (v.vertex);
o.uv[0] = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
o.uv[1] = MultiplyUV (UNITY_MATRIX_TEXTURE1, v.texcoord);
return o;
}
sampler2D _MainTex;
sampler2D _SSAO;
half4 frag( v2f i ) : SV_Target
{
half4 c = tex2D (_MainTex, i.uv[0]);
half ao = tex2D (_SSAO, i.uv[1]).r;
ao = pow (ao, _Params.w);
c.rgb *= ao;
return c;
}
ENDCG
}
}
Fallback off
}

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 5e5cf5af14ec55d4d973c292cbafe669
ShaderImporter:
userData:

View File

@@ -0,0 +1,246 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Skybox/Procedural" {
Properties {
_SunTint ("Sun Tint", Color) = (1, 1, 1, 1)
_SunStrength ("Sun Strength", Float) = 1.0
_Color ("Atmosphere Tint", Color) = (.5, .5, .5, 1)
_GroundColor ("Ground", Color) = (.369, .349, .341, 1)
_HdrExposure("HDR Exposure", Float) = 1.3
}
SubShader {
Tags { "Queue"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
Cull Off ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
uniform half _HdrExposure; // HDR exposure
uniform half3 _GroundColor;
half3 _Color;
half3 _SunTint;
half _SunStrength;
// RGB wavelengths
#define GAMMA .454545
static const float MN = 2;
static const float MX = .7;
#define WR (0.65*lerp(MN, MX, pow(_Color.r,GAMMA)))
#define WG (0.57*lerp(MN, MX, pow(_Color.g,GAMMA)))
#define WB (0.475*lerp(MN, MX, pow(_Color.b,GAMMA)))
//#define WR pow(0.65,GAMMA)
//#define WG pow(0.57,GAMMA)
//#define WB pow(0.475,GAMMA)
static const float3 kInvWavelength = float3(1.0 / (WR*WR*WR*WR), 1.0 / (WG*WG*WG*WG), 1.0 / (WB*WB*WB*WB));
#define OUTER_RADIUS 1.025
static const float kOuterRadius = OUTER_RADIUS;
static const float kOuterRadius2 = OUTER_RADIUS*OUTER_RADIUS;
static const float kInnerRadius = 1.0;
static const float kInnerRadius2 = 1.0;
static const float kCameraHeight = 0.0001;
#define kRAYLEIGH 0.0025 // Rayleigh constant
#define kMIE 0.0010 // Mie constant
#define kSUN_BRIGHTNESS 20.0 // Sun brightness
static const float kKrESun = kRAYLEIGH * kSUN_BRIGHTNESS;
static const float kKmESun = kMIE * kSUN_BRIGHTNESS;
static const float kKr4PI = kRAYLEIGH * 4.0 * 3.14159265;
static const float kKm4PI = kMIE * 4.0 * 3.14159265;
static const float kScale = 1.0 / (OUTER_RADIUS - 1.0);
static const float kScaleDepth = 0.25;
static const float kScaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;
static const float kSamples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH
#define MIE_G (-0.990)
#define MIE_G2 0.9801
struct appdata_t {
float4 vertex : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
half3 rayDir : TEXCOORD0; // Vector for incoming ray, normalized ( == -eyeRay )
half3 cIn : TEXCOORD1; // In-scatter coefficient
half3 cOut : TEXCOORD2; // Out-scatter coefficient
};
float scale(float inCos)
{
float x = 1.0 - inCos;
return 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
v2f vert (appdata_t v)
{
v2f OUT;
OUT.pos = UnityObjectToClipPos(v.vertex);
float3 cameraPos = float3(0,kInnerRadius + kCameraHeight,0); // The camera's current position
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 eyeRay = normalize(mul((float3x3)unity_ObjectToWorld, v.vertex.xyz));
OUT.rayDir = half3(-eyeRay);
float far = 0.0;
if(eyeRay.y >= 0.0)
{
// Sky
// Calculate the length of the "atmosphere"
far = sqrt(kOuterRadius2 + kInnerRadius2 * eyeRay.y * eyeRay.y - kInnerRadius2) - kInnerRadius * eyeRay.y;
float3 pos = cameraPos + far * eyeRay;
// Calculate the ray's starting position, then calculate its scattering offset
float height = kInnerRadius + kCameraHeight;
float depth = exp(kScaleOverScaleDepth * (-kCameraHeight));
float startAngle = dot(eyeRay, cameraPos) / height;
float startOffset = depth*scale(startAngle);
// Initialize the scattering loop variables
float sampleLength = far / kSamples;
float scaledLength = sampleLength * kScale;
float3 sampleRay = eyeRay * sampleLength;
float3 samplePoint = cameraPos + sampleRay * 0.5;
// Now loop through the sample rays
float3 frontColor = float3(0.0, 0.0, 0.0);
// WTF BBQ: WP8 and desktop FL_9_1 do not like the for loop here
// (but an almost identical loop is perfectly fine in the ground calculations below)
// Just unrolling this manually seems to make everything fine again.
// for(int i=0; i<int(kSamples); i++)
{
float height = length(samplePoint);
float depth = exp(kScaleOverScaleDepth * (kInnerRadius - height));
float lightAngle = dot(_WorldSpaceLightPos0.xyz, samplePoint) / height;
float cameraAngle = dot(eyeRay, samplePoint) / height;
float scatter = (startOffset + depth*(scale(lightAngle) - scale(cameraAngle)));
float3 attenuate = exp(-scatter * (kInvWavelength * kKr4PI + kKm4PI));
frontColor += attenuate * (depth * scaledLength);
samplePoint += sampleRay;
}
{
float height = length(samplePoint);
float depth = exp(kScaleOverScaleDepth * (kInnerRadius - height));
float lightAngle = dot(_WorldSpaceLightPos0.xyz, samplePoint) / height;
float cameraAngle = dot(eyeRay, samplePoint) / height;
float scatter = (startOffset + depth*(scale(lightAngle) - scale(cameraAngle)));
float3 attenuate = exp(-scatter * (kInvWavelength * kKr4PI + kKm4PI));
frontColor += attenuate * (depth * scaledLength);
samplePoint += sampleRay;
}
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
OUT.cIn.xyz = frontColor * (kInvWavelength * kKrESun);
OUT.cOut = frontColor * kKmESun;
}
else
{
// Ground
far = (-kCameraHeight) / (min(-0.00001, eyeRay.y));
float3 pos = cameraPos + far * eyeRay;
// Calculate the ray's starting position, then calculate its scattering offset
float depth = exp((-kCameraHeight) * (1.0/kScaleDepth));
float cameraAngle = dot(-eyeRay, pos);
float lightAngle = dot(_WorldSpaceLightPos0.xyz, pos);
float cameraScale = scale(cameraAngle);
float lightScale = scale(lightAngle);
float cameraOffset = depth*cameraScale;
float temp = (lightScale + cameraScale);
// Initialize the scattering loop variables
float sampleLength = far / kSamples;
float scaledLength = sampleLength * kScale;
float3 sampleRay = eyeRay * sampleLength;
float3 samplePoint = cameraPos + sampleRay * 0.5;
// Now loop through the sample rays
float3 frontColor = float3(0.0, 0.0, 0.0);
float3 attenuate;
for(int i=0; i<int(kSamples); i++)
{
float height = length(samplePoint);
float depth = exp(kScaleOverScaleDepth * (kInnerRadius - height));
float scatter = depth*temp - cameraOffset;
attenuate = exp(-scatter * (kInvWavelength * kKr4PI + kKm4PI));
frontColor += attenuate * (depth * scaledLength);
samplePoint += sampleRay;
}
OUT.cIn.xyz = frontColor * (kInvWavelength * kKrESun + kKmESun);
OUT.cOut.xyz = clamp(attenuate, 0.0, 1.0);
}
return OUT;
}
// Calculates the Mie phase function
half getMiePhase(half eyeCos, half eyeCos2)
{
half temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;
// A somewhat rough approx for :
// temp = pow(temp, 1.5);
temp = smoothstep(0.0, 0.01, temp) * temp;
temp = max(temp,1.0e-4); // prevent division by zero, esp. in half precision
return 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;
}
// Calculates the Rayleigh phase function
half getRayleighPhase(half eyeCos2)
{
return 0.75 + 0.75*eyeCos2;
}
half4 frag (v2f IN) : SV_Target
{
half3 col;
if(IN.rayDir.y < 0.0)
{
half eyeCos = dot(_WorldSpaceLightPos0.xyz, normalize(IN.rayDir.xyz));
half eyeCos2 = eyeCos * eyeCos;
col = getRayleighPhase(eyeCos2) * IN.cIn.xyz + getMiePhase(eyeCos, eyeCos2) * IN.cOut * _LightColor0.xyz * _SunTint * _SunStrength;
}
else
{
col = IN.cIn.xyz + _GroundColor * IN.cOut;
}
//Adjust color from HDR
col *= _HdrExposure;
return half4(col,1.0);
}
ENDCG
}
}
Fallback Off
}

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: ea3d46e265bb7184ba7aad192cbc45b5
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:

View File

@@ -0,0 +1,47 @@
Shader "Custom/SurfaceShader_VC" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Normal("Normap Map", 2D) = "bump" {}
}
SubShader{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 200
Blend One OneMinusSrcAlpha
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Normal;
struct Input {
float2 uv_MainTex;
float4 vertex : SV_POSITION;
float4 color : COLOR;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = v.color;
}
fixed4 _Color;
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*IN.color;
o.Normal = UnpackNormal(tex2D(_Normal, IN.uv_MainTex));
o.Alpha = c.a*IN.color.a;
}
ENDCG
}
FallBack "Diffuse"
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5e0b7dc1782a986469ed1446388360f5
timeCreated: 1473092108
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,356 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/Tonemapper" {
Properties {
_MainTex ("", 2D) = "black" {}
_SmallTex ("", 2D) = "grey" {}
_Curve ("", 2D) = "black" {}
}
CGINCLUDE
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
sampler2D _SmallTex;
sampler2D _Curve;
float4 _HdrParams;
float2 intensity;
float4 _MainTex_TexelSize;
float _AdaptionSpeed;
float _ExposureAdjustment;
float _RangeScale;
v2f vert( appdata_img v )
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
return o;
}
float4 fragLog(v2f i) : SV_Target
{
const float DELTA = 0.0001f;
float fLogLumSum = 0.0f;
fLogLumSum += log( Luminance(tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(-1,-1)).rgb) + DELTA);
fLogLumSum += log( Luminance(tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(1,1)).rgb) + DELTA);
fLogLumSum += log( Luminance(tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(-1,1)).rgb) + DELTA);
fLogLumSum += log( Luminance(tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(1,-1)).rgb) + DELTA);
float avg = fLogLumSum / 4.0;
return float4(avg, avg, avg, avg);
}
float4 fragExp(v2f i) : SV_Target
{
float2 lum = float2(0.0f, 0.0f);
lum += tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(-1,-1)).xy;
lum += tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(1,1)).xy;
lum += tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(1,-1)).xy;
lum += tex2D(_MainTex, i.uv + _MainTex_TexelSize.xy * float2(-1,1)).xy;
lum = exp(lum / 4.0f);
return float4(lum.x, lum.y, lum.x, saturate(0.0125 * _AdaptionSpeed));
}
float3 ToCIE(float3 FullScreenImage)
{
// RGB -> XYZ conversion
// http://www.w3.org/Graphics/Color/sRGB
// The official sRGB to XYZ conversion matrix is (following ITU-R BT.709)
// 0.4125 0.3576 0.1805
// 0.2126 0.7152 0.0722
// 0.0193 0.1192 0.9505
float3x3 RGB2XYZ = {0.5141364, 0.3238786, 0.16036376, 0.265068, 0.67023428, 0.06409157, 0.0241188, 0.1228178, 0.84442666};
float3 XYZ = mul(RGB2XYZ, FullScreenImage.rgb);
// XYZ -> Yxy conversion
float3 Yxy;
Yxy.r = XYZ.g;
// x = X / (X + Y + Z)
// y = X / (X + Y + Z)
float temp = dot(float3(1.0,1.0,1.0), XYZ.rgb);
Yxy.gb = XYZ.rg / temp;
return Yxy;
}
float3 FromCIE(float3 Yxy)
{
float3 XYZ;
// Yxy -> XYZ conversion
XYZ.r = Yxy.r * Yxy.g / Yxy. b;
// X = Y * x / y
XYZ.g = Yxy.r;
// copy luminance Y
XYZ.b = Yxy.r * (1 - Yxy.g - Yxy.b) / Yxy.b;
// Z = Y * (1-x-y) / y
// XYZ -> RGB conversion
// The official XYZ to sRGB conversion matrix is (following ITU-R BT.709)
// 3.2410 -1.5374 -0.4986
// -0.9692 1.8760 0.0416
// 0.0556 -0.2040 1.0570
float3x3 XYZ2RGB = { 2.5651,-1.1665,-0.3986, -1.0217, 1.9777, 0.0439, 0.0753, -0.2543, 1.1892};
return mul(XYZ2RGB, XYZ);
}
// NOTE/OPTIMIZATION: we're not going the extra CIE detour anymore, but
// scale with the OUT/IN luminance ratio,this is sooooo much faster
float4 fragAdaptive(v2f i) : SV_Target
{
float avgLum = tex2D(_SmallTex, i.uv).x;
float4 color = tex2D (_MainTex, i.uv);
float cieLum = max(0.000001, Luminance(color.rgb)); //ToCIE(color.rgb);
float lumScaled = cieLum * _HdrParams.z / (0.001 + avgLum.x);
lumScaled = (lumScaled * (1.0f + lumScaled / (_HdrParams.w)))/(1.0f + lumScaled);
//cie.r = lumScaled;
color.rgb = color.rgb * (lumScaled / cieLum);
//color.rgb = FromCIE(cie);
return color;
}
float4 fragAdaptiveAutoWhite(v2f i) : SV_Target
{
float2 avgLum = tex2D(_SmallTex, i.uv).xy;
float4 color = tex2D(_MainTex, i.uv);
float cieLum = max(0.000001, Luminance(color.rgb)); //ToCIE(color.rgb);
float lumScaled = cieLum * _HdrParams.z / (0.001 + avgLum.x);
lumScaled = (lumScaled * (1.0f + lumScaled / (avgLum.y*avgLum.y)))/(1.0f + lumScaled);
//cie.r = lumScaled;
color.rgb = color.rgb * (lumScaled / cieLum);
//color.rgb = FromCIE(cie);
return color;
}
float4 fragCurve(v2f i) : SV_Target
{
float4 color = tex2D(_MainTex, i.uv);
float3 cie = ToCIE(color.rgb);
// Remap to new lum range
float newLum = tex2D(_Curve, float2(cie.r * _RangeScale, 0.5)).r;
cie.r = newLum;
color.rgb = FromCIE(cie);
return color;
}
float4 fragHable(v2f i) : SV_Target
{
const float A = 0.15;
const float B = 0.50;
const float C = 0.10;
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
const float W = 11.2;
float3 texColor = tex2D(_MainTex, i.uv).rgb;
texColor *= _ExposureAdjustment;
float ExposureBias = 2.0;
float3 x = ExposureBias*texColor;
float3 curr = ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
x = W;
float3 whiteScale = 1.0f/(((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F);
float3 color = curr*whiteScale;
// float3 retColor = pow(color,1/2.2); // we have SRGB write enabled at this stage
return float4(color, 1.0);
}
// we are doing it on luminance here (better color preservation, but some other problems like very fast saturation)
float4 fragSimpleReinhard(v2f i) : SV_Target
{
float4 texColor = tex2D(_MainTex, i.uv);
float lum = Luminance(texColor.rgb);
float lumTm = lum * _ExposureAdjustment;
float scale = lumTm / (1+lumTm);
return float4(texColor.rgb * scale / lum, texColor.a);
}
float4 fragOptimizedHejiDawson(v2f i) : SV_Target
{
float4 texColor = tex2D(_MainTex, i.uv );
texColor *= _ExposureAdjustment;
float4 X = max(float4(0.0,0.0,0.0,0.0), texColor-0.004);
float4 retColor = (X*(6.2*X+.5))/(X*(6.2*X+1.7)+0.06);
return retColor*retColor;
}
float4 fragPhotographic(v2f i) : SV_Target
{
float4 texColor = tex2D(_MainTex, i.uv);
return 1-exp2(-_ExposureAdjustment * texColor);
}
float4 fragDownsample(v2f i) : SV_Target
{
float4 tapA = tex2D(_MainTex, i.uv + _MainTex_TexelSize * 0.5);
float4 tapB = tex2D(_MainTex, i.uv - _MainTex_TexelSize * 0.5);
float4 tapC = tex2D(_MainTex, i.uv + _MainTex_TexelSize * float2(0.5,-0.5));
float4 tapD = tex2D(_MainTex, i.uv - _MainTex_TexelSize * float2(0.5,-0.5));
float4 average = (tapA+tapB+tapC+tapD)/4;
average.y = max(max(tapA.y,tapB.y), max(tapC.y,tapD.y));
return average;
}
ENDCG
Subshader {
// adaptive reinhhard apply
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdaptive
ENDCG
}
// 1
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragLog
ENDCG
}
// 2
Pass {
ZTest Always Cull Off ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment fragExp
ENDCG
}
// 3
Pass {
ZTest Always Cull Off ZWrite Off
Blend Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragExp
ENDCG
}
// 4 user controllable tonemap curve
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragCurve
ENDCG
}
// 5 tonemapping in uncharted
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragHable
ENDCG
}
// 6 simple tonemapping based reinhard
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragSimpleReinhard
ENDCG
}
// 7 OptimizedHejiDawson
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragOptimizedHejiDawson
ENDCG
}
// 8 Photographic
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragPhotographic
ENDCG
}
// 9 Downsample with auto white detection
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragDownsample
ENDCG
}
// 10 adaptive reinhhard apply with auto white
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment fragAdaptiveAutoWhite
ENDCG
}
}
Fallback off
} // shader

View File

@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 3470cde901598604691cfc11b5bcf008
ShaderImporter:
userData:

View File

@@ -0,0 +1,48 @@
half frag_ao (v2f_ao i, int sampleCount, float3 samples[INPUT_SAMPLE_COUNT])
{
// read random normal from noise texture
half3 randN = tex2D (_RandomTexture, i.uvr).xyz * 2.0 - 1.0;
// read scene depth/normal
float4 depthnormal = tex2D (_CameraDepthNormalsTexture, i.uv);
float3 viewNorm;
float depth;
DecodeDepthNormal (depthnormal, depth, viewNorm);
depth *= _ProjectionParams.z;
float scale = _Params.x / depth;
// accumulated occlusion factor
float occ = 0.0;
for (int s = 0; s < sampleCount; ++s)
{
// Reflect sample direction around a random vector
half3 randomDir = reflect(samples[s], randN);
// Make it point to the upper hemisphere
half flip = (dot(viewNorm,randomDir)<0) ? 1.0 : -1.0;
randomDir *= -flip;
// Add a bit of normal to reduce self shadowing
randomDir += viewNorm * 0.3;
float2 offset = randomDir.xy * scale;
float sD = depth - (randomDir.z * _Params.x);
// Sample depth at offset location
float4 sampleND = tex2D (_CameraDepthNormalsTexture, i.uv + offset);
float sampleD;
float3 sampleN;
DecodeDepthNormal (sampleND, sampleD, sampleN);
sampleD *= _ProjectionParams.z;
float zd = saturate(sD-sampleD);
if (zd > _Params.y) {
// This sample occludes, contribute to occlusion
occ += pow(1-zd,_Params.z); // sc2
//occ += 1.0-saturate(pow(1.0 - zd, 11.0) + zd); // nullsq
//occ += 1.0/(1.0+zd*zd*10); // iq
}
}
occ /= sampleCount;
return 1-occ;
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 16319f9665e404944968f584bf7bc5eb
timeCreated: 1517183018
licenseType: Store
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant: