parameters: (self, fullrebuild, changed)
return_statement: return True
docstring: Reconfigure is called whenever any configuration change is made.
docstring_summary: Reconfigure is called whenever any configuration change is made.
docstring_tokens: Reconfigure is called whenever any configuration change is made .
function: def reconfigure(self, fullrebuild, changed):
          """ Reconfigure is called whenever any configuration change is made. """
  
          configuration = self.configuration
  
          if fullrebuild:
              self.cleanup()
  
              if len(configuration) == 0:
                  return
  
              if not self.manager.win.gsg.getSupportsBasicShaders():
                  return False
  
              auxbits = 0
              needtex = set(["color"])
              needtexcoord = set(["color"])
  
              if "CartoonInk" in configuration:
                  needtex.add("aux")
                  auxbits |= AuxBitplaneAttrib.ABOAuxNormal
                  needtexcoord.add("aux")
  
              if "AmbientOcclusion" in configuration:
                  needtex.add("depth")
                  needtex.add("ssao0")
                  needtex.add("ssao1")
                  needtex.add("ssao2")
                  needtex.add("aux")
                  auxbits |= AuxBitplaneAttrib.ABOAuxNormal
                  needtexcoord.add("ssao2")
  
              if "BlurSharpen" in configuration:
                  needtex.add("blur0")
                  needtex.add("blur1")
                  needtexcoord.add("blur1")
  
              if "Bloom" in configuration:
                  needtex.add("bloom0")
                  needtex.add("bloom1")
                  needtex.add("bloom2")
                  needtex.add("bloom3")
                  auxbits |= AuxBitplaneAttrib.ABOGlow
                  needtexcoord.add("bloom3")
  
              if "ViewGlow" in configuration:
                  auxbits |= AuxBitplaneAttrib.ABOGlow
  
              if "VolumetricLighting" in configuration:
                  needtex.add(configuration["VolumetricLighting"].source)
  
              for tex in needtex:
                  self.textures[tex] = Texture("scene-" + tex)
                  self.textures[tex].setWrapU(Texture.WMClamp)
                  self.textures[tex].setWrapV(Texture.WMClamp)
  
              fbprops = None
              clamping = None
              if "HighDynamicRange" in configuration:
                  fbprops = FrameBufferProperties()
                  fbprops.setFloatColor(True)
                  fbprops.setSrgbColor(False)
                  clamping = False
  
              self.finalQuad = self.manager.renderSceneInto(textures = self.textures, auxbits=auxbits, fbprops=fbprops, clamping=clamping)
              if self.finalQuad is None:
                  self.cleanup()
                  return False
  
              if "BlurSharpen" in configuration:
                  blur0 = self.textures["blur0"]
                  blur1 = self.textures["blur1"]
                  self.blur.append(self.manager.renderQuadInto("filter-blur0", colortex=blur0, div=2))
                  self.blur.append(self.manager.renderQuadInto("filter-blur1", colortex=blur1))
                  self.blur[0].setShaderInput("src", self.textures["color"])
                  self.blur[0].setShader(Shader.make(BLUR_X, Shader.SL_Cg))
                  self.blur[1].setShaderInput("src", blur0)
                  self.blur[1].setShader(Shader.make(BLUR_Y, Shader.SL_Cg))
  
              if "AmbientOcclusion" in configuration:
                  ssao0 = self.textures["ssao0"]
                  ssao1 = self.textures["ssao1"]
                  ssao2 = self.textures["ssao2"]
                  self.ssao.append(self.manager.renderQuadInto("filter-ssao0", colortex=ssao0))
                  self.ssao.append(self.manager.renderQuadInto("filter-ssao1", colortex=ssao1, div=2))
                  self.ssao.append(self.manager.renderQuadInto("filter-ssao2", colortex=ssao2))
                  self.ssao[0].setShaderInput("depth", self.textures["depth"])
                  self.ssao[0].setShaderInput("normal", self.textures["aux"])
                  self.ssao[0].setShaderInput("random", base.loader.loadTexture("maps/random.rgb"))
                  self.ssao[0].setShader(Shader.make(SSAO_BODY % configuration["AmbientOcclusion"].numsamples, Shader.SL_Cg))
                  self.ssao[1].setShaderInput("src", ssao0)
                  self.ssao[1].setShader(Shader.make(BLUR_X, Shader.SL_Cg))
                  self.ssao[2].setShaderInput("src", ssao1)
                  self.ssao[2].setShader(Shader.make(BLUR_Y, Shader.SL_Cg))
  
              if "Bloom" in configuration:
                  bloomconf = configuration["Bloom"]
                  bloom0 = self.textures["bloom0"]
                  bloom1 = self.textures["bloom1"]
                  bloom2 = self.textures["bloom2"]
                  bloom3 = self.textures["bloom3"]
                  if bloomconf.size == "large":
                      scale=8
                      downsamplerName="filter-down4"
                      downsampler=DOWN_4
                  elif bloomconf.size == "medium":
                      scale=4
                      downsamplerName="filter-copy"
                      downsampler=COPY
                  else:
                      scale=2
                      downsamplerName="filter-copy"
                      downsampler=COPY
                  self.bloom.append(self.manager.renderQuadInto("filter-bloomi", colortex=bloom0, div=2,     align=scale))
                  self.bloom.append(self.manager.renderQuadInto(downsamplerName, colortex=bloom1, div=scale, align=scale))
                  self.bloom.append(self.manager.renderQuadInto("filter-bloomx", colortex=bloom2, div=scale, align=scale))
                  self.bloom.append(self.manager.renderQuadInto("filter-bloomy", colortex=bloom3, div=scale, align=scale))
                  self.bloom[0].setShaderInput("src", self.textures["color"])
                  self.bloom[0].setShader(Shader.make(BLOOM_I, Shader.SL_Cg))
                  self.bloom[1].setShaderInput("src", bloom0)
                  self.bloom[1].setShader(Shader.make(downsampler, Shader.SL_Cg))
                  self.bloom[2].setShaderInput("src", bloom1)
                  self.bloom[2].setShader(Shader.make(BLOOM_X, Shader.SL_Cg))
                  self.bloom[3].setShaderInput("src", bloom2)
                  self.bloom[3].setShader(Shader.make(BLOOM_Y, Shader.SL_Cg))
  
              texcoords = {}
              texcoordPadding = {}
  
              for tex in needtexcoord:
                  if self.textures[tex].getAutoTextureScale() != ATSNone or \
                                             "HalfPixelShift" in configuration:
                      texcoords[tex] = "l_texcoord_" + tex
                      texcoordPadding["l_texcoord_" + tex] = tex
                  else:
                      # Share unpadded texture coordinates.
                      texcoords[tex] = "l_texcoord"
                      texcoordPadding["l_texcoord"] = None
  
              texcoordSets = list(enumerate(texcoordPadding.keys()))
  
              text = "//Cg\n"
              if "HighDynamicRange" in configuration:
                  text += "static const float3x3 aces_input_mat = {\n"
                  text += "  {0.59719, 0.35458, 0.04823},\n"
                  text += "  {0.07600, 0.90834, 0.01566},\n"
                  text += "  {0.02840, 0.13383, 0.83777},\n"
                  text += "};\n"
                  text += "static const float3x3 aces_output_mat = {\n"
                  text += "  { 1.60475, -0.53108, -0.07367},\n"
                  text += "  {-0.10208,  1.10813, -0.00605},\n"
                  text += "  {-0.00327, -0.07276,  1.07602},\n"
                  text += "};\n"
              text += "void vshader(float4 vtx_position : POSITION,\n"
              text += "  out float4 l_position : POSITION,\n"
  
              for texcoord, padTex in texcoordPadding.items():
                  if padTex is not None:
                      text += "  uniform float4 texpad_tx%s,\n" % (padTex)
                      if "HalfPixelShift" in configuration:
                          text += "  uniform float4 texpix_tx%s,\n" % (padTex)
  
              for i, name in texcoordSets:
                  text += "  out float2 %s : TEXCOORD%d,\n" % (name, i)
  
              text += "  uniform float4x4 mat_modelproj)\n"
              text += "{\n"
              text += "  l_position = mul(mat_modelproj, vtx_position);\n"
  
              for texcoord, padTex in texcoordPadding.items():
                  if padTex is None:
                      text += "  %s = vtx_position.xz * float2(0.5, 0.5) + float2(0.5, 0.5);\n" % (texcoord)
                  else:
                      text += "  %s = (vtx_position.xz * texpad_tx%s.xy) + texpad_tx%s.xy;\n" % (texcoord, padTex, padTex)
  
                      if "HalfPixelShift" in configuration:
                          text += "  %s += texpix_tx%s.xy * 0.5;\n" % (texcoord, padTex)
  
              text += "}\n"
  
              text += "void fshader(\n"
  
              for i, name in texcoordSets:
                  text += "  float2 %s : TEXCOORD%d,\n" % (name, i)
  
              for key in self.textures:
                  text += "  uniform sampler2D k_tx" + key + ",\n"
  
              if "CartoonInk" in configuration:
                  text += "  uniform float4 k_cartoonseparation,\n"
                  text += "  uniform float4 k_cartooncolor,\n"
                  text += "  uniform float4 texpix_txaux,\n"
  
              if "BlurSharpen" in configuration:
                  text += "  uniform float4 k_blurval,\n"
  
              if "VolumetricLighting" in configuration:
                  text += "  uniform float4 k_casterpos,\n"
                  text += "  uniform float4 k_vlparams,\n"
  
              if "ExposureAdjust" in configuration:
                  text += "  uniform float k_exposure,\n"
  
              text += "  out float4 o_color : COLOR)\n"
              text += "{\n"
              text += "  o_color = tex2D(k_txcolor, %s);\n" % (texcoords["color"])
              if "CartoonInk" in configuration:
                  text += CARTOON_BODY % {"texcoord" : texcoords["aux"]}
              if "AmbientOcclusion" in configuration:
                  text += "  o_color *= tex2D(k_txssao2, %s).r;\n" % (texcoords["ssao2"])
              if "BlurSharpen" in configuration:
                  text += "  o_color = lerp(tex2D(k_txblur1, %s), o_color, k_blurval.x);\n" % (texcoords["blur1"])
              if "Bloom" in configuration:
                  text += "  o_color = saturate(o_color);\n"
                  text += "  float4 bloom = 0.5 * tex2D(k_txbloom3, %s);\n" % (texcoords["bloom3"])
                  text += "  o_color = 1-((1-bloom)*(1-o_color));\n"
              if "ViewGlow" in configuration:
                  text += "  o_color.r = o_color.a;\n"
              if "VolumetricLighting" in configuration:
                  text += "  float decay = 1.0f;\n"
                  text += "  float2 curcoord = %s;\n" % (texcoords["color"])
                  text += "  float2 lightdir = curcoord - k_casterpos.xy;\n"
                  text += "  lightdir *= k_vlparams.x;\n"
                  text += "  half4 sample = tex2D(k_txcolor, curcoord);\n"
                  text += "  float3 vlcolor = sample.rgb * sample.a;\n"
                  text += "  for (int i = 0; i < %s; i++) {\n" % (int(configuration["VolumetricLighting"].numsamples))
                  text += "    curcoord -= lightdir;\n"
                  text += "    sample = tex2D(k_tx%s, curcoord);\n" % (configuration["VolumetricLighting"].source)
                  text += "    sample *= sample.a * decay;//*weight\n"
                  text += "    vlcolor += sample.rgb;\n"
                  text += "    decay *= k_vlparams.y;\n"
                  text += "  }\n"
                  text += "  o_color += float4(vlcolor * k_vlparams.z, 1);\n"
  
              if "ExposureAdjust" in configuration:
                  text += "  o_color.rgb *= k_exposure;\n"
  
              # With thanks to Stephen Hill!
              if "HighDynamicRange" in configuration:
                  text += "  float3 aces_color = mul(aces_input_mat, o_color.rgb);\n"
                  text += "  o_color.rgb = saturate(mul(aces_output_mat, (aces_color * (aces_color + 0.0245786f) - 0.000090537f) / (aces_color * (0.983729f * aces_color + 0.4329510f) + 0.238081f)));\n"
  
              if "GammaAdjust" in configuration:
                  gamma = configuration["GammaAdjust"]
                  if gamma == 0.5:
                      text += "  o_color.rgb = sqrt(o_color.rgb);\n"
                  elif gamma == 2.0:
                      text += "  o_color.rgb *= o_color.rgb;\n"
                  elif gamma != 1.0:
                      text += "  o_color.rgb = pow(o_color.rgb, %ff);\n" % (gamma)
  
              if "SrgbEncode" in configuration:
                  text += "  o_color.r = (o_color.r < 0.0031308) ? (o_color.r * 12.92) : (1.055 * pow(o_color.r, 0.41666) - 0.055);\n"
                  text += "  o_color.g = (o_color.g < 0.0031308) ? (o_color.g * 12.92) : (1.055 * pow(o_color.g, 0.41666) - 0.055);\n"
                  text += "  o_color.b = (o_color.b < 0.0031308) ? (o_color.b * 12.92) : (1.055 * pow(o_color.b, 0.41666) - 0.055);\n"
  
              if "Inverted" in configuration:
                  text += "  o_color = float4(1, 1, 1, 1) - o_color;\n"
              text += "}\n"
  
              shader = Shader.make(text, Shader.SL_Cg)
              if not shader:
                  return False
              self.finalQuad.setShader(shader)
              for tex in self.textures:
                  self.finalQuad.setShaderInput("tx"+tex, self.textures[tex])
  
              self.task = taskMgr.add(self.update, "common-filters-update")
  
          if changed == "CartoonInk" or fullrebuild:
              if "CartoonInk" in configuration:
                  c = configuration["CartoonInk"]
                  self.finalQuad.setShaderInput("cartoonseparation", LVecBase4(c.separation, 0, c.separation, 0))
                  self.finalQuad.setShaderInput("cartooncolor", c.color)
  
          if changed == "BlurSharpen" or fullrebuild:
              if "BlurSharpen" in configuration:
                  blurval = configuration["BlurSharpen"]
                  self.finalQuad.setShaderInput("blurval", LVecBase4(blurval, blurval, blurval, blurval))
  
          if changed == "Bloom" or fullrebuild:
              if "Bloom" in configuration:
                  bloomconf = configuration["Bloom"]
                  intensity = bloomconf.intensity * 3.0
                  self.bloom[0].setShaderInput("blend", bloomconf.blendx, bloomconf.blendy, bloomconf.blendz, bloomconf.blendw * 2.0)
                  self.bloom[0].setShaderInput("trigger", bloomconf.mintrigger, 1.0/(bloomconf.maxtrigger-bloomconf.mintrigger), 0.0, 0.0)
                  self.bloom[0].setShaderInput("desat", bloomconf.desat)
                  self.bloom[3].setShaderInput("intensity", intensity, intensity, intensity, intensity)
  
          if changed == "VolumetricLighting" or fullrebuild:
              if "VolumetricLighting" in configuration:
                  config = configuration["VolumetricLighting"]
                  tcparam = config.density / float(config.numsamples)
                  self.finalQuad.setShaderInput("vlparams", tcparam, config.decay, config.exposure, 0.0)
  
          if changed == "AmbientOcclusion" or fullrebuild:
              if "AmbientOcclusion" in configuration:
                  config = configuration["AmbientOcclusion"]
                  self.ssao[0].setShaderInput("params1", config.numsamples, -float(config.amount) / config.numsamples, config.radius, 0)
                  self.ssao[0].setShaderInput("params2", config.strength, config.falloff, 0, 0)
  
          if changed == "ExposureAdjust" or fullrebuild:
              if "ExposureAdjust" in configuration:
                  stops = configuration["ExposureAdjust"]
                  self.finalQuad.setShaderInput("exposure", 2 ** stops)
  
          self.update()
          return True
function_tokens: def reconfigure ( self , fullrebuild , changed ) : configuration = self . configuration if fullrebuild : self . cleanup ( ) if len ( configuration ) == 0 : return if not self . manager . win . gsg . getSupportsBasicShaders ( ) : return False auxbits = 0 needtex = set ( [ "color" ] ) needtexcoord = set ( [ "color" ] ) if "CartoonInk" in configuration : needtex . add ( "aux" ) auxbits |= AuxBitplaneAttrib . ABOAuxNormal needtexcoord . add ( "aux" ) if "AmbientOcclusion" in configuration : needtex . add ( "depth" ) needtex . add ( "ssao0" ) needtex . add ( "ssao1" ) needtex . add ( "ssao2" ) needtex . add ( "aux" ) auxbits |= AuxBitplaneAttrib . ABOAuxNormal needtexcoord . add ( "ssao2" ) if "BlurSharpen" in configuration : needtex . add ( "blur0" ) needtex . add ( "blur1" ) needtexcoord . add ( "blur1" ) if "Bloom" in configuration : needtex . add ( "bloom0" ) needtex . add ( "bloom1" ) needtex . add ( "bloom2" ) needtex . add ( "bloom3" ) auxbits |= AuxBitplaneAttrib . ABOGlow needtexcoord . add ( "bloom3" ) if "ViewGlow" in configuration : auxbits |= AuxBitplaneAttrib . ABOGlow if "VolumetricLighting" in configuration : needtex . add ( configuration [ "VolumetricLighting" ] . source ) for tex in needtex : self . textures [ tex ] = Texture ( "scene-" + tex ) self . textures [ tex ] . setWrapU ( Texture . WMClamp ) self . textures [ tex ] . setWrapV ( Texture . WMClamp ) fbprops = None clamping = None if "HighDynamicRange" in configuration : fbprops = FrameBufferProperties ( ) fbprops . setFloatColor ( True ) fbprops . setSrgbColor ( False ) clamping = False self . finalQuad = self . manager . renderSceneInto ( textures = self . textures , auxbits = auxbits , fbprops = fbprops , clamping = clamping ) if self . finalQuad is None : self . cleanup ( ) return False if "BlurSharpen" in configuration : blur0 = self . textures [ "blur0" ] blur1 = self . textures [ "blur1" ] self . blur . append ( self . manager . renderQuadInto ( "filter-blur0" , colortex = blur0 , div = 2 ) ) self . blur . append ( self . manager . renderQuadInto ( "filter-blur1" , colortex = blur1 ) ) self . blur [ 0 ] . setShaderInput ( "src" , self . textures [ "color" ] ) self . blur [ 0 ] . setShader ( Shader . make ( BLUR_X , Shader . SL_Cg ) ) self . blur [ 1 ] . setShaderInput ( "src" , blur0 ) self . blur [ 1 ] . setShader ( Shader . make ( BLUR_Y , Shader . SL_Cg ) ) if "AmbientOcclusion" in configuration : ssao0 = self . textures [ "ssao0" ] ssao1 = self . textures [ "ssao1" ] ssao2 = self . textures [ "ssao2" ] self . ssao . append ( self . manager . renderQuadInto ( "filter-ssao0" , colortex = ssao0 ) ) self . ssao . append ( self . manager . renderQuadInto ( "filter-ssao1" , colortex = ssao1 , div = 2 ) ) self . ssao . append ( self . manager . renderQuadInto ( "filter-ssao2" , colortex = ssao2 ) ) self . ssao [ 0 ] . setShaderInput ( "depth" , self . textures [ "depth" ] ) self . ssao [ 0 ] . setShaderInput ( "normal" , self . textures [ "aux" ] ) self . ssao [ 0 ] . setShaderInput ( "random" , base . loader . loadTexture ( "maps/random.rgb" ) ) self . ssao [ 0 ] . setShader ( Shader . make ( SSAO_BODY % configuration [ "AmbientOcclusion" ] . numsamples , Shader . SL_Cg ) ) self . ssao [ 1 ] . setShaderInput ( "src" , ssao0 ) self . ssao [ 1 ] . setShader ( Shader . make ( BLUR_X , Shader . SL_Cg ) ) self . ssao [ 2 ] . setShaderInput ( "src" , ssao1 ) self . ssao [ 2 ] . setShader ( Shader . make ( BLUR_Y , Shader . SL_Cg ) ) if "Bloom" in configuration : bloomconf = configuration [ "Bloom" ] bloom0 = self . textures [ "bloom0" ] bloom1 = self . textures [ "bloom1" ] bloom2 = self . textures [ "bloom2" ] bloom3 = self . textures [ "bloom3" ] if bloomconf . size == "large" : scale = 8 downsamplerName = "filter-down4" downsampler = DOWN_4 elif bloomconf . size == "medium" : scale = 4 downsamplerName = "filter-copy" downsampler = COPY else : scale = 2 downsamplerName = "filter-copy" downsampler = COPY self . bloom . append ( self . manager . renderQuadInto ( "filter-bloomi" , colortex = bloom0 , div = 2 , align = scale ) ) self . bloom . append ( self . manager . renderQuadInto ( downsamplerName , colortex = bloom1 , div = scale , align = scale ) ) self . bloom . append ( self . manager . renderQuadInto ( "filter-bloomx" , colortex = bloom2 , div = scale , align = scale ) ) self . bloom . append ( self . manager . renderQuadInto ( "filter-bloomy" , colortex = bloom3 , div = scale , align = scale ) ) self . bloom [ 0 ] . setShaderInput ( "src" , self . textures [ "color" ] ) self . bloom [ 0 ] . setShader ( Shader . make ( BLOOM_I , Shader . SL_Cg ) ) self . bloom [ 1 ] . setShaderInput ( "src" , bloom0 ) self . bloom [ 1 ] . setShader ( Shader . make ( downsampler , Shader . SL_Cg ) ) self . bloom [ 2 ] . setShaderInput ( "src" , bloom1 ) self . bloom [ 2 ] . setShader ( Shader . make ( BLOOM_X , Shader . SL_Cg ) ) self . bloom [ 3 ] . setShaderInput ( "src" , bloom2 ) self . bloom [ 3 ] . setShader ( Shader . make ( BLOOM_Y , Shader . SL_Cg ) ) texcoords = { } texcoordPadding = { } for tex in needtexcoord : if self . textures [ tex ] . getAutoTextureScale ( ) != ATSNone or "HalfPixelShift" in configuration : texcoords [ tex ] = "l_texcoord_" + tex texcoordPadding [ "l_texcoord_" + tex ] = tex else : # Share unpadded texture coordinates. texcoords [ tex ] = "l_texcoord" texcoordPadding [ "l_texcoord" ] = None texcoordSets = list ( enumerate ( texcoordPadding . keys ( ) ) ) text = "//Cg\n" if "HighDynamicRange" in configuration : text += "static const float3x3 aces_input_mat = {\n" text += "  {0.59719, 0.35458, 0.04823},\n" text += "  {0.07600, 0.90834, 0.01566},\n" text += "  {0.02840, 0.13383, 0.83777},\n" text += "};\n" text += "static const float3x3 aces_output_mat = {\n" text += "  { 1.60475, -0.53108, -0.07367},\n" text += "  {-0.10208,  1.10813, -0.00605},\n" text += "  {-0.00327, -0.07276,  1.07602},\n" text += "};\n" text += "void vshader(float4 vtx_position : POSITION,\n" text += "  out float4 l_position : POSITION,\n" for texcoord , padTex in texcoordPadding . items ( ) : if padTex is not None : text += "  uniform float4 texpad_tx%s,\n" % ( padTex ) if "HalfPixelShift" in configuration : text += "  uniform float4 texpix_tx%s,\n" % ( padTex ) for i , name in texcoordSets : text += "  out float2 %s : TEXCOORD%d,\n" % ( name , i ) text += "  uniform float4x4 mat_modelproj)\n" text += "{\n" text += "  l_position = mul(mat_modelproj, vtx_position);\n" for texcoord , padTex in texcoordPadding . items ( ) : if padTex is None : text += "  %s = vtx_position.xz * float2(0.5, 0.5) + float2(0.5, 0.5);\n" % ( texcoord ) else : text += "  %s = (vtx_position.xz * texpad_tx%s.xy) + texpad_tx%s.xy;\n" % ( texcoord , padTex , padTex ) if "HalfPixelShift" in configuration : text += "  %s += texpix_tx%s.xy * 0.5;\n" % ( texcoord , padTex ) text += "}\n" text += "void fshader(\n" for i , name in texcoordSets : text += "  float2 %s : TEXCOORD%d,\n" % ( name , i ) for key in self . textures : text += "  uniform sampler2D k_tx" + key + ",\n" if "CartoonInk" in configuration : text += "  uniform float4 k_cartoonseparation,\n" text += "  uniform float4 k_cartooncolor,\n" text += "  uniform float4 texpix_txaux,\n" if "BlurSharpen" in configuration : text += "  uniform float4 k_blurval,\n" if "VolumetricLighting" in configuration : text += "  uniform float4 k_casterpos,\n" text += "  uniform float4 k_vlparams,\n" if "ExposureAdjust" in configuration : text += "  uniform float k_exposure,\n" text += "  out float4 o_color : COLOR)\n" text += "{\n" text += "  o_color = tex2D(k_txcolor, %s);\n" % ( texcoords [ "color" ] ) if "CartoonInk" in configuration : text += CARTOON_BODY % { "texcoord" : texcoords [ "aux" ] } if "AmbientOcclusion" in configuration : text += "  o_color *= tex2D(k_txssao2, %s).r;\n" % ( texcoords [ "ssao2" ] ) if "BlurSharpen" in configuration : text += "  o_color = lerp(tex2D(k_txblur1, %s), o_color, k_blurval.x);\n" % ( texcoords [ "blur1" ] ) if "Bloom" in configuration : text += "  o_color = saturate(o_color);\n" text += "  float4 bloom = 0.5 * tex2D(k_txbloom3, %s);\n" % ( texcoords [ "bloom3" ] ) text += "  o_color = 1-((1-bloom)*(1-o_color));\n" if "ViewGlow" in configuration : text += "  o_color.r = o_color.a;\n" if "VolumetricLighting" in configuration : text += "  float decay = 1.0f;\n" text += "  float2 curcoord = %s;\n" % ( texcoords [ "color" ] ) text += "  float2 lightdir = curcoord - k_casterpos.xy;\n" text += "  lightdir *= k_vlparams.x;\n" text += "  half4 sample = tex2D(k_txcolor, curcoord);\n" text += "  float3 vlcolor = sample.rgb * sample.a;\n" text += "  for (int i = 0; i < %s; i++) {\n" % ( int ( configuration [ "VolumetricLighting" ] . numsamples ) ) text += "    curcoord -= lightdir;\n" text += "    sample = tex2D(k_tx%s, curcoord);\n" % ( configuration [ "VolumetricLighting" ] . source ) text += "    sample *= sample.a * decay;//*weight\n" text += "    vlcolor += sample.rgb;\n" text += "    decay *= k_vlparams.y;\n" text += "  }\n" text += "  o_color += float4(vlcolor * k_vlparams.z, 1);\n" if "ExposureAdjust" in configuration : text += "  o_color.rgb *= k_exposure;\n" # With thanks to Stephen Hill! if "HighDynamicRange" in configuration : text += "  float3 aces_color = mul(aces_input_mat, o_color.rgb);\n" text += "  o_color.rgb = saturate(mul(aces_output_mat, (aces_color * (aces_color + 0.0245786f) - 0.000090537f) / (aces_color * (0.983729f * aces_color + 0.4329510f) + 0.238081f)));\n" if "GammaAdjust" in configuration : gamma = configuration [ "GammaAdjust" ] if gamma == 0.5 : text += "  o_color.rgb = sqrt(o_color.rgb);\n" elif gamma == 2.0 : text += "  o_color.rgb *= o_color.rgb;\n" elif gamma != 1.0 : text += "  o_color.rgb = pow(o_color.rgb, %ff);\n" % ( gamma ) if "SrgbEncode" in configuration : text += "  o_color.r = (o_color.r < 0.0031308) ? (o_color.r * 12.92) : (1.055 * pow(o_color.r, 0.41666) - 0.055);\n" text += "  o_color.g = (o_color.g < 0.0031308) ? (o_color.g * 12.92) : (1.055 * pow(o_color.g, 0.41666) - 0.055);\n" text += "  o_color.b = (o_color.b < 0.0031308) ? (o_color.b * 12.92) : (1.055 * pow(o_color.b, 0.41666) - 0.055);\n" if "Inverted" in configuration : text += "  o_color = float4(1, 1, 1, 1) - o_color;\n" text += "}\n" shader = Shader . make ( text , Shader . SL_Cg ) if not shader : return False self . finalQuad . setShader ( shader ) for tex in self . textures : self . finalQuad . setShaderInput ( "tx" + tex , self . textures [ tex ] ) self . task = taskMgr . add ( self . update , "common-filters-update" ) if changed == "CartoonInk" or fullrebuild : if "CartoonInk" in configuration : c = configuration [ "CartoonInk" ] self . finalQuad . setShaderInput ( "cartoonseparation" , LVecBase4 ( c . separation , 0 , c . separation , 0 ) ) self . finalQuad . setShaderInput ( "cartooncolor" , c . color ) if changed == "BlurSharpen" or fullrebuild : if "BlurSharpen" in configuration : blurval = configuration [ "BlurSharpen" ] self . finalQuad . setShaderInput ( "blurval" , LVecBase4 ( blurval , blurval , blurval , blurval ) ) if changed == "Bloom" or fullrebuild : if "Bloom" in configuration : bloomconf = configuration [ "Bloom" ] intensity = bloomconf . intensity * 3.0 self . bloom [ 0 ] . setShaderInput ( "blend" , bloomconf . blendx , bloomconf . blendy , bloomconf . blendz , bloomconf . blendw * 2.0 ) self . bloom [ 0 ] . setShaderInput ( "trigger" , bloomconf . mintrigger , 1.0 / ( bloomconf . maxtrigger - bloomconf . mintrigger ) , 0.0 , 0.0 ) self . bloom [ 0 ] . setShaderInput ( "desat" , bloomconf . desat ) self . bloom [ 3 ] . setShaderInput ( "intensity" , intensity , intensity , intensity , intensity ) if changed == "VolumetricLighting" or fullrebuild : if "VolumetricLighting" in configuration : config = configuration [ "VolumetricLighting" ] tcparam = config . density / float ( config . numsamples ) self . finalQuad . setShaderInput ( "vlparams" , tcparam , config . decay , config . exposure , 0.0 ) if changed == "AmbientOcclusion" or fullrebuild : if "AmbientOcclusion" in configuration : config = configuration [ "AmbientOcclusion" ] self . ssao [ 0 ] . setShaderInput ( "params1" , config . numsamples , - float ( config . amount ) / config . numsamples , config . radius , 0 ) self . ssao [ 0 ] . setShaderInput ( "params2" , config . strength , config . falloff , 0 , 0 ) if changed == "ExposureAdjust" or fullrebuild : if "ExposureAdjust" in configuration : stops = configuration [ "ExposureAdjust" ] self . finalQuad . setShaderInput ( "exposure" , 2 ** stops ) self . update ( ) return True