mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
Fix a bug with clamping, and added support for volumetric lighting
This commit is contained in:
parent
0b5d517dcd
commit
406ea02a5e
@ -93,6 +93,8 @@ class CommonFilters:
|
|||||||
auxbits |= AuxBitplaneAttrib.ABOGlow
|
auxbits |= AuxBitplaneAttrib.ABOGlow
|
||||||
for tex in needtex:
|
for tex in needtex:
|
||||||
self.textures[tex] = Texture("scene-"+tex)
|
self.textures[tex] = Texture("scene-"+tex)
|
||||||
|
self.textures[tex].setWrapU(Texture.WMClamp)
|
||||||
|
self.textures[tex].setWrapV(Texture.WMClamp)
|
||||||
needtexpix = True
|
needtexpix = True
|
||||||
|
|
||||||
self.finalQuad = self.manager.renderSceneInto(textures = self.textures, auxbits=auxbits)
|
self.finalQuad = self.manager.renderSceneInto(textures = self.textures, auxbits=auxbits)
|
||||||
@ -141,6 +143,10 @@ class CommonFilters:
|
|||||||
if (configuration.has_key("Bloom")):
|
if (configuration.has_key("Bloom")):
|
||||||
text += " uniform float4 texpad_txbloom3,\n"
|
text += " uniform float4 texpad_txbloom3,\n"
|
||||||
text += " out float4 l_texcoordB : TEXCOORD2,\n"
|
text += " out float4 l_texcoordB : TEXCOORD2,\n"
|
||||||
|
if (configuration.has_key("VolumetricLighting")):
|
||||||
|
text += "uniform float4x4 trans_model_to_clip_of_camera,\n"
|
||||||
|
text += "uniform float4 mspos_caster,\n"
|
||||||
|
text += "out float2 l_casterpos,\n"
|
||||||
text += " uniform float4x4 mat_modelproj)\n"
|
text += " uniform float4x4 mat_modelproj)\n"
|
||||||
text += "{\n"
|
text += "{\n"
|
||||||
text += " l_position=mul(mat_modelproj, vtx_position);\n"
|
text += " l_position=mul(mat_modelproj, vtx_position);\n"
|
||||||
@ -153,6 +159,8 @@ class CommonFilters:
|
|||||||
text += " l_texcoordC+=texpix_txcolor*0.5;\n"
|
text += " l_texcoordC+=texpix_txcolor*0.5;\n"
|
||||||
if (configuration.has_key("CartoonInk")):
|
if (configuration.has_key("CartoonInk")):
|
||||||
text += " l_texcoordN+=texpix_txaux*0.5;\n"
|
text += " l_texcoordN+=texpix_txaux*0.5;\n"
|
||||||
|
if (configuration.has_key("VolumetricLighting")):
|
||||||
|
text += " l_casterpos=(mul(trans_model_to_clip_of_camera, mspos_caster).xy);\n"
|
||||||
text += "}\n"
|
text += "}\n"
|
||||||
|
|
||||||
text += "void fshader(\n"
|
text += "void fshader(\n"
|
||||||
@ -167,6 +175,9 @@ class CommonFilters:
|
|||||||
text += "uniform sampler2D k_tx" + key + ",\n"
|
text += "uniform sampler2D k_tx" + key + ",\n"
|
||||||
if (configuration.has_key("CartoonInk")):
|
if (configuration.has_key("CartoonInk")):
|
||||||
text += "uniform float4 k_cartoonseparation,\n"
|
text += "uniform float4 k_cartoonseparation,\n"
|
||||||
|
if (configuration.has_key("VolumetricLighting")):
|
||||||
|
text += "uniform float4 k_vlparams,\n"
|
||||||
|
text += "float2 l_casterpos,\n"
|
||||||
text += "out float4 o_color : COLOR)\n"
|
text += "out float4 o_color : COLOR)\n"
|
||||||
text += "{\n"
|
text += "{\n"
|
||||||
text += " o_color = tex2D(k_txcolor, l_texcoordC.xy);\n"
|
text += " o_color = tex2D(k_txcolor, l_texcoordC.xy);\n"
|
||||||
@ -178,6 +189,20 @@ class CommonFilters:
|
|||||||
text += "o_color = 1-((1-bloom)*(1-o_color));\n"
|
text += "o_color = 1-((1-bloom)*(1-o_color));\n"
|
||||||
if (configuration.has_key("ViewGlow")):
|
if (configuration.has_key("ViewGlow")):
|
||||||
text += "o_color.r = o_color.a;\n"
|
text += "o_color.r = o_color.a;\n"
|
||||||
|
if (configuration.has_key("VolumetricLighting")):
|
||||||
|
text += "float decay = 1.0f;\n"
|
||||||
|
text += "float2 curcoord = l_texcoordC.xy;\n"
|
||||||
|
text += "float2 lightdir = normalize(curcoord - l_casterpos);\n"
text += "lightdir *= k_vlparams.y;\n"
|
||||||
|
text += "half4 sample = tex2D(k_txcolor, curcoord);\n"
|
||||||
|
text += "float3 vlcolor = sample.rgb * sample.a;\n"
|
||||||
|
text += "for (int i = 0; i < k_vlparams.x; i++) {\n"
|
||||||
|
text += " curcoord -= lightdir;\n"
|
||||||
|
text += " sample = tex2D(k_txcolor, curcoord);\n"
|
||||||
|
text += " sample *= sample.a * decay;//*weight\n"
|
||||||
|
text += " vlcolor += sample.rgb;\n"
|
||||||
|
text += " decay *= k_vlparams.z;\n"
|
||||||
|
text += "}\n"
|
||||||
|
text += "o_color += float4(vlcolor * k_vlparams.w, 1);\n"
|
||||||
if (configuration.has_key("Inverted")):
|
if (configuration.has_key("Inverted")):
|
||||||
text += "o_color = float4(1, 1, 1, 1) - o_color;\n"
|
text += "o_color = float4(1, 1, 1, 1) - o_color;\n"
|
||||||
text += "}\n"
|
text += "}\n"
|
||||||
@ -200,6 +225,14 @@ class CommonFilters:
|
|||||||
self.bloom[0].setShaderInput("desat", bloomconf.desat)
|
self.bloom[0].setShaderInput("desat", bloomconf.desat)
|
||||||
self.bloom[3].setShaderInput("intensity", intensity, intensity, intensity, intensity)
|
self.bloom[3].setShaderInput("intensity", intensity, intensity, intensity, intensity)
|
||||||
|
|
||||||
|
if (changed == "VolumetricLighting") or fullrebuild:
|
||||||
|
if (configuration.has_key("VolumetricLighting")):
|
||||||
|
config = configuration["VolumetricLighting"]
|
||||||
|
tcparam = (1.0 / config.density) / float(config.numsamples)
|
||||||
|
self.finalQuad.setShaderInput("camera", self.manager.camera)
|
||||||
|
self.finalQuad.setShaderInput("caster", config.caster)
|
||||||
|
self.finalQuad.setShaderInput("vlparams", config.numsamples, tcparam, 1.0 - config.decay, config.exposure)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setCartoonInk(self, separation=1):
|
def setCartoonInk(self, separation=1):
|
||||||
@ -275,3 +308,20 @@ class CommonFilters:
|
|||||||
return self.reconfigure(True, "Inverted")
|
return self.reconfigure(True, "Inverted")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def setVolumetricLighting(self, caster, numsamples = 32, density = 5.0, decay = 0.1, exposure = 0.1):
|
||||||
|
fullrebuild = (self.configuration.has_key("VolumetricLighting") == False)
|
||||||
|
newconfig = FilterConfig()
|
||||||
|
newconfig.caster = caster
|
||||||
|
newconfig.numsamples = numsamples
|
||||||
|
newconfig.density = density
|
||||||
|
newconfig.decay = decay
|
||||||
|
newconfig.exposure = exposure
|
||||||
|
self.configuration["VolumetricLighting"] = newconfig
|
||||||
|
return self.reconfigure(fullrebuild, "VolumetricLighting")
|
||||||
|
|
||||||
|
def delVolumetricLighting(self):
|
||||||
|
if (self.configuration.has_key("VolumetricLighting")):
|
||||||
|
del self.configuration["VolumetricLighting"]
|
||||||
|
return self.reconfigure(True, "VolumetricLighting")
|
||||||
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user