// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

// clang-format off
// This file has been automatically generated from resource file resources/Shaders/RaytraceSmooth.fs

static const char Shaders_RaytraceSmooth_fs[] =
  "//! Input ray-traced image.\n"
  "uniform sampler2D uFSAAInputTexture;\n"
  "\n"
  "//! Number of accumulated FSAA samples.\n"
  "uniform int uSamples;\n"
  "\n"
  "//! Output pixel color.\n"
  "out vec4 OutColor;\n"
  "\n"
  "#define LUM_DIFFERENCE 0.085f\n"
  "\n"
  "// =======================================================================\n"
  "// function : main\n"
  "// purpose  :\n"
  "// =======================================================================\n"
  "void main (void)\n"
  "{\n"
  "#ifndef PATH_TRACING\n"
  "\n"
  "  int aPixelX = int (gl_FragCoord.x);\n"
  "  int aPixelY = int (gl_FragCoord.y);\n"
  "\n"
  "  // Adjust FLIPTRI pattern used for adaptive FSAA\n"
  "  float anOffsetX = mix (uFsaaOffset.x, -uFsaaOffset.x, float (aPixelX % 2));\n"
  "  float anOffsetY = mix (uFsaaOffset.y, -uFsaaOffset.y, float (aPixelY % 2));\n"
  "\n"
  "  vec4 aClr0 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 0), 0);\n"
  "  vec4 aClr1 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY - 1), 0);\n"
  "  vec4 aClr2 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 1), 0);\n"
  "\n"
  "  vec4 aClr3 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 1, aPixelY + 0), 0);\n"
  "  vec4 aClr4 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 1, aPixelY - 1), 0);\n"
  "  vec4 aClr5 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 1, aPixelY + 1), 0);\n"
  "\n"
  "  vec4 aClr6 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX - 1, aPixelY + 0), 0);\n"
  "  vec4 aClr7 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX - 1, aPixelY - 1), 0);\n"
  "  vec4 aClr8 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX - 1, aPixelY + 1), 0);\n"
  "\n"
  "  float aLum = dot (LUMA, aClr0.xyz);\n"
  "\n"
  "  bool aRender = abs (aClr1.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr2.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr3.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr4.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr5.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr6.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr7.w - aClr0.w) > LUM_DIFFERENCE ||\n"
  "                 abs (aClr8.w - aClr0.w) > LUM_DIFFERENCE;\n"
  "\n"
  "  if (!aRender)\n"
  "  {\n"
  "    aRender = abs (dot (LUMA, aClr1.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr2.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr3.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr4.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr5.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr6.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr7.xyz) - aLum) > LUM_DIFFERENCE ||\n"
  "              abs (dot (LUMA, aClr8.xyz) - aLum) > LUM_DIFFERENCE;\n"
  "  }\n"
  "\n"
  "  vec4 aColor = aClr0;\n"
  "\n"
  "  if (aRender)\n"
  "  {\n"
  "    SRay aRay = GenerateRay (vPixel + vec2 (anOffsetX, anOffsetY));\n"
  "\n"
  "    vec3 aInvDirect = 1.f / max (abs (aRay.Direct), SMALL);\n"
  "\n"
  "    aInvDirect = vec3 (aRay.Direct.x < 0.f ? -aInvDirect.x : aInvDirect.x,\n"
  "                       aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y,\n"
  "                       aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);\n"
  "\n"
  "    aColor = mix (aClr0, clamp (Radiance (aRay, aInvDirect), 0.0, 1.0), 1.0 / float(uSamples));\n"
  "  }\n"
  "\n"
  "  OutColor = aColor;\n"
  "\n"
  "#endif\n"
  "}\n";

// clang-format on
