Advertisement
Shadowfury333

bloom shader v0.31 tweaked

Dec 6th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.85 KB | None | 0 0
  1. -- $Id: BloomShader.lua 3171 2008-11-06 09:06:29Z det $
  2. function widget:GetInfo()
  3.     return {
  4.         name      = "BloomShader (v0.31) (unstable)",
  5.         desc      = "Sets Spring In Bloom (do not use with < 7xxx geforce series or non-latest ATI cards!)",
  6.         author    = "Kloot",
  7.         date      = "28-5-2008",
  8.         license   = "",
  9.         layer     = 9,
  10.         enabled   = false
  11.     }
  12. end
  13.  
  14.  
  15. -- CarRepairer: v0.31 has configurable settings in the menu.
  16.  
  17. options_path = 'Settings/Graphics/Effects/Bloom'
  18. options = {
  19.  
  20.     dbgDraw         = { type='bool',    name='Draw Only Bloom Mask',    value=false,        },
  21.     dilatePass      = { type='bool',    name='Dilate Pass',             value=false,        },
  22.    
  23.     glowAmplifier   = { type='number',      name='Glow Amplifier',          value=0.35,     min=0.001, max=3,step=0.001,    },
  24.     blurAmplifier   = { type='number',      name='Blur Amplifier',          value=1.0,  min=0.001, max=1.5,step=0.001,  },
  25.     illumThreshold  = { type='number',      name='Illumination Threshold',  value=0.65,         min=0, max=1,step=0.001,    },
  26.     blurPasses      = { type='number',      name='Blur Passes',             value=3,        min=0, max=10,step=1,       },
  27. }
  28.  
  29. -- config params
  30. local dbgDraw = 0                   -- draw only the bloom-mask? [0 | 1]
  31. local glowAmplifier = 0.35          -- intensity multiplier when filtering a glow source fragment [1, n]
  32. local blurAmplifier = 1.0 -- intensity multiplier when applying a blur pass [1, n] (should be set close to 1)
  33. local illumThreshold = 0.65         -- how bright does a fragment need to be before being considered a glow source? [0, 1]
  34. local blurPasses = 4                -- how many iterations of (7x7) Gaussian blur should be applied to the glow sources?
  35. local dilatePass = 0                -- dilate the glow sources after blurring? [0 | 1]
  36.  
  37. local function OnchangeFunc()
  38.     dbgDraw         = options.dbgDraw.value and 1 or 0
  39.     dilatePass      = options.dilatePass.value and 1 or 0
  40.    
  41.     glowAmplifier   = options.glowAmplifier.value
  42.     blurAmplifier   = options.blurAmplifier.value
  43.     illumThreshold  = options.illumThreshold.value
  44.     blurPasses      = options.blurPasses.value
  45.     dilatePass      = options.dilatePass.value
  46. end
  47. for key,option in pairs(options) do
  48.     option.OnChange = OnchangeFunc
  49. end
  50. OnchangeFunc()
  51.  
  52. -- non-editables
  53. local vsx = 1                       -- current viewport width
  54. local vsy = 1                       -- current viewport height
  55. local ivsx = 1.0 / vsx
  56. local ivsy = 1.0 / vsy
  57.  
  58. -- shader and texture handles
  59. local blurShaderH71 = nil
  60. local blurShaderV71 = nil
  61. local dilateShaderH51 = nil
  62. local dilateShaderV51 = nil
  63.  
  64. local brightShader = nil
  65. local brightTexture1 = nil
  66. local brightTexture2 = nil
  67.  
  68. local combineShader = nil
  69. local screenTexture = nil
  70. local screenTextureQuarter = nil
  71. local screenTextureSixteenth = nil
  72.  
  73. -- speedups
  74. local glGetSun = gl.GetSun
  75.  
  76. local glCreateTexture = gl.CreateTexture
  77. local glDeleteTexture = gl.DeleteTexture
  78. local glActiveTexture = gl.ActiveTexture
  79. local glCopyToTexture = gl.CopyToTexture
  80. local glRenderToTexture = gl.RenderToTexture
  81. local glTexture = gl.Texture
  82. local glTexRect = gl.TexRect
  83. local glGenerateMipmaps = gl.GenerateMipmap
  84.  
  85. local glGetShaderLog = gl.GetShaderLog
  86. local glCreateShader = gl.CreateShader
  87. local glDeleteShader = gl.DeleteShader
  88. local glUseShader = gl.UseShader
  89.  
  90. local glUniformInt = gl.UniformInt
  91. local glUniform = gl.Uniform
  92. local glGetUniformLocation = gl.GetUniformLocation
  93. local glGetActiveUniforms = gl.GetActiveUniforms
  94.  
  95.  
  96. local GL_RGBA32F_ARB                = 0x8814
  97. local GL_RGB32F_ARB                 = 0x8815
  98. local GL_ALPHA32F_ARB               = 0x8816
  99. local GL_INTENSITY32F_ARB           = 0x8817
  100. local GL_LUMINANCE32F_ARB           = 0x8818
  101. local GL_LUMINANCE_ALPHA32F_ARB     = 0x8819
  102. local GL_RGBA16F_ARB                = 0x881A
  103. local GL_RGB16F_ARB                 = 0x881B
  104. local GL_ALPHA16F_ARB               = 0x881C
  105. local GL_INTENSITY16F_ARB           = 0x881D
  106. local GL_LUMINANCE16F_ARB           = 0x881E
  107. local GL_LUMINANCE_ALPHA16F_ARB     = 0x881F
  108. local GL_TEXTURE_RED_TYPE_ARB       = 0x8C10
  109. local GL_TEXTURE_GREEN_TYPE_ARB     = 0x8C11
  110. local GL_TEXTURE_BLUE_TYPE_ARB      = 0x8C12
  111. local GL_TEXTURE_ALPHA_TYPE_ARB     = 0x8C13
  112. local GL_TEXTURE_LUMINANCE_TYPE_ARB = 0x8C14
  113. local GL_TEXTURE_INTENSITY_TYPE_ARB = 0x8C15
  114. local GL_TEXTURE_DEPTH_TYPE_ARB     = 0x8C16
  115. local GL_UNSIGNED_NORMALIZED_ARB    = 0x8C17
  116.  
  117.  
  118. -- shader uniform locations
  119. local brightShaderText0Loc = nil
  120. local brightShaderInvRXLoc = nil
  121. local brightShaderInvRYLoc = nil
  122. local brightShaderIllumLoc = nil
  123. local brightShaderFragLoc = nil
  124.  
  125. local blurShaderH51Text0Loc = nil
  126. local blurShaderH51InvRXLoc = nil
  127. local blurShaderH51FragLoc = nil
  128. local blurShaderV51Text0Loc = nil
  129. local blurShaderV51InvRYLoc = nil
  130. local blurShaderV51FragLoc = nil
  131.  
  132. local blurShaderH71Text0Loc = nil
  133. local blurShaderH71InvRXLoc = nil
  134. local blurShaderH71FragLoc = nil
  135. local blurShaderV71Text0Loc = nil
  136. local blurShaderV71InvRYLoc = nil
  137. local blurShaderV71FragLoc = nil
  138.  
  139. local dilateShaderH51Text0Loc = nil
  140. local dilateShaderH51InvRXLoc = nil
  141. local dilateShaderV51Text0Loc = nil
  142. local dilateShaderV51InvRYLoc = nil
  143.  
  144. local combineShaderDebgDrawLoc = nil
  145. local combineShaderTexture0Loc = nil
  146. local combineShaderTexture1Loc = nil
  147.  
  148.  
  149.  
  150. local function SetIllumThreshold()
  151.     local ra, ga, ba = glGetSun("ambient")
  152.     local rd, gd, bd = glGetSun("diffuse")
  153.     local rs, gs, bs = glGetSun("specular")
  154.  
  155.     local ambientIntensity  = ra * 0.299 + ga * 0.587 + ba * 0.114
  156.     local diffuseIntensity  = rd * 0.299 + gd * 0.587 + bd * 0.114
  157.     local specularIntensity = rs * 0.299 + gs * 0.587 + bs * 0.114
  158.  
  159.     -- illumThreshold = (0.8 * ambientIntensity) + (0.1 * diffuseIntensity) + (0.1 * specularIntensity)
  160.  
  161.     print("[BloomShader::SetIllumThreshold] sun ambient color:  ", ra .. ", " .. ga .. ", " .. ba .. " (intensity: " .. ambientIntensity .. ")")
  162.     print("[BloomShader::SetIllumThreshold] sun diffuse color:  ", rd .. ", " .. gd .. ", " .. bd .. " (intensity: " .. diffuseIntensity .. ")")
  163.     print("[BloomShader::SetIllumThreshold] sun specular color: ", rs .. ", " .. gs .. ", " .. bs .. " (intensity: " .. specularIntensity .. ")")
  164.     print("[BloomShader::SetIllumThreshold] illumination threshold: " .. illumThreshold)
  165. end
  166.  
  167. local function RemoveMe(msg)
  168.     Spring.Echo(msg)
  169.     widgetHandler:RemoveWidget()
  170. end
  171.  
  172.  
  173. function widget:ViewResize(viewSizeX, viewSizeY)
  174.     vsx = viewSizeX; ivsx = 1.0 / vsx
  175.     vsy = viewSizeY; ivsy = 1.0 / vsy
  176.  
  177.     glDeleteTexture(brightTexture1 or "")
  178.     glDeleteTexture(brightTexture2 or "")
  179.     glDeleteTexture(screenTexture or "")
  180.  
  181.     brightTexture1 = glCreateTexture(vsx/4, vsy/4, {
  182.         fbo = true, min_filter = GL.LINEAR, mag_filter = GL.LINEAR,
  183.         format = GL_RGB16F_ARB, wrap_s = GL.CLAMP, wrap_t = GL.CLAMP,
  184.     })
  185.     brightTexture2 = glCreateTexture(vsx/4, vsy/4, {
  186.         fbo = true, min_filter = GL.LINEAR, mag_filter = GL.LINEAR,
  187.         format = GL_RGB16F_ARB, wrap_s = GL.CLAMP, wrap_t = GL.CLAMP,
  188.     })
  189.  
  190.     screenTexture = glCreateTexture(vsx, vsy, {
  191.         min_filter = GL.LINEAR, mag_filter = GL.LINEAR,
  192.     })
  193.     screenTextureQuarter = glCreateTexture(vsx/2, vsy/2, {
  194.         min_filter = GL.LINEAR, mag_filter = GL.LINEAR,
  195.     })
  196.     screenTextureSixteenth = glCreateTexture(vsx/4, vsy/4, {
  197.         min_filter = GL.LINEAR, mag_filter = GL.LINEAR,
  198.     })
  199.  
  200.     if (brightTexture1 == nil or brightTexture2 == nil or screenTexture == nil or screenTextureQuarter == nil or screenTextureSixteenth == nil) then
  201.         RemoveMe("[BloomShader::ViewResize] removing widget, bad texture target")
  202.         return
  203.     end
  204. end
  205.  
  206. widget:ViewResize(widgetHandler:GetViewSizes())
  207.  
  208.  
  209.  
  210.  
  211. function widget:Initialize()
  212.     if (glCreateShader == nil) then
  213.         RemoveMe("[BloomShader::Initialize] removing widget, no shader support")
  214.         return
  215.     end
  216.  
  217.     SetIllumThreshold()
  218.  
  219.  
  220.  
  221.     combineShader = glCreateShader({
  222.         fragment = [[
  223.             uniform sampler2D texture0;
  224.             uniform sampler2D texture1;
  225.             uniform int debugDraw;
  226.  
  227.             void main(void) {
  228.  
  229.                 vec2 C0 = vec2(gl_TexCoord[0]);
  230.                 vec4 S0 = texture2D(texture0, C0);
  231.                 vec4 S1 = texture2D(texture1, C0);
  232.  
  233.  
  234.                 gl_FragColor = bool(debugDraw) ? S1 : (S0 + S1);
  235.             }
  236.         ]],
  237.  
  238.         uniformInt = { texture0 = 0, texture1 = 1, debugDraw = 0}
  239.     })
  240.  
  241.     if (combineShader == nil) then
  242.         RemoveMe("[BloomShader::Initialize] combineShader compilation failed"); print(glGetShaderLog()); return
  243.     end
  244.  
  245.  
  246.  
  247.     blurShaderH71 = glCreateShader({
  248.         fragment = [[
  249.             uniform sampler2D texture0;
  250.             uniform float inverseRX;
  251.             uniform float fragBlurAmplifier;
  252.             //const float invKernelSum = 0.015625;
  253.             const float bloomSigma = 2.5;
  254.  
  255.             void main(void) {
  256.                 vec2 C0 = vec2(gl_TexCoord[0]);
  257.  
  258.                 vec4 S = texture2D(texture0, C0);
  259.                 float weight = 1.0 / (2.50663 * bloomSigma);
  260.                 float total_weight = weight;
  261.                 S *= weight;
  262.                 for (float r = 1.0; r < 4.0; r += 1.0)
  263.                 {
  264.                     weight = exp(-((r*r)/(2.0 * bloomSigma * bloomSigma)))/(2.50663 * bloomSigma);
  265.                     S += texture2D(texture0, C0 - vec2(r * inverseRX, 0.0)) * weight;
  266.                     S += texture2D(texture0, C0 + vec2(r * inverseRX, 0.0)) * weight;
  267.  
  268.                     total_weight += 2*weight;
  269.                 }
  270.                 gl_FragColor = vec4(S.rgb/total_weight * fragBlurAmplifier, 1.0);
  271.             }
  272.         ]],
  273.  
  274.         uniformInt = {texture0 = 0},
  275.         uniformFloat = {inverseRX, fragBlurAmplifier}
  276.     })
  277.  
  278.     if (blurShaderH71 == nil) then
  279.         RemoveMe("[BloomShader::Initialize] blurShaderH71 compilation failed"); print(glGetShaderLog()); return
  280.     end
  281.  
  282.     blurShaderV71 = glCreateShader({
  283.         fragment = [[
  284.             uniform sampler2D texture0;
  285.             uniform float inverseRY;
  286.             uniform float fragBlurAmplifier;
  287.             //const float invKernelSum = 0.015625;
  288.             const float bloomSigma = 2.5;
  289.  
  290.             void main(void) {
  291.                 vec2 C0 = vec2(gl_TexCoord[0]);
  292.  
  293.                 vec4 S = texture2D(texture0, C0);
  294.                 float weight = 1.0 / (2.50663 * bloomSigma);
  295.                 float total_weight = weight;
  296.                 S *= weight;
  297.                 for (float r = 1.0; r < 4.0; r += 1.0)
  298.                 {
  299.                     weight = exp(-((r*r)/(2.0 * bloomSigma * bloomSigma)))/(2.50663 * bloomSigma);
  300.                     S += texture2D(texture0, C0 - vec2(0.0, r * inverseRY)) * weight;
  301.                     S += texture2D(texture0, C0 + vec2(0.0, r * inverseRY)) * weight;
  302.  
  303.                     total_weight += 2*weight;
  304.                 }
  305.                 gl_FragColor = vec4(S.rgb/total_weight * fragBlurAmplifier, 1.0);
  306.             }
  307.         ]],
  308.  
  309.         uniformInt = {texture0 = 0},
  310.         uniformFloat = {inverseRY, fragBlurAmplifier}
  311.     })
  312.  
  313.     if (blurShaderV71 == nil) then
  314.         RemoveMe("[BloomShader::Initialize] blurShaderV71 compilation failed"); print(glGetShaderLog()); return
  315.     end
  316.  
  317.  
  318.  
  319.     dilateShaderH51 = glCreateShader({
  320.         fragment = [[
  321.             uniform sampler2D texture0;
  322.             uniform float inverseRX;
  323.  
  324.             void main(void) {
  325.                 vec2 C0 = vec2(gl_TexCoord[0]);
  326.                 vec4 maxSample;
  327.  
  328.                 vec4 S0 = texture2D(texture0, C0 + vec2(-2.0 * inverseRX, 0.0));
  329.                 vec4 S1 = texture2D(texture0, C0 + vec2(-1.0 * inverseRX, 0.0));
  330.                 vec4 S2 = texture2D(texture0, C0 + vec2( 0.0            , 0.0));
  331.                 vec4 S3 = texture2D(texture0, C0 + vec2( 1.0 * inverseRX, 0.0));
  332.                 vec4 S4 = texture2D(texture0, C0 + vec2( 2.0 * inverseRX, 0.0));
  333.  
  334.                 maxSample    = max(S0,        S1);
  335.                 maxSample    = max(maxSample, S2);
  336.                 maxSample    = max(maxSample, S3);
  337.                 gl_FragColor = max(maxSample, S4);
  338.             }
  339.         ]],
  340.  
  341.         uniformInt = { texture0 = 0 },
  342.         uniformFloat = { inverseRX }
  343.     })
  344.  
  345.     if (dilateShaderH51 == nil) then
  346.         RemoveMe("[BloomShader::Initialize] dilateShaderH51 compilation failed"); print(glGetShaderLog()); return
  347.     end
  348.  
  349.     dilateShaderV51 = glCreateShader({
  350.         fragment = [[
  351.             uniform sampler2D texture0;
  352.             uniform float inverseRY;
  353.  
  354.             void main(void) {
  355.                 vec2 C0 = vec2(gl_TexCoord[0]);
  356.                 vec4 maxSample;
  357.  
  358.                 vec4 S0 = texture2D(texture0, C0 + vec2(0.0, -2.0 * inverseRY));
  359.                 vec4 S1 = texture2D(texture0, C0 + vec2(0.0, -1.0 * inverseRY));
  360.                 vec4 S2 = texture2D(texture0, C0 + vec2(0.0,  0.0            ));
  361.                 vec4 S3 = texture2D(texture0, C0 + vec2(0.0,  1.0 * inverseRY));
  362.                 vec4 S4 = texture2D(texture0, C0 + vec2(0.0,  2.0 * inverseRY));
  363.  
  364.  
  365.                 maxSample    = max(S0,        S1);
  366.                 maxSample    = max(maxSample, S2);
  367.                 maxSample    = max(maxSample, S3);
  368.                 gl_FragColor = max(maxSample, S4);
  369.             }
  370.         ]],
  371.  
  372.         uniformInt = { texture0 = 0 },
  373.         uniformFloat = { inverseRY }
  374.     })
  375.  
  376.     if (dilateShaderV51 == nil) then
  377.         RemoveMe("[BloomShader::Initialize] dilateShaderV51 compilation failed"); print(glGetShaderLog()); return
  378.     end
  379.  
  380.  
  381.  
  382.     brightShader = glCreateShader({
  383.         fragment = [[
  384.             uniform sampler2D texture0;
  385.             uniform float illuminationThreshold;
  386.             uniform float fragGlowAmplifier;
  387.             uniform float inverseRX;
  388.             uniform float inverseRY;
  389.  
  390.             void main(void) {
  391.                 vec2 C0 = vec2(gl_TexCoord[0]);
  392.                 vec3 color = vec3(texture2D(texture0, C0));
  393.                 float illum = dot(color, vec3(0.2990, 0.5870, 0.1140));
  394.  
  395. //              vec4 samples[25];
  396.  
  397.                 if (illum > illuminationThreshold) {
  398.                     gl_FragColor = vec4((color - color*(illuminationThreshold/max(illum, 0.00001))) * fragGlowAmplifier/max(1.0 - illuminationThreshold, 0.0001), 1.0);
  399.                 } else {
  400.                     gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
  401.                 }
  402.             }
  403.         ]],
  404.  
  405.         uniformInt = {texture0 = 0},
  406.         uniformFloat = {illuminationThreshold, fragGlowAmplifier, inverseRX, inverseRY}
  407.     })
  408.  
  409.     if (brightShader == nil) then
  410.         RemoveMe("[BloomShader::Initialize] brightShader compilation failed"); print(glGetShaderLog()); return
  411.     end
  412.  
  413.  
  414.  
  415.     brightShaderText0Loc = glGetUniformLocation(brightShader, "texture0")
  416.     brightShaderInvRXLoc = glGetUniformLocation(brightShader, "inverseRX")
  417.     brightShaderInvRYLoc = glGetUniformLocation(brightShader, "inverseRY")
  418.     brightShaderIllumLoc = glGetUniformLocation(brightShader, "illuminationThreshold")
  419.     brightShaderFragLoc = glGetUniformLocation(brightShader, "fragGlowAmplifier")
  420.  
  421.     blurShaderH71Text0Loc = glGetUniformLocation(blurShaderH71, "texture0")
  422.     blurShaderH71InvRXLoc = glGetUniformLocation(blurShaderH71, "inverseRX")
  423.     blurShaderH71FragLoc = glGetUniformLocation(blurShaderH71, "fragBlurAmplifier")
  424.     blurShaderV71Text0Loc = glGetUniformLocation(blurShaderV71, "texture0")
  425.     blurShaderV71InvRYLoc = glGetUniformLocation(blurShaderV71, "inverseRY")
  426.     blurShaderV71FragLoc = glGetUniformLocation(blurShaderV71, "fragBlurAmplifier")
  427.  
  428.     dilateShaderH51Text0Loc = glGetUniformLocation(dilateShaderH51, "texture0")
  429.     dilateShaderH51InvRXLoc = glGetUniformLocation(dilateShaderH51, "inverseRX")
  430.     dilateShaderV51Text0Loc = glGetUniformLocation(dilateShaderV51, "texture0")
  431.     dilateShaderV51InvRYLoc = glGetUniformLocation(dilateShaderV51, "inverseRY")
  432.  
  433.     combineShaderDebgDrawLoc = glGetUniformLocation(combineShader, "debugDraw")
  434.     combineShaderTexture0Loc = glGetUniformLocation(combineShader, "texture0")
  435.     combineShaderTexture1Loc = glGetUniformLocation(combineShader, "texture1")
  436. end
  437.  
  438. function widget:Shutdown()
  439.     glDeleteTexture(brightTexture1 or "")
  440.     glDeleteTexture(brightTexture2 or "")
  441.     glDeleteTexture(screenTexture or "")
  442.  
  443.     if (glDeleteShader) then
  444.         glDeleteShader(brightShader or 0)
  445.         glDeleteShader(blurShaderH71 or 0)
  446.         glDeleteShader(blurShaderV71 or 0)
  447.         glDeleteShader(dilateShaderH51 or 0)
  448.         glDeleteShader(dilateShaderV51 or 0)
  449.         glDeleteShader(combineShader or 0)
  450.     end
  451. end
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458. local function mglDrawTexture(texUnit, tex, w, h, flipS, flipT)
  459.     glTexture(texUnit, tex)
  460.     glTexRect(0, 0, w, h, flipS, flipT)
  461.     glTexture(texUnit, false)
  462. end
  463.  
  464. local function mglDrawFBOTexture(tex)
  465.     glTexture(tex)
  466.     glTexRect(-1, -1, 1, 1)
  467.     glTexture(false)
  468. end
  469.  
  470.  
  471. local function activeTextureFunc(texUnit, tex, w, h, flipS, flipT)
  472.     glTexture(texUnit, tex)
  473.     glTexRect(0, 0, w, h, flipS, flipT)
  474.     glTexture(texUnit, false)
  475. end
  476.  
  477. local function mglActiveTexture(texUnit, tex, w, h, flipS, flipT)
  478.     glActiveTexture(texUnit, activeTextureFunc, texUnit, tex, w, h, flipS, flipT)
  479. end
  480.  
  481.  
  482. local function renderToTextureFunc(tex, s, t)
  483.     glTexture(tex)
  484.     glTexRect(-1 * s, -1 * t,  1 * s, 1 * t)
  485.     glTexture(false)
  486. end
  487.  
  488. local function mglRenderToTexture(FBOTex, tex, s, t)
  489.     glRenderToTexture(FBOTex, renderToTextureFunc, tex, s, t)
  490. end
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497. local function Bloom()
  498.     gl.Color(1, 1, 1, 1)
  499.  
  500.     glCopyToTexture(screenTexture, 0, 0, 0, 0, vsx, vsy)
  501.  
  502.  
  503.     glUseShader(brightShader)
  504.         glUniformInt(brightShaderText0Loc, 0)
  505.         glUniform(   brightShaderInvRXLoc, ivsx)
  506.         glUniform(   brightShaderInvRYLoc, ivsy)
  507.         glUniform(   brightShaderIllumLoc, illumThreshold)
  508.         glUniform(   brightShaderFragLoc, glowAmplifier)
  509.         mglRenderToTexture(brightTexture1, screenTexture, 1, -1)
  510.     glUseShader(0)
  511.  
  512.  
  513.  
  514.     for i = 1, blurPasses do
  515.         glUseShader(blurShaderH71)
  516.             glUniformInt(blurShaderH71Text0Loc, 0)
  517.             glUniform(   blurShaderH71InvRXLoc, ivsx)
  518.             glUniform(   blurShaderH71FragLoc, blurAmplifier)
  519.             mglRenderToTexture(brightTexture2, brightTexture1, 1, -1)
  520.         glUseShader(0)
  521.         glUseShader(blurShaderV71)
  522.             glUniformInt(blurShaderV71Text0Loc, 0)
  523.             glUniform(   blurShaderV71InvRYLoc, ivsy)
  524.             glUniform(   blurShaderV71FragLoc, blurAmplifier)
  525.             mglRenderToTexture(brightTexture1, brightTexture2, 1, -1)
  526.         glUseShader(0)
  527.     end
  528.  
  529.  
  530.     if (dilatePass == 1) then
  531.         glUseShader(dilateShaderH51)
  532.             glUniformInt(dilateShaderH51Text0Loc, 0)
  533.             glUniform(   dilateShaderH51InvRXLoc, ivsx)
  534.             mglRenderToTexture(brightTexture2, brightTexture1, 1, -1)
  535.         glUseShader(0)
  536.         glUseShader(dilateShaderV51)
  537.             glUniformInt(dilateShaderV51Text0Loc, 0)
  538.             glUniform(   dilateShaderV51InvRYLoc, ivsy)
  539.             mglRenderToTexture(brightTexture1, brightTexture2, 1, -1)
  540.         glUseShader(0)
  541.     end
  542.  
  543.  
  544.     glUseShader(combineShader)
  545.         glUniformInt(combineShaderDebgDrawLoc, dbgDraw)
  546.         glUniformInt(combineShaderTexture0Loc, 0)
  547.         glUniformInt(combineShaderTexture1Loc, 1)
  548.         mglActiveTexture(0, screenTexture, vsx, vsy, false, true)
  549.         mglActiveTexture(1, brightTexture1, vsx, vsy, false, true)
  550.     glUseShader(0)
  551. end
  552.  
  553. function widget:DrawScreenEffects() Bloom() end
  554.  
  555.  
  556. --[[
  557. function widget:TextCommand(command)
  558.     if (string.find(command, "+illumthres") == 1) then illumThreshold = illumThreshold + 0.02 end
  559.     if (string.find(command, "-illumthres") == 1) then illumThreshold = illumThreshold - 0.02 end
  560.  
  561.     if (string.find(command, "+glowamplif") == 1) then glowAmplifier = glowAmplifier + 0.05 end
  562.     if (string.find(command, "-glowamplif") == 1) then glowAmplifier = glowAmplifier - 0.05 end
  563.  
  564.     if (string.find(command, "+bluramplif") == 1) then blurAmplifier = blurAmplifier + 0.05 end
  565.     if (string.find(command, "-bluramplif") == 1) then blurAmplifier = blurAmplifier - 0.05 end
  566.  
  567.     if (string.find(command, "+blurpasses") == 1) then blurPasses = blurPasses + 1 end
  568.     if (string.find(command, "-blurpasses") == 1) then blurPasses = blurPasses - 1 end
  569.  
  570.     if (string.find(command, "+dilatepass") == 1) then dilatePass = 1 end
  571.     if (string.find(command, "-dilatepass") == 1) then dilatePass = 0 end
  572.  
  573.     if (string.find(command, "+bloomdebug") == 1) then dbgDraw = 1 end
  574.     if (string.find(command, "-bloomdebug") == 1) then dbgDraw = 0 end
  575.  
  576.     illumThreshold = math.max(0.0, math.min(1.0, illumThreshold))
  577.     blurPasses = math.max(0, blurPasses)
  578.  
  579.     Spring.Echo("[BloomShader::TextCommand]")
  580.     Spring.Echo("   illumThreshold: " .. illumThreshold)
  581.     Spring.Echo("   glowAmplifier:  " .. glowAmplifier)
  582.     Spring.Echo("   blurAmplifier:  " .. blurAmplifier)
  583.     Spring.Echo("   blurPasses:     " .. blurPasses)
  584.     Spring.Echo("   dilatePass:     " .. dilatePass)
  585. end
  586. --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement