游戏

游戏人生

Unity3d-模型描边和混色Shader

游戏中很常见的一个模型描边shader,不用自己写,话不多说祭出Shader利器Shader Forge

用一个Cube测试效果:

编辑界面:

游戏中实际效果:


生成代码:

// Shader created with Shader Forge v1.03 
// Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.03;sub:START;pass:START;ps:flbk:,lico:0,lgpr:1,nrmq:1,limd:1,uamb:False,mssp:True,lmpd:False,lprd:False,rprd:False,enco:False,frtr:True,vitr:True,dbil:False,rmgx:True,rpth:0,hqsc:False,hqlp:False,tesm:0,blpr:0,bsrc:0,bdst:1,culm:0,dpts:2,wrdp:True,dith:2,ufog:True,aust:True,igpj:False,qofs:0,qpre:1,rntp:1,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,ofsf:0,ofsu:0,f2p0:False;n:type:ShaderForge.SFN_Final,id:7889,x:33392,y:32570,varname:node_7889,prsc:2|emission-321-OUT,olwid-8727-OUT,olcol-323-RGB;n:type:ShaderForge.SFN_Color,id:323,x:32871,y:32990,ptovrint:False,ptlb:outlineColor,ptin:_outlineColor,varname:_outlineColor,prsc:2,glob:False,c1:0,c2:0,c3:0,c4:1;n:type:ShaderForge.SFN_Slider,id:8727,x:33003,y:32847,ptovrint:False,ptlb:outlineWidth,ptin:_outlineWidth,varname:_outlineWidth,prsc:2,min:0,cur:0.03418804,max:1;n:type:ShaderForge.SFN_Tex2d,id:3435,x:32935,y:32450,ptovrint:False,ptlb:mainTexture,ptin:_mainTexture,varname:_mainTexture,prsc:2,tex:3d403fe3184a448fa8bc190c7f07f28c,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Color,id:8677,x:32904,y:32704,ptovrint:False,ptlb:tintColor,ptin:_tintColor,varname:_tintColor,prsc:2,glob:False,c1:1,c2:0.05862069,c3:0,c4:1;n:type:ShaderForge.SFN_Multiply,id:321,x:33171,y:32668,varname:node_321,prsc:2|A-3435-RGB,B-8677-RGB;proporder:8727-323-3435-8677;pass:END;sub:END;*/

Shader "Shader Forge/NewShader" {
    Properties {
        _outlineWidth ("outlineWidth", Range(0, 1)) = 0.03418804
        _outlineColor ("outlineColor", Color) = (0,0,0,1)
        _mainTexture ("mainTexture", 2D) = "white" {}
        _tintColor ("tintColor", Color) = (1,0.05862069,0,1)
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
            Name "Outline"
            Tags {
            }
            Cull Front
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma multi_compile_shadowcaster
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0
            uniform float4 _outlineColor;
            uniform float _outlineWidth;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float4 screenPos : TEXCOORD0;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.pos = mul(UNITY_MATRIX_MVP, float4(v.vertex.xyz + v.normal*_outlineWidth,1));
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {
                return fixed4(_outlineColor.rgb,0);
            }
            ENDCG
        }
        Pass {
            Name "ForwardBase"
            Tags {
                "LightMode"="ForwardBase"
            }
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma exclude_renderers xbox360 ps3 flash d3d11_9x 
            #pragma target 3.0

            uniform sampler2D _mainTexture; uniform float4 _mainTexture_ST;
            uniform float4 _tintColor;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 screenPos : TEXCOORD1;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                return o;
            }
            fixed4 frag(VertexOutput i) : COLOR {

                float4 _mainTexture_var = tex2D(_mainTexture,TRANSFORM_TEX(i.uv0, _mainTexture));
                float3 emissive = (_mainTexture_var.rgb*_tintColor.rgb);
                float3 finalColor = emissive;
                return fixed4(finalColor,1);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    CustomEditor "ShaderForgeMaterialInspector"
}




阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cabxyz/article/details/44411385
个人分类: unity3d code
所属专栏: Unity3d语言基础
想对作者说点什么? 我来说一句

unity描边shader

2015年12月24日 4KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭