diff options
Diffstat (limited to 'decal.cginc')
| -rw-r--r-- | decal.cginc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/decal.cginc b/decal.cginc new file mode 100644 index 0000000..69fb9e5 --- /dev/null +++ b/decal.cginc @@ -0,0 +1,55 @@ +#ifndef __DECAL_INC +#define __DECAL_INC + +#include "globals.cginc" +#include "pbr.cginc" +#include "interpolators.cginc" +#include "texture_utils.cginc" + +float4 decal_sample(texture2D tex, float2 uv, int uv_mode) { + [forcecase] + switch (uv_mode) { + case DECAL_UV_MODE_REPEAT: + return tex.Sample(aniso4_trilinear_repeat_s, uv); + case DECAL_UV_MODE_MIRROR: + return tex.Sample(aniso4_trilinear_mirror_s, uv); + case DECAL_UV_MODE_CLAMP: + return tex.Sample(aniso4_trilinear_clamp_s, uv); + default: + return 0; + } +} + +float2 decal_rotate(float2 uv, float rotation) { + float s, c; + sincos(rotation * TAU, s, c); + float2 d = uv - 0.5; + return float2(d.x * c - d.y * s, d.x * s + d.y * c) + 0.5; +} + +void applyDecals(v2f i, inout Pbr pbr) { +#if defined(_DECAL0) + { + float2 uv = get_uv_by_channel(i, _Decal0_UV_Channel); + uv -= _Decal0_MainTex_ST.zw; + uv *= _Decal0_MainTex_ST.xy; +#if defined(_DECAL0_ROTATION) + uv = decal_rotate(uv, _Decal0_Rotation); +#endif + float4 albedo = decal_sample(_Decal0_MainTex, uv, _Decal0_UV_Mode); + albedo *= _Decal0_Color; + albedo.a *= _Decal0_Opacity; + [forcecase] + switch (_Decal0_Mix_Mode) { + case DECAL_MIX_MODE_ALPHA_BLEND: + pbr.albedo = alpha_blend(albedo, pbr.albedo); + break; + case DECAL_MIX_MODE_MULTIPLY: + pbr.albedo.rgb *= lerp(1, albedo.rgb, albedo.a); + break; + } + } +#endif +} + +#endif // __DECAL_INC |
