콘텐츠로 건너뛰기

Packed Metallic and smoothness information together in NormalMap.

Usually, I used custom functions created and used, but it is more convenient to use visualized nodes for examples, so I tried to express it using Amplify Shader Editor canvas.

Input normal texture asset type is default image and turned off sRGB bypass coz normalmap and metallic with smoothness texture is scalar data.So, should turned off sRGB bypass.

Upper image have two type of ways.

First upper red rectangle area cotained used Unpack Scale Normal node from defaul ASE unpack normal function node and Lower red rectangle area contained used spreading contents unity unpackNormalRGorAG() .

Additionally We could used or referencing way of below code.

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"

real3 CustomUnpackNormalRG(real4 packedNormal, real scale = 1.0)
{
    real3 normal;
    normal.xy = packedNormal.rg * 2.0 - 1.0;
    normal.z = max(1.0e-16, sqrt(1.0 - saturate(dot(normal.xy, normal.xy))));

    // must scale after reconstruction of normal.z which also
    // mirrors UnpackNormalRGB(). This does imply normal is not returned
    // as a unit length vector but doesn't need it since it will get normalized after TBN transformation.
    // If we ever need to blend contributions with built-in shaders for URP
    // then we should consider using UnpackDerivativeNormalAG() instead like
    // HDRP does since derivatives do not use renormalization and unlike tangent space
    // normals allow you to blend, accumulate and scale contributions correctly.
    normal.xy *= scale;
    return normal;
}

real3 CustomUnpackNormalAG(real4 packedNormal, real scale = 1.0)
{
    real3 normal;
    normal.xy = packedNormal.ag * 2.0 - 1.0;
    normal.z = max(1.0e-16, sqrt(1.0 - saturate(dot(normal.xy, normal.xy))));

    // must scale after reconstruction of normal.z which also
    // mirrors UnpackNormalRGB(). This does imply normal is not returned
    // as a unit length vector but doesn't need it since it will get normalized after TBN transformation.
    // If we ever need to blend contributions with built-in shaders for URP
    // then we should consider using UnpackDerivativeNormalAG() instead like
    // HDRP does since derivatives do not use renormalization and unlike tangent space
    // normals allow you to blend, accumulate and scale contributions correctly.
    normal.xy *= scale;
    return normal;
}

real3 CustomUnpackNormalmapRGorAG(real4 packedNormal, real scale = 1.0)
{
    // Convert to (?, y, 0, x)
    packedNormal.a *= packedNormal.r;
    return CustomUnpackNormalAG(packedNormal, scale);
}

real3 CustomUnpackNormalRGScale(real4 packedNormal, real bumpScale)
{
    return CustomUnpackNormalRG(packedNormal, bumpScale);
}

Code language: PHP (php)
태그:

댓글 남기기

%d 블로거가 이것을 좋아합니다: