Billboard Shader

1、alpha blend need to turn off zwrite, or tansparent object will cut off opaque object behind, 

in this case, you can not get effect you want to realize. so, pay attention to the render sequence of objects

2、about DisableBatching tag, unity official explain

//code ( unity version5.4.0)

Shader"billboard"{

Properties{

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

_ScaleX ("ScaleX",Float) =1.0

_ScaleY ("ScaleY",Float) =1.0

//_Pos("Poscenter",Vector)=(0,0,0,0)

_Scope("Scope",float) =2.0

//_Color("Color",color)=(1,1,1,1)

_Random("Random",Range(-1,1)) =0.5

}

SubShader{

Tags{"Queue"="Transparent""RenderType"="Opaque""DisableBatching"="True"}

LOD200

//Lightingoff

//BlendoneOneMinusSrcAlpha

BlendSrcAlphaOneMinusSrcAlpha

//ZWriteoff

ZWriteon

ZTestLEqual

//BlendDstColorZero

//AlphaTestLess1

Pass{

//

//CUlloff

//ZWriteon

CGPROGRAM

#pragmavertexvert

#pragmafragmentfrag

//User-specifieduniforms

uniformsampler2D_MainTex;

uniformfloat_ScaleX;

uniformfloat_ScaleY;

//float4_Pos;

float_Scope;

float_Random;

//half4_Color;

structvertexInput {

float4vertex: POSITION;

float4tex :TEXCOORD0;

};

structvertexOutput {

float4pos : SV_POSITION;

float4tex :TEXCOORD0;

};

vertexOutput vert(vertexInput input)

{

vertexOutput output;

output.pos =mul(UNITY_MATRIX_P,

mul(UNITY_MATRIX_MV,float4(0.0,0.5, input.vertex.z,1.0))

+float4(input.vertex.x, input.vertex.y,0.0,0.0)

*float4(_ScaleX, _ScaleY,1.0,1.0) );

//mul(p,mul(mv,pos1)+pos2);

//floatdis=distance(input.vertex,_Pos);

//input.vertex.y=sin(dis+_Time.y*_Speed)*_Pos.w;

//output.tex.x=input.vertex.y;

//output.pos=mul(UNITY_MATRIX_MVP,input.vertex);

//floatoffsetY=sin(output.pos.y+_Time.y)*_Scope;

floatoffsetY =sin((output.pos.x+output.pos.z)+_Time.y)*_Scope;

if(output.pos.y>0)

output.pos.xyz =float3(output.pos.x+offsetY, output.pos.y, output.pos.z);

//else

//output.pos.xyz=float3(output.pos.x+offsetY,output.pos.y,output.pos.z);

//input.tex.w=input.tex.w*_CutOff;

output.tex = input.tex;

returnoutput;

}

half4frag(vertexOutput input) :COLOR

{

returntex2D(_MainTex,float2(input.tex.xy));

//return_Color*input.tex.x;

}

ENDCG

}

}

}

你可能感兴趣的:(Billboard Shader)