새소식

개발/Shader

[HLSL] Simple Texture Normal

  • -

결과

float3 getNormalFromTexture(Texture2D t, SamplerState s, float strength, float2 offset, float2 uv)
{
	offset = pow(offset, 3) * 0.1f;
    float2 offsetU = float2(uv.x + offset.x, uv.y);
    float2 offsetV = float2(uv.x, uv.y + offset.y);
    
    float normalSample = t.Sample(smp, uv).a;
    float uSample = t.Sample(s, offsetU).a;
    float vSample = t.Sample(s, offsetV).a;
    float3 va = float3(1.0f, 0.0f, (uSample - normalSample) * strength);
    float3 vb = float3(0.0f, 1.0f, (vSample - normalSample) * strength);
    
    //float3 normal = (cross(va, vb));
    float3 normal = normalize(cross(va, vb));
    return normal;
}
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.