Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/shaders/common_smaa_lib.glsl
| Show First 20 Lines • Show All 582 Lines • ▼ Show 20 Lines | |||||
| # define lerp(a, b, t) mix(a, b, t) | # define lerp(a, b, t) mix(a, b, t) | ||||
| # define saturate(a) clamp(a, 0.0, 1.0) | # define saturate(a) clamp(a, 0.0, 1.0) | ||||
| # if defined(SMAA_GLSL_4) | # if defined(SMAA_GLSL_4) | ||||
| # define mad(a, b, c) fma(a, b, c) | # define mad(a, b, c) fma(a, b, c) | ||||
| # define SMAAGather(tex, coord) textureGather(tex, coord) | # define SMAAGather(tex, coord) textureGather(tex, coord) | ||||
| # else | # else | ||||
| # define mad(a, b, c) (a * b + c) | # define mad(a, b, c) (a * b + c) | ||||
| # endif | # endif | ||||
| /* NOTE(Metal): Types already natively declared in MSL. */ | |||||
| # ifndef GPU_METAL | |||||
| # define float2 vec2 | # define float2 vec2 | ||||
| # define float3 vec3 | # define float3 vec3 | ||||
| # define float4 vec4 | # define float4 vec4 | ||||
| # define int2 ivec2 | # define int2 ivec2 | ||||
| # define int3 ivec3 | # define int3 ivec3 | ||||
| # define int4 ivec4 | # define int4 ivec4 | ||||
| # define bool2 bvec2 | # define bool2 bvec2 | ||||
| # define bool3 bvec3 | # define bool3 bvec3 | ||||
| # define bool4 bvec4 | # define bool4 bvec4 | ||||
| #endif | # endif | ||||
| #endif | |||||
| /* clang-format off */ | /* clang-format off */ | ||||
| #if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL) | #if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL) | ||||
| # error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL | # error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL | ||||
| #endif | #endif | ||||
| /* clang-format on */ | /* clang-format on */ | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| #if SMAA_INCLUDE_VS | #if SMAA_INCLUDE_VS | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| // Vertex Shaders | // Vertex Shaders | ||||
| /** | /** | ||||
| * Edge Detection Vertex Shader | * Edge Detection Vertex Shader | ||||
| */ | */ | ||||
| # ifdef GPU_METAL | |||||
| /* NOTE: Metal API requires explicit address space qualifiers for pointer types. | |||||
| * Arrays in functions are passed as pointers, and thus require explicit address | |||||
| * space. */ | |||||
| void SMAAEdgeDetectionVS(float2 texcoord, thread float4 *offset) | |||||
| # else | |||||
| void SMAAEdgeDetectionVS(float2 texcoord, out float4 offset[3]) | void SMAAEdgeDetectionVS(float2 texcoord, out float4 offset[3]) | ||||
| # endif | |||||
| { | { | ||||
| offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy); | offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), texcoord.xyxy); | ||||
| offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(1.0, 0.0, 0.0, 1.0), texcoord.xyxy); | offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(1.0, 0.0, 0.0, 1.0), texcoord.xyxy); | ||||
| offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy); | offset[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy); | ||||
| } | } | ||||
| /** | /** | ||||
| * Blend Weight Calculation Vertex Shader | * Blend Weight Calculation Vertex Shader | ||||
| */ | */ | ||||
| # ifdef GPU_METAL | |||||
| /* NOTE: Metal API requires explicit address space qualifiers for pointer types. | |||||
| * Arrays in functions are passed as pointers, and thus require explicit address | |||||
| * space. */ | |||||
| void SMAABlendingWeightCalculationVS(float2 texcoord, | |||||
| thread float2 &pixcoord, | |||||
| thread float4 *offset) | |||||
| # else | |||||
| void SMAABlendingWeightCalculationVS(float2 texcoord, out float2 pixcoord, out float4 offset[3]) | void SMAABlendingWeightCalculationVS(float2 texcoord, out float2 pixcoord, out float4 offset[3]) | ||||
| # endif | |||||
| { | { | ||||
| pixcoord = texcoord * SMAA_RT_METRICS.zw; | pixcoord = texcoord * SMAA_RT_METRICS.zw; | ||||
| // We will use these offsets for the searches later on (see @PSEUDO_GATHER4): | // We will use these offsets for the searches later on (see @PSEUDO_GATHER4): | ||||
| offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy); | offset[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.25, -0.125, 1.25, -0.125), texcoord.xyxy); | ||||
| offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy); | offset[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.25, -0.125, 1.25), texcoord.xyxy); | ||||
| // And these for the searches, they indicate the ends of the loops: | // And these for the searches, they indicate the ends of the loops: | ||||
| ▲ Show 20 Lines • Show All 791 Lines • Show Last 20 Lines | |||||