拼接后的纹理:
正常的草地(不进行WRAP寻址):
WRAP = 5时的情况:
MinFilter = Linear时的情况:
shader实现:
float4x4 matViewProjection; float4 Light_Position; float4 Light_Attenuation; float4 Light_Color; float4 Ambient_Color; float4 vViewPosition; float alpha;
struct VS_INPUT { float4 Position : POSITION0; float3 Normal : NORMAL0; float2 Texcoord : TEXCOORD0; };
struct VS_OUTPUT { float4 Position : POSITION0; float2 Texcoord : TEXCOORD0; float4 Color : COLOR0; };
float4 PointLighting(float3 position, float3 normal , float3 eyedir, float4 ambient , float3 lightpos, float3 lightatt, float4 lightcolor) { float3 lightdir = normalize(position - lightpos); float3 dis = distance(position, lightpos); float disatt = saturate(1 / ( lightatt.x lightatt.y * dis lightatt.z * dis * dis )); float angleatt = saturate(-lightdir * normal); float3 reflectdir = normalize(reflect(lightdir, normal)); float specularatt = pow(saturate(reflectdir * eyedir), alpha); return ambient lightcolor * disatt * (angleatt specularatt); }
VS_OUTPUT vs_main( VS_INPUT Input ) { VS_OUTPUT Output;
Output.Position = mul( Input.Position, matViewProjection ); Output.Texcoord = Input.Texcoord; float3 eyedir = normalize(vViewPosition - Input.Position); Output.Color = PointLighting(Input.Position, Input.Normal , eyedir, Ambient_Color , Light_Position, Light_Attenuation, Light_Color);
return( Output ); }
Reference:
ShaderX3 : Improved Batching via Texture Atlases