标签:surface utf-8 version map yuv htm 添加 ack stat
//inherits "normalMap.frag" USE_TEXTURE2D(tDetailNormalMap); USE_TEXTURE2D(tDetailWeightMap); uniform float uDetailWeight; uniform vec4 uDetailTiling; //xy-scale, zw-offset uniform vec4 uDetailWeightSwizzle; uniform float uDetailUseSecondaryUV; //0.0 - use primary uv, 1.0 - use secondary uniform vec3 uDetailNormalMapScale; //typically 2,2,2 uniform vec3 uDetailNormalMapBias; //typically -1,-1,-1 void SurfaceDetailNormalMap( inout FragmentState s ) { SurfaceNormalMap(s); //look up detail normal vec2 uv = lerp( s.vertexTexCoord.xy, s.vertexTexCoordSecondary.xy, uDetailUseSecondaryUV ); uv = uv*uDetailTiling.xy + uDetailTiling.zw; vec3 dn = texture2D( tDetailNormalMap, uv ).xyz; dn = uDetailNormalMapScale*dn + uDetailNormalMapBias; //ortho-normalization of new tangent basis vec3 T = s.vertexTangent; vec3 B = s.vertexBitangent; vec3 N = s.normal; T -= dot(T,N)*N; T = normalize(T); B -= dot(B,N)*N + dot(B,T)*T; B = normalize(B); //blend in the detail normal dn = dn.x * T + dn.y * B + dn.z * N; float detailWeight = dot( texture2D( tDetailWeightMap, s.vertexTexCoord ), uDetailWeightSwizzle ); detailWeight *= uDetailWeight; s.normal = normalize( s.normal + dn * detailWeight ); } #undef Surface #define Surface SurfaceDetailNormalMap
unity.shader:
#ifdef _NORMALMAP half3 NormalInTangentSpace(float4 texcoords) { half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, texcoords.xy), _BumpScale); #if _DETAIL && defined(UNITY_ENABLE_DETAIL_NORMALMAP) half mask = DetailMask(texcoords.xy); half3 detailNormalTangent = UnpackScaleNormal(tex2D (_DetailNormalMap, texcoords.zw), _DetailNormalMapScale); #if _DETAIL_LERP normalTangent = lerp( normalTangent, detailNormalTangent, mask); #else normalTangent = lerp( normalTangent, BlendNormals(normalTangent, detailNormalTangent), mask); #endif #endif return normalTangent; } #endif // 法线在切空间叠加 half3 BlendNormals(half3 n1, half3 n2) { return normalize(half3(n1.xy + n2.xy, n1.z*n2.z)); }
标签:surface utf-8 version map yuv htm 添加 ack stat
原文地址:https://www.cnblogs.com/sifenkesi/p/11925177.html