12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436 |
- #if defined(SMAA_PRESET_LOW)
- #define SMAA_THRESHOLD 0.15
- #define SMAA_MAX_SEARCH_STEPS 4
- #define SMAA_DISABLE_DIAG_DETECTION
- #define SMAA_DISABLE_CORNER_DETECTION
- #elif defined(SMAA_PRESET_MEDIUM)
- #define SMAA_THRESHOLD 0.1
- #define SMAA_MAX_SEARCH_STEPS 8
- #define SMAA_DISABLE_DIAG_DETECTION
- #define SMAA_DISABLE_CORNER_DETECTION
- #elif defined(SMAA_PRESET_HIGH)
- #define SMAA_THRESHOLD 0.1
- #define SMAA_MAX_SEARCH_STEPS 16
- #define SMAA_MAX_SEARCH_STEPS_DIAG 8
- #define SMAA_CORNER_ROUNDING 25
- #elif defined(SMAA_PRESET_ULTRA)
- #define SMAA_THRESHOLD 0.05
- #define SMAA_MAX_SEARCH_STEPS 32
- #define SMAA_MAX_SEARCH_STEPS_DIAG 16
- #define SMAA_CORNER_ROUNDING 25
- #endif
- #ifndef SMAA_THRESHOLD
- #define SMAA_THRESHOLD 0.1
- #endif
- #ifndef SMAA_DEPTH_THRESHOLD
- #define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD)
- #endif
- #ifndef SMAA_MAX_SEARCH_STEPS
- #define SMAA_MAX_SEARCH_STEPS 16
- #endif
- #ifndef SMAA_MAX_SEARCH_STEPS_DIAG
- #define SMAA_MAX_SEARCH_STEPS_DIAG 8
- #endif
- #ifndef SMAA_CORNER_ROUNDING
- #define SMAA_CORNER_ROUNDING 25
- #endif
- #ifndef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR
- #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0
- #endif
- #ifndef SMAA_PREDICATION
- #define SMAA_PREDICATION 0
- #endif
- #ifndef SMAA_PREDICATION_THRESHOLD
- #define SMAA_PREDICATION_THRESHOLD 0.01
- #endif
- #ifndef SMAA_PREDICATION_SCALE
- #define SMAA_PREDICATION_SCALE 2.0
- #endif
- #ifndef SMAA_PREDICATION_STRENGTH
- #define SMAA_PREDICATION_STRENGTH 0.4
- #endif
- #ifndef SMAA_REPROJECTION
- #define SMAA_REPROJECTION 0
- #endif
- #ifndef SMAA_UV_BASED_REPROJECTION
- #define SMAA_UV_BASED_REPROJECTION 0
- #endif
- #ifndef SMAA_REPROJECTION_WEIGHT_SCALE
- #define SMAA_REPROJECTION_WEIGHT_SCALE 30.0
- #endif
- #ifndef SMAA_INCLUDE_VS
- #define SMAA_INCLUDE_VS 1
- #endif
- #ifndef SMAA_INCLUDE_PS
- #define SMAA_INCLUDE_PS 1
- #endif
- #ifndef SMAA_AREATEX_SELECT
- #if defined(SMAA_HLSL_3)
- #define SMAA_AREATEX_SELECT(sample) sample.ra
- #else
- #define SMAA_AREATEX_SELECT(sample) sample.rg
- #endif
- #endif
- #ifndef SMAA_SEARCHTEX_SELECT
- #define SMAA_SEARCHTEX_SELECT(sample) sample.r
- #endif
- #ifndef SMAA_DECODE_VELOCITY
- #define SMAA_DECODE_VELOCITY(sample) sample.rg
- #endif
- #define SMAA_AREATEX_MAX_DISTANCE 16
- #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
- #define SMAA_AREATEX_PIXEL_SIZE (1.0 / float2(160.0, 560.0))
- #define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)
- #define SMAA_SEARCHTEX_SIZE float2(66.0, 33.0)
- #define SMAA_SEARCHTEX_PACKED_SIZE float2(64.0, 16.0)
- #define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0)
- #if defined(SMAA_HLSL_3)
- #define SMAATexture2D(tex) sampler2D tex
- #define SMAATexturePass2D(tex) tex
- #define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
- #define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
- #define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0))
- #define SMAASample(tex, coord) tex2D(tex, coord)
- #define SMAASamplePoint(tex, coord) tex2D(tex, coord)
- #define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy)
- #define SMAA_FLATTEN
- #define SMAA_BRANCH
- #endif
- #if defined(SMAA_HLSL_4) || defined(SMAA_HLSL_4_1)
- #define SMAATexture2D(tex) TEXTURE2D_X(tex)
- #define SMAATexture2D_Non_Array(tex) Texture2D tex
- #define SMAATexturePass2D(tex) tex
- #define SMAASampleLevelZero(tex, coord) SAMPLE_TEXTURE2D_X_LOD(tex, LinearSampler, coord, 0)
- #define SMAASampleLevelZeroNoRescale(tex, coord) tex.SampleLevel(LinearSampler, coord, 0)
- #define SMAASampleLevelZeroPoint(tex, coord) SAMPLE_TEXTURE2D_X_LOD(tex, PointSampler, coord, 0)
- #define SMAASampleLevelZeroOffset(tex, coord, offset) SAMPLE_TEXTURE2D_X_LOD(tex, LinearSampler, coord + offset * SMAA_RT_METRICS.xy, 0)
- #define SMAASample(tex, coord) SAMPLE_TEXTURE2D_X(tex, LinearSampler, coord)
- #define SMAASamplePoint(tex, coord) SAMPLE_TEXTURE2D_X(tex, PointSampler, coord)
- #define SMAASampleOffset(tex, coord, offset) SAMPLE_TEXTURE2D_X(tex, LinearSampler, coord + offset * SMAA_RT_METRICS.xy)
- #define SMAA_FLATTEN [flatten]
- #define SMAA_BRANCH [branch]
- #define SMAATexture2DMS2(tex) Texture2DMS<float4, 2> tex
- #define SMAALoad(tex, pos, sample) tex.Load(pos, sample)
- #endif
- #if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4)
- #define SMAATexture2D(tex) sampler2D tex
- #define SMAATexturePass2D(tex) tex
- #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
- #define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0)
- #define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset)
- #define SMAASample(tex, coord) texture(tex, coord)
- #define SMAASamplePoint(tex, coord) texture(tex, coord)
- #define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset)
- #define SMAA_FLATTEN
- #define SMAA_BRANCH
- #define lerp(a, b, t) mix(a, b, t)
- #define saturate(a) clamp(a, 0.0, 1.0)
- #if defined(SMAA_GLSL_4)
- #define mad(a, b, c) fma(a, b, c)
- #define SMAAGather(tex, coord) textureGather(tex, coord)
- #else
- #define mad(a, b, c) ((a) * (b) + (c))
- #endif
- #define float2 vec2
- #define float3 vec3
- #define float4 vec4
- #define int2 ivec2
- #define int3 ivec3
- #define int4 ivec4
- #define bool2 bvec2
- #define bool3 bvec3
- #define bool4 bvec4
- #endif
- #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
- #endif
- float3 SMAAGatherNeighbours(float2 texcoord,
- float4 offset[3],
- SMAATexture2D(tex)) {
- #ifdef SMAAGather
- return SMAAGather(tex, texcoord + SMAA_RT_METRICS.xy * float2(-0.5, -0.5)).grb;
- #else
- float P = SMAASamplePoint(tex, texcoord).r;
- float Pleft = SMAASamplePoint(tex, offset[0].xy).r;
- float Ptop = SMAASamplePoint(tex, offset[0].zw).r;
- return float3(P, Pleft, Ptop);
- #endif
- }
- float2 SMAACalculatePredicatedThreshold(float2 texcoord,
- float4 offset[3],
- SMAATexture2D(predicationTex)) {
- float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(predicationTex));
- float2 delta = abs(neighbours.xx - neighbours.yz);
- float2 edges = step(SMAA_PREDICATION_THRESHOLD, delta);
- return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges);
- }
- void SMAAMovc(bool2 cond, inout float2 variable, float2 value) {
- SMAA_FLATTEN if (cond.x) variable.x = value.x;
- SMAA_FLATTEN if (cond.y) variable.y = value.y;
- }
- void SMAAMovc(bool4 cond, inout float4 variable, float4 value) {
- SMAAMovc(cond.xy, variable.xy, value.xy);
- SMAAMovc(cond.zw, variable.zw, value.zw);
- }
- #if SMAA_INCLUDE_VS
- void SMAAEdgeDetectionVS(float2 texcoord,
- out float4 offset[3]) {
- 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[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), texcoord.xyxy);
- }
- void SMAABlendingWeightCalculationVS(float2 texcoord,
- out float2 pixcoord,
- out float4 offset[3]) {
- pixcoord = texcoord * SMAA_RT_METRICS.zw;
-
- 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[2] = mad(SMAA_RT_METRICS.xxyy,
- float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS),
- float4(offset[0].xz, offset[1].yw));
- }
- void SMAANeighborhoodBlendingVS(float2 texcoord,
- out float4 offset) {
- offset = mad(SMAA_RT_METRICS.xyxy, float4(1.0, 0.0, 0.0, 1.0), texcoord.xyxy);
- }
- #endif
- #if SMAA_INCLUDE_PS
- float2 SMAALumaEdgeDetectionPS(float2 texcoord,
- float4 offset[3],
- SMAATexture2D(colorTex)
- #if SMAA_PREDICATION
- , SMAATexture2D(predicationTex)
- #endif
- ) {
-
- #if SMAA_PREDICATION
- float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, SMAATexturePass2D(predicationTex));
- #else
- float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
- #endif
-
- float3 weights = float3(0.2126, 0.7152, 0.0722);
- float L = dot(SMAASamplePoint(colorTex, texcoord).rgb, weights);
- float Lleft = dot(SMAASamplePoint(colorTex, offset[0].xy).rgb, weights);
- float Ltop = dot(SMAASamplePoint(colorTex, offset[0].zw).rgb, weights);
-
- float4 delta;
- delta.xy = abs(L - float2(Lleft, Ltop));
- float2 edges = step(threshold, delta.xy);
-
- if (dot(edges, float2(1.0, 1.0)) == 0.0)
- discard;
-
- float Lright = dot(SMAASamplePoint(colorTex, offset[1].xy).rgb, weights);
- float Lbottom = dot(SMAASamplePoint(colorTex, offset[1].zw).rgb, weights);
- delta.zw = abs(L - float2(Lright, Lbottom));
-
- float2 maxDelta = max(delta.xy, delta.zw);
-
- float Lleftleft = dot(SMAASamplePoint(colorTex, offset[2].xy).rgb, weights);
- float Ltoptop = dot(SMAASamplePoint(colorTex, offset[2].zw).rgb, weights);
- delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop));
-
- maxDelta = max(maxDelta.xy, delta.zw);
- float finalDelta = max(maxDelta.x, maxDelta.y);
-
- #if !defined(SHADER_API_OPENGL)
- edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
- #endif
- return edges;
- }
- float2 SMAAColorEdgeDetectionPS(float2 texcoord,
- float4 offset[3],
- SMAATexture2D(colorTex)
- #if SMAA_PREDICATION
- , SMAATexture2D(predicationTex)
- #endif
- ) {
-
- #if SMAA_PREDICATION
- float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, predicationTex);
- #else
- float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
- #endif
-
- float4 delta;
- float3 C = PositivePow(SMAASamplePoint(colorTex, texcoord).rgb, GAMMA_FOR_EDGE_DETECTION);
- float3 Cleft = PositivePow(SMAASamplePoint(colorTex, offset[0].xy).rgb, GAMMA_FOR_EDGE_DETECTION);
- float3 t = abs(C - Cleft);
- delta.x = max(max(t.r, t.g), t.b);
- float3 Ctop = PositivePow(SMAASamplePoint(colorTex, offset[0].zw).rgb, GAMMA_FOR_EDGE_DETECTION);
- t = abs(C - Ctop);
- delta.y = max(max(t.r, t.g), t.b);
-
- float2 edges = step(threshold, delta.xy);
-
- if (dot(edges, float2(1.0, 1.0)) == 0.0)
- discard;
-
- float3 Cright = PositivePow(SMAASamplePoint(colorTex, offset[1].xy).rgb, GAMMA_FOR_EDGE_DETECTION);
- t = abs(C - Cright);
- delta.z = max(max(t.r, t.g), t.b);
- float3 Cbottom = PositivePow(SMAASamplePoint(colorTex, offset[1].zw).rgb, GAMMA_FOR_EDGE_DETECTION);
- t = abs(C - Cbottom);
- delta.w = max(max(t.r, t.g), t.b);
-
- float2 maxDelta = max(delta.xy, delta.zw);
-
- float3 Cleftleft = PositivePow(SMAASamplePoint(colorTex, offset[2].xy).rgb, GAMMA_FOR_EDGE_DETECTION);
- t = abs(Cleft - Cleftleft);
- delta.z = max(max(t.r, t.g), t.b);
- float3 Ctoptop = PositivePow(SMAASamplePoint(colorTex, offset[2].zw).rgb, GAMMA_FOR_EDGE_DETECTION);
- t = abs(Ctop - Ctoptop);
- delta.w = max(max(t.r, t.g), t.b);
-
- maxDelta = max(maxDelta.xy, delta.zw);
- float finalDelta = max(maxDelta.x, maxDelta.y);
-
- #if !defined(SHADER_API_OPENGL)
- edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy);
- #endif
- return edges;
- }
- float2 SMAADepthEdgeDetectionPS(float2 texcoord,
- float4 offset[3],
- SMAATexture2D(depthTex)) {
- float3 neighbours = SMAAGatherNeighbours(texcoord, offset, SMAATexturePass2D(depthTex));
- float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z));
- float2 edges = step(SMAA_DEPTH_THRESHOLD, delta);
- if (dot(edges, float2(1.0, 1.0)) == 0.0)
- discard;
- return edges;
- }
- #if !defined(SMAA_DISABLE_DIAG_DETECTION)
- float2 SMAADecodeDiagBilinearAccess(float2 e) {
-
-
-
-
-
-
-
-
-
-
-
-
-
- e.r = e.r * abs(5.0 * e.r - 5.0 * 0.75);
- return round(e);
- }
- float4 SMAADecodeDiagBilinearAccess(float4 e) {
- e.rb = e.rb * abs(5.0 * e.rb - 5.0 * 0.75);
- return round(e);
- }
- float2 SMAASearchDiag1(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) {
- float4 coord = float4(texcoord, -1.0, 1.0);
- float3 t = float3(SMAA_RT_METRICS.xy, 1.0);
- while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) &&
- coord.w > 0.9) {
- coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
- e = SMAASampleLevelZero(edgesTex, coord.xy).rg;
- coord.w = dot(e, float2(0.5, 0.5));
- }
- return coord.zw;
- }
- float2 SMAASearchDiag2(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, out float2 e) {
- float4 coord = float4(texcoord, -1.0, 1.0);
- coord.x += 0.25 * SMAA_RT_METRICS.x;
- float3 t = float3(SMAA_RT_METRICS.xy, 1.0);
- while (coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) &&
- coord.w > 0.9) {
- coord.xyz = mad(t, float3(dir, 1.0), coord.xyz);
-
-
- e = SMAASampleLevelZero(edgesTex, coord.xy).rg;
- e = SMAADecodeDiagBilinearAccess(e);
-
-
-
- coord.w = dot(e, float2(0.5, 0.5));
- }
- return coord.zw;
- }
- float2 SMAAAreaDiag(SMAATexture2D_Non_Array(areaTex), float2 dist, float2 e, float offset) {
- float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist);
-
- texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
-
- texcoord.x += 0.5;
-
- texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset;
-
- return SMAA_AREATEX_SELECT(SMAASampleLevelZeroNoRescale(areaTex, texcoord));
- }
- float2 SMAACalculateDiagWeights(SMAATexture2D(edgesTex), SMAATexture2D_Non_Array(areaTex), float2 texcoord, float2 e, float4 subsampleIndices) {
- float2 weights = float2(0.0, 0.0);
-
- float4 d;
- float2 end;
- if (e.r > 0.0) {
- d.xz = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, 1.0), end);
- d.x += float(end.y > 0.9);
- }
- else
- d.xz = float2(0.0, 0.0);
- d.yw = SMAASearchDiag1(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, -1.0), end);
- SMAA_BRANCH
- if (d.x + d.y > 2.0) {
-
- float4 coords = mad(float4(-d.x + 0.25, d.x, d.y, -d.y - 0.25), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
- float4 c;
- c.xy = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).rg;
- c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2(1, 0)).rg;
- c.yxwz = SMAADecodeDiagBilinearAccess(c.xyzw);
-
-
-
-
-
-
-
-
- float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
-
- SMAAMovc(bool2(step(float2(0.9, 0.9), d.zw)), cc, float2(0.0, 0.0));
-
- weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.z);
- }
-
- d.xz = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(-1.0, -1.0), end);
- if (SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r > 0.0) {
- d.yw = SMAASearchDiag2(SMAATexturePass2D(edgesTex), texcoord, float2(1.0, 1.0), end);
- d.y += float(end.y > 0.9);
- }
- else
- d.yw = float2(0.0, 0.0);
- SMAA_BRANCH
- if (d.x + d.y > 2.0) {
-
- float4 coords = mad(float4(-d.x, -d.x, d.y, d.y), SMAA_RT_METRICS.xyxy, texcoord.xyxy);
- float4 c;
- c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1, 0)).g;
- c.y = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(0, -1)).r;
- c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2(1, 0)).gr;
- float2 cc = mad(float2(2.0, 2.0), c.xz, c.yw);
-
- SMAAMovc(bool2(step(float2(0.9, 0.9), d.zw)), cc, float2(0.0, 0.0));
-
- weights += SMAAAreaDiag(SMAATexturePass2D(areaTex), d.xy, cc, subsampleIndices.w).gr;
- }
- return weights;
- }
- #endif
- float SMAASearchLength(SMAATexture2D_Non_Array(searchTex), float2 e, float offset) {
-
-
- float2 scale = SMAA_SEARCHTEX_SIZE * float2(0.5, -1.0);
- float2 bias = SMAA_SEARCHTEX_SIZE * float2(offset, 1.0);
-
- scale += float2(-1.0, 1.0);
- bias += float2(0.5, -0.5);
-
-
- scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
- bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE;
-
- return SMAA_SEARCHTEX_SELECT(SMAASampleLevelZeroNoRescale(searchTex, mad(scale, e, bias)));
- }
- float SMAASearchXLeft(SMAATexture2D(edgesTex), SMAATexture2D_Non_Array(searchTex), float2 texcoord, float end) {
-
- float2 e = float2(0.0, 1.0);
- while (texcoord.x > end &&
- e.g > 0.8281 &&
- e.r == 0.0) {
- e = SMAASampleLevelZero(edgesTex, texcoord).rg;
- texcoord = mad(-float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
- }
- float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.0), 3.25);
- return mad(SMAA_RT_METRICS.x, offset, texcoord.x);
-
-
-
-
-
-
-
-
-
- }
- float SMAASearchXRight(SMAATexture2D(edgesTex), SMAATexture2D_Non_Array(searchTex), float2 texcoord, float end) {
- float2 e = float2(0.0, 1.0);
- while (texcoord.x < end &&
- e.g > 0.8281 &&
- e.r == 0.0) {
- e = SMAASampleLevelZero(edgesTex, texcoord).rg;
- texcoord = mad(float2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord);
- }
- float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e, 0.5), 3.25);
- return mad(-SMAA_RT_METRICS.x, offset, texcoord.x);
- }
- float SMAASearchYUp(SMAATexture2D(edgesTex), SMAATexture2D_Non_Array(searchTex), float2 texcoord, float end) {
- float2 e = float2(1.0, 0.0);
- while (texcoord.y > end &&
- e.r > 0.8281 &&
- e.g == 0.0) {
- e = SMAASampleLevelZero(edgesTex, texcoord).rg;
- texcoord = mad(-float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
- }
- float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.0), 3.25);
- return mad(SMAA_RT_METRICS.y, offset, texcoord.y);
- }
- float SMAASearchYDown(SMAATexture2D(edgesTex), SMAATexture2D_Non_Array(searchTex), float2 texcoord, float end) {
- float2 e = float2(1.0, 0.0);
- while (texcoord.y < end &&
- e.r > 0.8281 &&
- e.g == 0.0) {
- e = SMAASampleLevelZero(edgesTex, texcoord).rg;
- texcoord = mad(float2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord);
- }
- float offset = mad(-(255.0 / 127.0), SMAASearchLength(SMAATexturePass2D(searchTex), e.gr, 0.5), 3.25);
- return mad(-SMAA_RT_METRICS.y, offset, texcoord.y);
- }
- float2 SMAAArea(SMAATexture2D_Non_Array(areaTex), float2 dist, float e1, float e2, float offset) {
-
- float2 texcoord = mad(float2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * float2(e1, e2)), dist);
-
- texcoord = mad(SMAA_AREATEX_PIXEL_SIZE, texcoord, 0.5 * SMAA_AREATEX_PIXEL_SIZE);
-
- texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y);
-
- return SMAA_AREATEX_SELECT(SMAASampleLevelZeroNoRescale(areaTex, texcoord));
- }
- void SMAADetectHorizontalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) {
- #if !defined(SMAA_DISABLE_CORNER_DETECTION)
- float2 leftRight = step(d.xy, d.yx);
- float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
- rounding /= leftRight.x + leftRight.y;
- float2 factor = float2(1.0, 1.0);
- factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, 1)).r;
- factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, 1)).r;
- factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(0, -2)).r;
- factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, -2)).r;
- weights *= saturate(factor);
- #endif
- }
- void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), inout float2 weights, float4 texcoord, float2 d) {
- #if !defined(SMAA_DISABLE_CORNER_DETECTION)
- float2 leftRight = step(d.xy, d.yx);
- float2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight;
- rounding /= leftRight.x + leftRight.y;
- float2 factor = float2(1.0, 1.0);
- factor.x -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(1, 0)).g;
- factor.x -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(1, 1)).g;
- factor.y -= rounding.x * SMAASampleLevelZeroOffset(edgesTex, texcoord.xy, int2(-2, 0)).g;
- factor.y -= rounding.y * SMAASampleLevelZeroOffset(edgesTex, texcoord.zw, int2(-2, 1)).g;
- weights *= saturate(factor);
- #endif
- }
- float4 SMAABlendingWeightCalculationPS(float2 texcoord,
- float2 pixcoord,
- float4 offset[3],
- SMAATexture2D(edgesTex),
- SMAATexture2D_Non_Array(areaTex),
- SMAATexture2D_Non_Array(searchTex),
- float4 subsampleIndices) {
- float4 weights = float4(0.0, 0.0, 0.0, 0.0);
- float2 e = SMAASample(edgesTex, texcoord).rg;
- SMAA_BRANCH
- if (e.g > 0.0) {
- #if !defined(SMAA_DISABLE_DIAG_DETECTION)
- weights.rg = SMAACalculateDiagWeights(SMAATexturePass2D(edgesTex), SMAATexturePass2D(areaTex), texcoord, e, subsampleIndices);
-
-
- SMAA_BRANCH
- if (weights.r == -weights.g) {
- #endif
- float2 d;
-
- float3 coords;
- coords.x = SMAASearchXLeft(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].xy, offset[2].x);
- coords.y = offset[1].y;
- d.x = coords.x;
-
-
-
- float e1 = SMAASampleLevelZero(edgesTex, coords.xy).r;
-
- coords.z = SMAASearchXRight(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[0].zw, offset[2].y);
- d.y = coords.z;
-
-
- d = abs(round(mad(SMAA_RT_METRICS.zz, d, -pixcoord.xx)));
-
-
- float2 sqrt_d = sqrt(d);
-
- float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.zy, int2(1, 0)).r;
-
-
- weights.rg = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.y);
-
- coords.y = texcoord.y;
- SMAADetectHorizontalCornerPattern(SMAATexturePass2D(edgesTex), weights.rg, coords.xyzy, d);
- #if !defined(SMAA_DISABLE_DIAG_DETECTION)
- }
- else
- e.r = 0.0;
- #endif
- }
- SMAA_BRANCH
- if (e.r > 0.0) {
- float2 d;
-
- float3 coords;
- coords.y = SMAASearchYUp(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].xy, offset[2].z);
- coords.x = offset[0].x;
- d.x = coords.y;
-
- float e1 = SMAASampleLevelZero(edgesTex, coords.xy).g;
-
- coords.z = SMAASearchYDown(SMAATexturePass2D(edgesTex), SMAATexturePass2D(searchTex), offset[1].zw, offset[2].w);
- d.y = coords.z;
-
- d = abs(round(mad(SMAA_RT_METRICS.ww, d, -pixcoord.yy)));
-
-
- float2 sqrt_d = sqrt(d);
-
- float e2 = SMAASampleLevelZeroOffset(edgesTex, coords.xz, int2(0, 1)).g;
-
- weights.ba = SMAAArea(SMAATexturePass2D(areaTex), sqrt_d, e1, e2, subsampleIndices.x);
-
- coords.x = texcoord.x;
- SMAADetectVerticalCornerPattern(SMAATexturePass2D(edgesTex), weights.ba, coords.xyxz, d);
- }
- return weights;
- }
- #if SMAA_UV_BASED_REPROJECTION
- float2 SMAAReproject(float2 texcoord)
- {
-
-
-
- float depth = SMAASampleLevelZero(_CameraDepthTexture, texcoord).r;
- float3 clipPosition = float3(2. * texcoord - 1., depth);
-
- float4 previousClipPosition = mul(_ReprojectionMatrix, float4(clipPosition, 1.));
- previousClipPosition.xyz /= previousClipPosition.w;
-
- return (.5 * previousClipPosition.xy + .5);
- }
- #endif
- float4 SMAANeighborhoodBlendingPS(float2 texcoord,
- float4 offset,
- SMAATexture2D(colorTex),
- SMAATexture2D(blendTex)
- #if SMAA_REPROJECTION
- , SMAATexture2D(velocityTex)
- #endif
- ) {
-
- float4 a;
- a.x = SMAASample(blendTex, offset.xy).a;
- a.y = SMAASample(blendTex, offset.zw).g;
- a.wz = SMAASample(blendTex, texcoord).xz;
-
- SMAA_BRANCH
- if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5) {
- float4 color = SMAASampleLevelZero(colorTex, texcoord);
- #if SMAA_REPROJECTION
- float2 velocity = SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, texcoord));
- #elif SMAA_UV_BASED_REPROJECTION
- float2 velocity = texcoord - SMAAReproject(texcoord);
- #endif
- #if (SMAA_REPROJECTION || SMAA_UV_BASED_REPROJECTION)
-
- color.a = sqrt(5.0 * length(velocity));
- #endif
- return color;
- }
- else {
- bool h = max(a.x, a.z) > max(a.y, a.w);
-
- float4 blendingOffset = float4(0.0, a.y, 0.0, a.w);
- float2 blendingWeight = a.yw;
- SMAAMovc(bool4(h, h, h, h), blendingOffset, float4(a.x, 0.0, a.z, 0.0));
- SMAAMovc(bool2(h, h), blendingWeight, a.xz);
- blendingWeight /= dot(blendingWeight, float2(1.0, 1.0));
-
- float4 blendingCoord = mad(blendingOffset, float4(SMAA_RT_METRICS.xy, -SMAA_RT_METRICS.xy), texcoord.xyxy);
-
-
- float4 color = blendingWeight.x * SMAASampleLevelZero(colorTex, blendingCoord.xy);
- color += blendingWeight.y * SMAASampleLevelZero(colorTex, blendingCoord.zw);
- #if SMAA_REPROJECTION
-
- float2 velocity = blendingWeight.x * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.xy));
- velocity += blendingWeight.y * SMAA_DECODE_VELOCITY(SMAASampleLevelZero(velocityTex, blendingCoord.zw));
- #elif SMAA_UV_BASED_REPROJECTION
-
- float2 velocity = blendingWeight.x * (blendingCoord.xy - SMAAReproject(blendingCoord.xy));
- velocity += blendingWeight.y * (blendingCoord.zw - SMAAReproject(blendingCoord.zw));
- #endif
- #if (SMAA_REPROJECTION || SMAA_UV_BASED_REPROJECTION)
-
- color.a = sqrt(5.0 * length(velocity));
- #endif
- return color;
- }
- }
- float4 SMAAResolvePS(float2 texcoord,
- SMAATexture2D(currentColorTex),
- SMAATexture2D(previousColorTex)
- #if SMAA_REPROJECTION
- , SMAATexture2D(velocityTex)
- #endif
- ) {
- #if SMAA_REPROJECTION
-
-
- float2 velocity = -SMAA_DECODE_VELOCITY(SMAASamplePoint(velocityTex, texcoord).rg);
- #elif SMAA_UV_BASED_REPROJECTION
- float2 velocity = SMAAReproject(texcoord) - texcoord;
- #endif
- #if (SMAA_REPROJECTION || SMAA_UV_BASED_REPROJECTION)
-
- float4 current = SMAASamplePoint(currentColorTex, texcoord);
-
- float4 previous = SMAASamplePoint(previousColorTex, texcoord + velocity);
-
- float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0;
- float weight = 0.5 * saturate(1.0 - sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE);
-
-
-
-
- float4 n0 = SMAASampleOffset(currentColorTex, texcoord, float2(-1, -1));
- float4 n1 = SMAASampleOffset(currentColorTex, texcoord, float2(+1, -1));
- float4 n2 = SMAASampleOffset(currentColorTex, texcoord, float2(-1, +1));
- float4 n3 = SMAASampleOffset(currentColorTex, texcoord, float2(+1, +1));
- float4 cmax = max(n0, max(n1, max(n2, n3)));
- float4 cmin = min(n0, min(n1, min(n2, n3)));
- float4 avg = 0.25 * (n0 + n1 + n2 + n3);
- float4 wk = abs(avg - current);
- float blend = saturate(lerp(0.35, 0.85, wk));
-
- float4 previousClamped = clamp(previous, cmin, cmax);
- float4 color = lerp(lerp(current, previousClamped, 0.5*weight), previousClamped, weight);
- return color;
- #else
-
- float4 current = SMAASamplePoint(currentColorTex, texcoord);
- float4 previous = SMAASamplePoint(previousColorTex, texcoord);
- return lerp(current, previous, 0.5);
- #endif
- }
- #ifdef SMAALoad
- void SMAASeparatePS(float4 position,
- float2 texcoord,
- out float4 target0,
- out float4 target1,
- SMAATexture2DMS2(colorTexMS)) {
- int2 pos = int2(position.xy);
- target0 = SMAALoad(colorTexMS, pos, 0);
- target1 = SMAALoad(colorTexMS, pos, 1);
- }
- #endif
- #endif
|