Unity3d "Shader" diffuse reflection
Shader"custom/ambient"{Properties {_maintex ("Base (RGB)", 2D) =" White"{} _color ("Diffuse Material Color", Color) = (1,1,1,1) _speccolor ("Specular Color", Color) = (1,1,1,1) _shininess ("shininess", Float) =Ten} subshader {Pass {tags{"Lightmode"="Forwardbase"} cgprogram#pragmaExclude_renderers Gles#pragmaVertex vert#pragmaFragment Fragsampler2d _maintex; Uniform FLOAT4 _color; Uniform FLOAT4 _speccolor; Uniformfloat_shininess; Uniform FLOAT4 _lightcolor0; structvertexinput {float2 texcoord:texcoord0; FLOAT4 vertex:position; FLOAT3 Normal:normal; }; structvertexoutput {float4 pos:sv_position; FLOAT4 Color:color; FLOAT2 texcoord:texcoord0; }; Vertexoutput Vert (Vertexinput input) {vertexoutput output; float4x4 Modelmatrix=_object2world; FLOAT3 Normaldir= Normalize (FLOAT3 (Mul (_object2world, FLOAT4 (Input.normal,0.0)))); FLOAT3 Lightdir=Normalize (FLOAT3 (_WORLDSPACELIGHTPOS0)); FLOAT3 Viewdir= Normalize (_worldspacecamerapos-FLOAT3 (Mul (_object2world,input.vertex))); floatSpecularrefection = FLOAT3 (_lightcolor0) *float3 (_speccolor) *pow (Max (0.0, Dot (Reflect (-lightdir,normaldir), Viewdir), _shininess); FLOAT3 diffusereflection= FLOAT3 (_lightcolor0) *float3 (_color) *max (0.0, Dot (normaldir,lightdir)); FLOAT3 ambientlighting= FLOAT3 (unity_lightmodel_ambient) *FLOAT3 (_color); Output.color= Float4 (Ambientlighting+diffusereflection+specularrefection,1.0); Output.pos=Mul (Unity_matrix_mvp,input.vertex); Output.texcoord=Input.texcoord; returnoutput; } float4 Frag (Vertexoutput input): COLOR {float4 col= tex2d (_maintex,input.texcoord) *_color; returninput.color*Col; } ENDCG}} FallBack"Diffuse"}
Unity3d "Shader" diffuse reflection