使用landscape时,抓帧结果中,有一张法线贴图(不单是法线,四通道包含混合信息)。同样的图,使用了两个采样器采样。
一次采样是在landscape对应的ush文件中(LandscapeVertexFactory.ush)
float3x3 VertexFactoryGetPerPixelTangentBasis(FVertexFactoryInterpolantsVSToPS Interpolants)
{
float3x3 Result;
#if PIXELSHADER || RAYHITGROUPSHADER || COMPUTESHADER
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM4
float4 SampleValue = Texture2DSample(LandscapeParameters.NormalmapTexture, LandscapeParameters.NormalmapTextureSampler, Interpolants.WeightHeightMapTexCoord.zw);
#else
float4 SampleValue = Texture2DSample(LandscapeParameters.NormalmapTexture, LandscapeParameters.NormalmapTextureSampler, Interpolants.WeightMapTexCoord);
#endif
#if WEBGL
float2 SampleNormal = float2(SampleValue.b, SampleValue.a) * float2(2.0,2.0) - float2(1.0,1.0);
#else
float2 SampleNormal = float2(SampleValue.b, SampleValue.a) * float2(2.0,2.0) - float2(1.0,1.0);
#endif
float3 WorldNormal = float3( SampleNormal, sqrt(max(1.0-dot(SampleNormal,SampleNormal),0.0)) );
Result = CalcTangentBasisFromWorldNormal(WorldNormal);
#endif
return Result;
}
只要使用了 LandscapeParameters.NormalmapTexture,将会产生一次采样。这是在FLandscapeComponentSceneProxy 中声明的LandscapeUniformShaderParameters参数。在cpu层,FLandscapeComponentSceneProxy::OnTransformChanged()中指定初始化。
另外一次采样是发生成材质结点中,使用了Layer Blend结点后,将会产生另外一次采样。虽然是相同的图,但是采样器却是另外一个。
当landscape的地面效果复杂,导至采样器不够用时,这里或许可以优化。统一成一个采样器。