Desc:
记录法线贴图的变更
法线映射
非移动平台上,Unity会把法线贴图转换成 DXRT5nm 格式,只有两个有效通道 GA ,节省空间的优化
移动平台上,RGB 通道
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| fixed3 UnpackNormalmapRGorAG(fixed4 packednormal) { packednormal.x *= packednormal.w;
fixed3 normal; normal.xy = packednormal.xy * 2 - 1; normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy))); return normal; } inline fixed3 UnpackNormal(fixed4 packednormal) { #if defined(UNITY_NO_DXT5nm) return packednormal.xyz * 2 - 1; #else return UnpackNormalmapRGorAG(packednormal); #endif }
|
视察映射
知乎
1 2 3 4 5 6 7
| float2 ParallaxMapping(float2 Huv, real3 viewDirTS) { float height = tex2D(_HeightMap, Huv).r; float2 offuv = viewDirTS.xy / viewDirTS.z * height * _HeightScale; return offuv; }
|
陡视差映射
//陡峭视差映射
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| float2 SteepParallaxMapping(float2 uv, real3 viewDirTS) { float numLayers = 20.0; float layerHeight = 1.0 / numLayers; float currentLayerHeight = 0.0; float2 offlayerUV = viewDirTS.xy / viewDirTS.z * _HeightScale; float2 Stepping = offlayerUV / numLayers; float2 currentUV = uv; float2 AddUV = float2(0, 0); float currentHeightMapValue = tex2D(_HeightMap, currentUV + AddUV).r; for (int i = 0; i < numLayers; i++) { if (currentLayerHeight > currentHeightMapValue) { return AddUV; } AddUV += Stepping; currentHeightMapValue = tex2D(_HeightMap, currentUV + AddUV).r; currentLayerHeight += layerHeight; } return AddUV; }
|
视差遮蔽映射
1 2 3 4 5 6 7 8 9 10 11 12
| float2 prevTexCoords = currentTexCoords + deltaTexCoords;
float afterDepth = currentDepthMapValue - currentLayerDepth; float beforeDepth = texture(depthMap, prevTexCoords).r - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); float2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
|
浮雕映射
二分查找的操作存在性能开销,优化方法,视差闭塞贴图(pom)
链接
github