Skyshop.Detail Maps
Posted sifenkesi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Skyshop.Detail Maps相关的知识,希望对你有一定的参考价值。
Secondary Maps(Detail Maps) & Detail Mask
增加模型细节,而不需要使用单张的超大贴图。
应用:增加皮肤细节,比如毛孔;砖墙添加细小的裂缝和青苔;大型金属容器上增加一些小的划痕和擦痕。
toolbag.shader:
//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)); }
以上是关于Skyshop.Detail Maps的主要内容,如果未能解决你的问题,请参考以下文章
ID、标签 null 或父 ID 与 com.google.android.gms.maps.MapFragment 的另一个片段重复