1 line
18 KiB
Plaintext
1 line
18 KiB
Plaintext
|
|
{"version":3,"file":"SMAAShader.cjs","sources":["../../src/shaders/SMAAShader.ts"],"sourcesContent":["import { Vector2 } from 'three'\n\n/**\n * WebGL port of Subpixel Morphological Antialiasing (SMAA) v2.8\n * Preset: SMAA 1x Medium (with color edge detection)\n * https://github.com/iryoku/smaa/releases/tag/v2.8\n */\n\nexport const SMAAEdgesShader = {\n defines: {\n SMAA_THRESHOLD: '0.1',\n },\n\n uniforms: {\n tDiffuse: { value: null },\n resolution: { value: /* @__PURE__ */ new Vector2(1 / 1024, 1 / 512) },\n },\n\n vertexShader: /* glsl */ `\n uniform vec2 resolution;\n\n varying vec2 vUv;\n varying vec4 vOffset[ 3 ];\n\n void SMAAEdgeDetectionVS( vec2 texcoord ) {\n \tvOffset[ 0 ] = texcoord.xyxy + resolution.xyxy * vec4( -1.0, 0.0, 0.0, 1.0 ); // WebGL port note: Changed sign in W component\n \tvOffset[ 1 ] = texcoord.xyxy + resolution.xyxy * vec4( 1.0, 0.0, 0.0, -1.0 ); // WebGL port note: Changed sign in W component\n \tvOffset[ 2 ] = texcoord.xyxy + resolution.xyxy * vec4( -2.0, 0.0, 0.0, 2.0 ); // WebGL port note: Changed sign in W component\n }\n\n void main() {\n\n \tvUv = uv;\n\n \tSMAAEdgeDetectionVS( vUv );\n\n \tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n }\n `,\n\n fragmentShader: /* glsl */ `\n uniform sampler2D tDiffuse;\n\n varying vec2 vUv;\n varying vec4 vOffset[ 3 ];\n\n vec4 SMAAColorEdgeDetectionPS( vec2 texcoord, vec4 offset[3], sampler2D colorTex ) {\n \tvec2 threshold = vec2( SMAA_THRESHOLD, SMAA_THRESHOLD );\n\n // Calculate color deltas:\n \tvec4 delta;\n \tvec3 C = texture2D( colorTex, texcoord ).rgb;\n\n \tvec3 Cleft = texture2D( colorTex, offset[0].xy ).rgb;\n \tvec3 t = abs( C - Cleft );\n \tdelta.x = max( max( t.r, t.g ), t.b );\n\n \tvec3 Ctop = texture2D( colorTex, offset[0].zw ).rgb;\n \tt = abs( C - Ctop );\n \tdelta.y = max( max( t.r, t.g ), t.b );\n\n // We do the usual threshold:\n \tvec2 edges = step( threshold, delta.xy );\n\n // Then discard if there is no edge:\n \tif ( dot( edges, vec2( 1.0, 1.0 ) ) == 0.0 )\n \t\tdiscard;\n\n // Calculate right and bottom deltas:\n \tvec3 Cright = texture2D( colorTex, offset[1].xy ).rgb;\n \tt = abs( C - Cright );\n \tdelta.z = max( max( t.r, t.g ), t.b );\n\n \tvec3 Cbottom = texture2D( colorTex, offset[1].zw ).rgb;\n \tt = abs( C - Cbottom );\n \tdelta.w = max( max( t.r, t.g ), t.b );\n\n // Calculate the maximum delta in the direct neighborhood:\n \tfloat maxDelta = max( max( max( delta.x, delta.y ), delta.z ), delta.w );\n\n // Calculate left-left and top-top deltas:\n \tvec3 Cleftleft = texture2D( colorTex, offset[2].xy ).rgb;\n \tt = abs( C - Cleftleft );\n \tdelta.z = max( max( t.r, t.g ), t.b );\n\n \tvec3 Ctoptop = texture2D( colorTex, offset[2].zw ).rgb;\n \tt = abs( C - Ctoptop );\n \tdelta.w = max( max( t.r, t.g ), t.b );\n\n // Calculate the final maximum delta:\n \tmaxDelta = max( max( maxDelta, delta.z ), delta.w );\n\n // Local contrast adaptation in action:\n \tedges.xy *= step( 0.5 * maxDelta, delta.xy );\n\n \treturn vec4( edges, 0.0, 0.0 );\n }\n\n void main() {\n\n \tgl_FragColor = SMAAColorEdgeDetectionPS( vUv, vOffset, tDiffuse );\n\n }\n `,\n}\n\nexport const SMAAWeightsShader = {\n defines: {\n SMAA_MAX_SEARCH_STEPS: '8',\n SMAA_AREATEX_MAX_DISTANCE: '16',\n SMAA_AREATEX_PIXEL_SIZE: '( 1.0 / vec2( 160.0, 560.0 ) )',\n SMAA_AREATEX_SUBTEX_SIZE: '( 1.0 / 7.0 )',\n },\n\n uniforms: {\n tDiffuse: { value: null },\n tArea: { value: null },\n tSearch: { value: null },\n resolution: { value: /* @__PURE__ */ new Vector2(1 / 1024, 1 / 512) },\n },\n\n vertexShader: /* glsl */ `\n uniform vec2 resolution;\n\n varying vec2 vUv;\n varying vec4 vOffset[ 3 ];\n varying vec2 vPixcoord;\n\n void SMAABlendingWeightCalculationVS( vec2 texcoord ) {\n \tvPixcoord = texcoord / resolution;\n\n // We will use these offsets for the searches later on (see @PSEUDO_GAT
|