This repository has been archived on 2024-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
DX11Starter/Helpers.hlsli
2022-03-19 18:00:11 -04:00

41 lines
896 B
HLSL

#ifndef __SHADER_HELPERS__
#define __SHADER_HELPERS__
float3 getView(float3 cameraPosition, float3 pixelWorldPosition)
{
return normalize(cameraPosition - pixelWorldPosition);
}
float3 getReflection(float3 direction, float3 normal)
{
return reflect(direction, normal);
}
float getSpecularExponent(float roughness, float max)
{
return (1.0f - roughness) * max;
}
float getSpecular(float3 view, float3 reflection, float exponent)
{
float specular = 0;
if (exponent > 0.05f)
{
specular = pow(saturate(dot(reflection, view)), exponent);
}
return specular;
}
float getDiffuse(float3 normal, float3 direction)
{
return saturate(dot(normal, direction));
}
float getAttenuation(float3 pointPosition, float3 worldPosition, float3 range)
{
float dist = distance(pointPosition, worldPosition);
float attn = saturate(1.0f - (dist * dist / (range * range)));
return attn * attn;
}
#endif