纳金网

标题: 可以做镜头景深效果的shard-1 [打印本页]

作者: 晃晃    时间: 2011-9-8 08:14
标题: 可以做镜头景深效果的shard-1
Shader "Hidden/Render DOF Factor" {
Properties {

_MainTex ("Base", 2D) = "white" {}

_Cutoff ("Cutoff", float) = 0.5

}
// Helper code used in all of the below subshaders

CGINCLUDE

struct v2f {

float4 pos : POSITION;

float depth : TEXCOORD0;

};

struct v2f_uv {

float4 pos : POSITION;

float2 uv : TEXCOORD0;

float depth : TEXCOORD1;

};

uniform float4 _FocalParams;

half DOFFactor( float z ) {

float focalDist = _FocalParams.x;

float invRange = _FocalParams.w;

float fromFocal = z - focalDist;

if( fromFocal < 0.0 )

  fromFocal *= 4.0;

return saturate( abs( fromFocal ) * invRange );

}

uniform sampler2D _MainTex;

uniform float _Cutoff;

half4 frag(v2f i) : COLOR {

return DOFFactor(i.depth);

}

half4 frag_uv(v2f_uv i) : COLOR {

half4 texcol = tex2D( _MainTex, i.uv );

clip( texcol.a - _Cutoff );

return DOFFactor(i.depth);

}

ENDCG
Category {

Fog { Mode Off }



// regular opaque objects

SubShader {

  Tags { "RenderType"="Opaque" }

  Pass {

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"

v2f vert( appdata_base v ) {

v2f o;

o.pos = mul(glstate.matrix.mvp, v.vertex);

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG

  }

}



// transparent cutout objects

SubShader {

  Tags { "RenderType"="TransparentCutout" }

  Pass {

   Cull Off

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag_uv

#include "UnityCG.cginc"

v2f_uv vert( appdata_base v ) {

v2f_uv o;

o.pos = mul(glstate.matrix.mvp, v.vertex);

o.uv = v.texcoord;

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG
  }

}



// terrain tree bark

SubShader {

  Tags { "RenderType"="TreeOpaque" }

  Pass {

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"

#include "TerrainEngine.cginc"

struct appdata {

    float4 vertex : POSITION;

    float4 color : COLOR;

};

v2f vert( appdata v ) {

v2f o;

TerrainAnimateTree(v.vertex, v.color.w);

o.pos = mul( glstate.matrix.mvp, v.vertex );

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG

  }

}



// terrain tree leaves

SubShader {

  Tags { "RenderType"="TreeTransparentCutout" }

  Pass {

   Cull Off

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag_uv

#include "UnityCG.cginc"

#include "TerrainEngine.cginc"

struct appdata {

    float4 vertex : POSITION;

    float4 color : COLOR;

    float4 texcoord : TEXCOORD0;

};

v2f_uv vert( appdata v ) {

v2f_uv o;

TerrainAnimateTree(v.vertex, v.color.w);

o.pos = mul( glstate.matrix.mvp, v.vertex );

o.uv = v.texcoord;

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG

  }

}



// terrain tree billboards

SubShader {

  Tags { "RenderType"="TreeBillboard" }

  Pass {

   Cull Off

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag_tree

#include "UnityCG.cginc"

#include "TerrainEngine.cginc"

struct appdata {

    float4 vertex : POSITION;

    float4 color : COLOR;

    float4 texcoord : TEXCOORD0;

};

v2f_uv vert( appdata_tree_billboard v ) {

v2f_uv o;

TerrainBillboardTree(v.vertex, v.texcoord1.xy);

o.pos = mul( glstate.matrix.mvp, v.vertex );

o.uv = v.texcoord;

COMPUTE_EYEDEPTH(o.depth);

return o;

}

half4 frag_tree(v2f_uv i) : COLOR {

half4 texcol = tex2D( _MainTex, i.uv );

clip( texcol.a - 0.5 );

return DOFFactor(i.depth);

}

ENDCG

  }

}



// terrain grass billboards

SubShader {

  Tags { "RenderType"="GrassBillboard" }

  Pass {

   Cull Off

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag_uv

#pragma multi_compile NO_INTEL_GMA_X3100_WORKAROUND INTEL_GMA_X3100_WORKAROUND

#include "UnityCG.cginc"

#include "TerrainEngine.cginc"
v2f_uv vert (appdata_grass v) {

v2f_uv o;

TerrainBillboardGrass(v.vertex, v.texcoord1.xy);

float waveAmount = v.texcoord1.y;

float4 dummyColor = 0;

TerrainWaveGrass (v.vertex, waveAmount, dummyColor, dummyColor);

o.pos = mul (glstate.matrix.mvp, v.vertex);

o.uv = v.texcoord;

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG

  }

}



// terrain grass non-billboards

SubShader {

  Tags { "RenderType"="Grass" }

  Pass {

   Cull Off

  

CGPROGRAM

#pragma vertex vert

#pragma fragment frag_uv

#pragma multi_compile NO_INTEL_GMA_X3100_WORKAROUND INTEL_GMA_X3100_WORKAROUND

#include "UnityCG.cginc"

#include "TerrainEngine.cginc"
v2f_uv vert (appdata_grass v) {

v2f_uv o;

float waveAmount = v.color.a * _WaveAndDistance.z;

float4 dummyColor = 0;

TerrainWaveGrass (v.vertex, waveAmount, dummyColor, dummyColor);

o.pos = mul (glstate.matrix.mvp, v.vertex);

o.uv = v.texcoord;

COMPUTE_EYEDEPTH(o.depth);

return o;

}

ENDCG

  }

}



}

}
作者: Asen    时间: 2011-9-8 09:27

作者: tc    时间: 2012-2-9 23:20
不错哦,顶一下......

作者: 菜刀吻电线    时间: 2012-2-12 23:18
灌水。。。

作者: C.R.CAN    时间: 2012-2-16 23:29
顶!学习了!阅!

作者: 菜刀吻电线    时间: 2012-3-19 23:23
先垫一块,再说鸟

作者: C.R.CAN    时间: 2012-6-3 23:21
楼主收集的可真全哦

作者: 晃晃    时间: 2012-8-22 00:21
我是老实人,我来也!

作者: 奇    时间: 2012-10-19 23:26
有意思!学习了!

作者: 菜刀吻电线    时间: 2013-2-14 23:20
我看看就走,你们聊!

作者: 菜刀吻电线    时间: 2013-2-24 23:34
顶!学习了!阅!





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5