• Shader 1:能接受阴影的透明shader


    第一次接触Shader,项目需要,直接说需求吧,需要一个透明并且能接受阴影的shader。unity系统自带的shader已经满足不了了。上一段代码吧

    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"
    }
  • 相关阅读:
    Maven打包时过滤测试代码或指定特定的测试类(maven-surefire-plugin)
    Maven项目配置外部依赖(本地依赖)
    手把手教你创建「人物角色Persona」
    微服务与Docker介绍
    深入学习微框架:Spring Boot
    技术干货:我们的项目是如何技术选型的
    为什么选择Spring Boot作为微服务的入门级微框架
    Android Material Design 兼容库的使用详解
    Android 实现QQ、微信、新浪微博和百度第三方登录
    Android ijkplayer详解使用教程
  • 原文地址:https://www.cnblogs.com/leeplogs/p/7327488.html
Copyright © 2020-2023  润新知