The transparent shader receiving the shadow.
来源:互联网 发布:域名证书在什么网查询 编辑:程序博客网 时间:2024/05/16 05:39
Shader "FX/Matte Shadow" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
Blend Zero SrcColor
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo*atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
Blend Zero SrcColor
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo*atten;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = _Color;
o.Albedo = c.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Transparent/Cutout/VertexLit"
}
Transparent shader that accepts the shadow
Shader "GreenArch/Transparent Plane Shadow2" { Properties { } SubShader { Tags { "RenderType"="Opaque" } Pass { Name "DEFERRED" Tags { "LightMode"="Deferred" } CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_DEFERRED #include "UnityCG.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma fragmentoption ARB_precision_hint_fastest #pragma multi_compile_shadowcaster #pragma multi_compile ___ UNITY_HDR_ON #pragma multi_compile_fog #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 #pragma target 3.0 struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; }; struct VertexOutput { float4 pos : SV_POSITION; float4 posWorld : TEXCOORD0; float3 normalDir : TEXCOORD1; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.normalDir = UnityObjectToWorldNormal(v.normal); o.posWorld = mul(unity_ObjectToWorld, v.vertex); o.pos = mul(UNITY_MATRIX_MVP, v.vertex ); return o; } void frag( VertexOutput i, out half4 outDiffuse : SV_Target0, out half4 outSpecSmoothness : SV_Target1, out half4 outNormal : SV_Target2, out half4 outEmission : SV_Target3 ) { i.normalDir = normalize(i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 normalDirection = i.normalDir; float3 viewReflectDirection = reflect( -viewDirection, normalDirection );////// Lighting: float3 finalColor = 0; outDiffuse = half4( 0, 0, 0, 1 ); outSpecSmoothness = half4(0,0,0,0); outNormal = half4( normalDirection * 0.5 + 0.5, 1 ); outEmission = half4(0,0,0,1); #ifndef UNITY_HDR_ON outEmission.rgb = exp2(-outEmission.rgb); #endif } ENDCG } Pass { Name "FORWARD" Tags { "LightMode"="ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #define UNITY_PASS_FORWARDBASE #include "UnityCG.cginc" #include "UnityPBSLighting.cginc" #include "UnityStandardBRDF.cginc" #pragma multi_compile_fwdbase_fullshadows #pragma multi_compile_fog #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 #pragma target 3.0 struct VertexInput { float4 vertex : POSITION; float3 normal : NORMAL; }; struct VertexOutput { float4 pos : SV_POSITION; float4 posWorld : TEXCOORD0; float3 normalDir : TEXCOORD1; UNITY_FOG_COORDS(2) }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.normalDir = UnityObjectToWorldNormal(v.normal); o.posWorld = mul(unity_ObjectToWorld, v.vertex); o.pos = mul(UNITY_MATRIX_MVP, v.vertex ); UNITY_TRANSFER_FOG(o,o.pos); return o; } float4 frag(VertexOutput i) : COLOR { i.normalDir = normalize(i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); float3 normalDirection = i.normalDir; float3 viewReflectDirection = reflect( -viewDirection, normalDirection );////// Lighting: float3 finalColor = 0; fixed4 finalRGBA = fixed4(finalColor,1); UNITY_APPLY_FOG(i.fogCoord, finalRGBA); return finalRGBA; } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector"}
//This is based on a shader from https://alastaira.wordpress.com/2014/12/30/adding-shadows-to-a-unity-vertexfragment-shader-in-7-easy-steps/Shader "Custom/MobileARShadow"{ SubShader { Pass { // 1.) This will be the base forward rendering pass in which ambient, vertex, and // main directional light will be applied. Additional lights will need additional passes // using the "ForwardAdd" lightmode. // see: http://docs.unity3d.com/Manual/SL-PassTags.html Tags { "LightMode" = "ForwardBase" "RenderType"="Opaque" "Queue"="Geometry+1" "ForceNoShadowCasting"="True" }LOD 150Blend Zero SrcColorZWrite On CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" // 2.) This matches the "forward base" of the LightMode tag to ensure the shader compiles // properly for the forward bass pass. As with the LightMode tag, for any additional lights // this would be changed from _fwdbase to _fwdadd. #pragma multi_compile_fwdbase // 3.) Reference the Unity library that includes all the lighting shadow macros #include "AutoLight.cginc" struct v2f { float4 pos : SV_POSITION; // 4.) The LIGHTING_COORDS macro (defined in AutoLight.cginc) defines the parameters needed to sample // the shadow map. The (0,1) specifies which unused TEXCOORD semantics to hold the sampled values - // As I'm not using any texcoords in this shader, I can use TEXCOORD0 and TEXCOORD1 for the shadow // sampling. If I was already using TEXCOORD for UV coordinates, say, I could specify // LIGHTING_COORDS(1,2) instead to use TEXCOORD1 and TEXCOORD2. LIGHTING_COORDS(0,1) }; v2f vert(appdata_base v) { v2f o; o.pos = UnityObjectToClipPos (v.vertex); // 5.) The TRANSFER_VERTEX_TO_FRAGMENT macro populates the chosen LIGHTING_COORDS in the v2f structure // with appropriate values to sample from the shadow/lighting map TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } fixed4 frag(v2f i) : COLOR { // 6.) The LIGHT_ATTENUATION samples the shadowmap (using the coordinates calculated by TRANSFER_VERTEX_TO_FRAGMENT // and stored in the structure defined by LIGHTING_COORDS), and returns the value as a float. float attenuation = LIGHT_ATTENUATION(i); return fixed4(1.0,1.0,1.0,1.0) * attenuation; } ENDCG } } // 7.) To receive or cast a shadow, shaders must implement the appropriate "Shadow Collector" or "Shadow Caster" pass. // Although we haven't explicitly done so in this shader, if these passes are missing they will be read from a fallback // shader instead, so specify one here to import the collector/caster passes used in that fallback. Fallback "VertexLit"}
阅读全文
0 0
- The transparent shader receiving the shadow.
- How to SetUp The Receiving Transaction Manager
- ICF Error when receiving the response: ICM_HTTP_SSL_ERROR
- Hide in the shadow
- The Shadow over Firefox
- the shadow of pv3d (test7)
- The x86 kvm shadow mmu
- Shader Learing(Transparent Shader篇)
- the differences between transparent, pooled, and cluster tables
- When the Opposite of Transparent isn't Opaque
- CISCO switches change the VTP modeautomatically from client to transparent
- The Theory of Stencil Shadow Volumes
- What the Heck is Shadow DOM?
- 阴影介绍 the introduction of shadow
- Shader Effects: Shadow Mapping
- RFC6455-The WebSocket protocol 之七:6. Sending and Receiving Data
- Android: Receiving Data from the Send Intent,将自己的app注册系统分享
- How Many Processes Should Be Set For The Receiving Transaction Manager (RTM)
- qt下载
- Spring Boot 配置文件
- linux---libcurl
- maven-tomcat热部署和本地部署方式的区别
- restFUL架构详解
- The transparent shader receiving the shadow.
- json初级
- Java通过几种经典的算法来实现数组排序
- 数据结构03 队列
- 四层树状数据展示,无样式
- 移动端车牌OCR识别
- UVA 159 Word Crosses
- [自用门户]门户飘窗功能代码,加在最底部,body标签内就行
- Ubuntu操作redis主从复制(读写分离)