diff options
Diffstat (limited to 'Assets/Bundle/Shaders')
-rw-r--r-- | Assets/Bundle/Shaders/Common/Image/ImageEffect.cginc | 17 | ||||
-rw-r--r-- | Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader | 4 | ||||
-rw-r--r-- | Assets/Bundle/Shaders/Common/common_gbuffer.shader | 175 | ||||
-rw-r--r-- | Assets/Bundle/Shaders/Include.meta | 8 | ||||
-rw-r--r-- | Assets/Bundle/Shaders/Unit/Effect.meta | 8 |
5 files changed, 128 insertions, 84 deletions
diff --git a/Assets/Bundle/Shaders/Common/Image/ImageEffect.cginc b/Assets/Bundle/Shaders/Common/Image/ImageEffect.cginc index 04334ee4..7f657e59 100644 --- a/Assets/Bundle/Shaders/Common/Image/ImageEffect.cginc +++ b/Assets/Bundle/Shaders/Common/Image/ImageEffect.cginc @@ -1,4 +1,4 @@ -// UnitLensEffect效果 +// UnitLensEffect效果相关 sampler2D _MainTex; float4 _MainTex_ST; @@ -16,3 +16,18 @@ sampler2D _UnitMotionVectorTexture; float4 _UnitMotionVectorTexture_ST; float4 _UnitTileOffset; + +// functions + +// 只对一小部分进行后处理 +float4 CalculateUnitTillOfssetVertex(float4 vert) +{ + float4 v = float4(vert.xy * _UnitTileOffset.xy + _UnitTileOffset.zw, 0, 1); + v.xy = v.xy * 2 - float2(1,1); + return v; +} + +fixed2 CalculateUnitTillOfssetUV(fixed2 uv0) +{ + return uv0 * _UnitTileOffset.xy + _UnitTileOffset.zw; +} diff --git a/Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader b/Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader index 2246fda2..16ec6fe7 100644 --- a/Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader +++ b/Assets/Bundle/Shaders/Common/Image/common_img_motionblur.shader @@ -48,8 +48,8 @@ Shader "Erika/Common/Image/MotionBlur" v2f vert(appdata_img v) { v2f o; - o.vertex = UnityObjectToClipPos(v.vertex); - o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); + o.vertex = CalculateUnitTillOfssetVertex(v.vertex); + o.uv = CalculateUnitTillOfssetUV(TRANSFORM_TEX(v.texcoord, _MainTex)); return o; } diff --git a/Assets/Bundle/Shaders/Common/common_gbuffer.shader b/Assets/Bundle/Shaders/Common/common_gbuffer.shader index 485a52c1..c682d8fa 100644 --- a/Assets/Bundle/Shaders/Common/common_gbuffer.shader +++ b/Assets/Bundle/Shaders/Common/common_gbuffer.shader @@ -1,68 +1,113 @@ 锘縎hader "Erika/Common/GBuffer"
{
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 100
-
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "UnityCG.cginc"
-
- struct appdata
- {
- float3 vertex : POSITION;
- float3 normal : NORMAL;
- float3 tangent : TANGENT;
- float2 uv : TEXCOORD0;
- };
-
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float3 normal : TEXCOORD1;
- float3 worldPos : TEXCOORD2;
- float4 vertex : SV_POSITION;
- };
-
- struct Output
- {
- float4 diffuse : SV_Target0;
- float4 normal : SV_Target1;
- float4 position : SV_Target2;
- float4 texCoord : SV_Target3;
- };
-
- sampler2D _MainTex;
- float4 _MainTex_ST;
-
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
- o.worldPos = mul(unity_ObjectToWorld, float4(v.vertex, 1)).xyz;
- return o;
- }
-
- Output frag (v2f i)
- {
- Output o;
- fixed4 col = tex2D(_MainTex, i.uv);
- o.diffuse = fixed4(1,0,0,1);
- o.normal = fixed4(1,1,0,1);
- o.position = fixed4(i.worldPos, 1);
- return o;
- }
- ENDCG
- }
- }
+ //unity鍙傛暟鍏ュ彛 + Properties + { + _MainTex("璐村浘",2D) = "white"{} + _Diffuse("婕弽灏",Color) = (1,1,1,1) + _Specular("楂樺厜鑹",Color) = (1,1,1,1) + _Gloss("骞虫粦搴",Range(1,100)) = 50 + } + + SubShader + { + //闈為忔槑闃熷垪 + Tags { "RenderType" = "Opaque" } + LOD 100 + //寤惰繜娓叉煋 + Pass + { + //璁剧疆 鍏夌収妯″紡涓哄欢杩熸覆鏌 + Tags{"LightMode" = "Deferred"} + CGPROGRAM + // 澹版槑椤剁偣鐫鑹插櫒銆佺墖鍏冪潃鑹插櫒鍜岃緭鍑虹洰鏍 + #pragma target 3.0 + #pragma vertex vert + #pragma fragment frag + //鎺掗櫎涓嶆敮鎸丮RT鐨勭‖浠 + //#pragma exclude_renderers norm + // unity 鍑芥暟搴 + #include"UnityCG.cginc" + //瀹氫箟UNITY_HDR_ON鍏抽敭瀛 + //鍦╟# 涓 Shader.EnableKeyword("UNITY_HDR_ON"); Shader.DisableKeyword("UNITY_HDR_ON"); + // 璁惧畾hdr鏄惁寮鍚 + #pragma multi_compile __ UNITY_HDR_ON + // 璐村浘 + sampler2D _MainTex; + // 棰樺浘uv澶勭悊 + float4 _MainTex_ST; + // 婕弽灏勫厜 + float4 _Diffuse; + // 楂樺厜 + float4 _Specular; + // 骞虫粦搴 + float _Gloss; + // 椤剁偣娓叉煋鍣ㄦ墍浼犲叆鐨勫弬鏁扮粨鏋勶紝鍒嗗埆鏄《鐐逛綅缃佹硶绾夸俊鎭乽v鍧愭爣 + struct a2v + { + float4 pos:POSITION; + float3 normal:NORMAL; + float2 uv:TEXCOORD0; + }; + // 鐗囧厓娓叉煋鍣ㄦ墍闇鐨勪紶鍏ュ弬鏁扮粨鏋勶紝鍒嗗埆鏄儚绱犱綅缃乽v鍧愭爣銆佸儚绱犱笘鐣屼綅缃佸儚绱犱笘鐣屾硶绾 + struct v2f + { + float4 pos:SV_POSITION; + float2 uv : TEXCOORD0; + float3 worldPos:TEXCOORD1; + float3 worldNormal:TEXCOORD2; + }; + // 寤惰繜娓叉煋鎵闇鐨勮緭鍑虹粨鏋勩傛鍚戞覆鏌撳彧闇瑕佽緭鍑1涓猅arget锛岃屽欢杩熸覆鏌撶殑鐗囧厓闇瑕佽緭鍑4涓猅arget + struct DeferredOutput + { + //// RGB瀛樺偍婕弽灏勯鑹诧紝A閫氶亾瀛樺偍閬僵 + //float4 gBuffer0:SV_TARGET0; + //// RGB瀛樺偍楂樺厜锛堥暅闈級鍙嶅皠棰滆壊锛孉閫氶亾瀛樺偍楂樺厜鍙嶅皠鐨勬寚鏁伴儴鍒嗭紝涔熷氨鏄钩婊戝害 + //float4 gBuffer1:SV_TARGET1; + //// RGB閫氶亾瀛樺偍涓栫晫绌洪棿娉曠嚎锛孉閫氶亾娌$敤 + //float4 gBuffer2:SV_TARGET2; + //// Emission + lighting + lightmaps + reflection probes (楂樺姩鎬佸厜鐓ф覆鏌/浣庡姩鎬佸厜鐓ф覆鏌)鐢ㄤ簬瀛樺偍鑷彂鍏+lightmap+鍙嶅皠鎺㈤拡娣卞害缂撳啿鍜屾ā鏉跨紦鍐 + //float4 gBuffer3:SV_TARGET3; + float4 normal : SV_TARGET0; + float4 position : SV_TARGET1; + }; + // 椤剁偣娓叉煋鍣 + v2f vert(a2v v) + { + v2f o; + // 鑾峰彇瑁佸壀绌洪棿涓嬬殑椤剁偣鍧愭爣 + o.pos = UnityObjectToClipPos(v.pos); + // 搴旂敤uv璁剧疆锛岃幏鍙栨纭殑uv + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + // 鑾峰彇椤剁偣鐨勪笘鐣屽潗鏍 + o.worldPos = mul(unity_ObjectToWorld, v.pos).xyz; + // 鑾峰彇涓栫晫鍧愭爣涓嬬殑娉曠嚎 + o.worldNormal = UnityObjectToWorldNormal(v.normal); + return o; + } + // 鐗囧厓鐫鑹插櫒 + DeferredOutput frag(v2f i) + { + DeferredOutput o; + //// 鍍忕礌棰滆壊 = 璐村浘棰滆壊 * 婕弽灏勯鑹 + //fixed3 color = tex2D(_MainTex, i.uv).rgb * _Diffuse.rgb; + //// 榛樿浣跨敤楂樺厜鍙嶅皠杈撳嚭锛侊紒 + //o.gBuffer0.rgb = color; // RGB瀛樺偍婕弽灏勯鑹诧紝A閫氶亾瀛樺偍閬僵 + //o.gBuffer0.a = 1; // 婕弽灏勭殑閫忔槑搴 + //o.gBuffer1.rgb = _Specular.rgb; // RGB瀛樺偍楂樺厜锛堥暅闈級鍙嶅皠棰滆壊锛 + //o.gBuffer1.a = _Gloss / 100; // 楂樺厜锛堥暅闈級鍙嶅皠棰滆壊 鐨 + //o.gBuffer2 = float4(i.worldNormal * 0.5 + 0.5, 1); // RGB閫氶亾瀛樺偍涓栫晫绌洪棿娉曠嚎锛孉閫氶亾娌$敤 + //// 濡傛灉娌″紑鍚疕DR锛岃缁欓鑹茬紪鐮佽浆鎹竴涓嬫暟鎹甧xp2锛屽悗闈㈠湪lightpass2閲屽垯鏄繘琛岃В鐮乴og2 + //#if !defined(UNITY_HDR_ON) + // color.rgb = exp2(-color.rgb); + //#endif + //// Emission + lighting + lightmaps + reflection probes (楂樺姩鎬佸厜鐓ф覆鏌/浣庡姩鎬佸厜鐓ф覆鏌)鐢ㄤ簬瀛樺偍鑷彂鍏+lightmap+鍙嶅皠鎺㈤拡娣卞害缂撳啿鍜屾ā鏉跨紦鍐 + //o.gBuffer3 = fixed4(color, 1); + o.normal = float4(i.worldNormal * 0.5 + 0.5, 1); + o.position = float4(i.worldPos, 1); + return o; + } + ENDCG + } + } }
diff --git a/Assets/Bundle/Shaders/Include.meta b/Assets/Bundle/Shaders/Include.meta deleted file mode 100644 index 2666365a..00000000 --- a/Assets/Bundle/Shaders/Include.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: dc32af12c5122994d8791378227adeb6 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Bundle/Shaders/Unit/Effect.meta b/Assets/Bundle/Shaders/Unit/Effect.meta deleted file mode 100644 index 7df9a033..00000000 --- a/Assets/Bundle/Shaders/Unit/Effect.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 9cc4684b9f432f149b16a51f148c9490 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: |