shader.py
# This script grab the shader text from the the Filter2D actuator,
# this way we can have code high lighting for the GLSL shader.
from bge import logic, render
#from bgl import *
scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner
bufA = scene.filterManager.addFilter(0, logic.RAS_2DFILTER_CUSTOMFILTER, cont.actuators["BufferA"].shaderText)
if 'ran' not in own:
own['ran']=True
own["iFrame"] = -1
bufA.addOffScreen(1, hdr=render.HDR_FULL_FLOAT)
image = scene.filterManager.addFilter(2, logic.RAS_2DFILTER_CUSTOMFILTER, cont.actuators["Image"].shaderText)
def run(cont):
own = cont.owner
if (own["iFrame"] >= 0):
# Setup textures
# id = bufA.offScreen.colorBindCodes[0]
# glBindTexture(GL_TEXTURE_2D, id)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
image.setTexture(0, bufA.offScreen.colorBindCodes[0], "iChannel0")
# Setup textures
# id = bufA.offScreen.colorBindCodes[0]
# glBindTexture(GL_TEXTURE_2D, id)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
bufA.setTexture(1, bufA.offScreen.colorBindCodes[0], "iChannel0")
own["iFrame"] += 1
Brvdbury
(Brvdbury)
April 6, 2019, 1:39pm
22
So is there a way to remove the flickering when moving the camera? Or at least make the flickering not as intense?
@Brvdbury
yeah the temporal bloom I made from this fixes that.
I use a render attachment in recent upbge master, however I reverted the shader to use renderedTexture
replace buffer A with this
https://pastebin.com/NDUCG7vn
replace shader.py with this.
# This script grab the shader text from the the Filter2D actuator,
# this way we can have code high lighting for the GLSL shader.
from bge import logic, render
#from bgl import *
scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner
bufA = scene.filterManager.addFilter(0, logic.RAS_2DFILTER_CUSTOMFILTER, cont.actuators["BufferA"].shaderText)
if 'ran' not in own:
own['ran']=True
own["iFrame"] = -1
bufA.addOffScreen(1, hdr=render.HDR_FULL_FLOAT)
image = scene.filterManager.addFilter(2, logic.RAS_2DFILTER_CUSTOMFILTER, cont.actuators["Image"].shaderText)
def run(cont):
own = cont.owner
if (own["iFrame"] >= 0):
# Setup textures
# id = bufA.offScreen.colorBindCodes[0]
# glBindTexture(GL_TEXTURE_2D, id)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
image.setTexture(0, bufA.offScreen.colorBindCodes[0], "iChannel0")
# Setup textures
# id = bufA.offScreen.colorBindCodes[0]
# glBindTexture(GL_TEXTURE_2D, id)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
bufA.setTexture(1, bufA.offScreen.colorBindCodes[0], "iChannel0")
own["iFrame"] += 1
Brvdbury
(Brvdbury)
April 6, 2019, 4:53pm
24
I’ve tried this script in 0.2.3 UPBGE and it doesn’t seem like it works. Do I need to be using 0.2.4 for it to work?
I just edited it to work without attachments and posted it,
let me test on my end.
(hrm I don’t have 0.2.3 installed anymore can you test on your end?)
edit: derp I can test it in 0.2.4 by removing the bge_dataTexture line
it works @Brvdbury
as you can see, now I can’t control what blooms
this is what makes the render attachment bloom buffer so handy
Brvdbury
(Brvdbury)
April 6, 2019, 5:00pm
26
The script doesn’t solve the flickering. The console comes back with this repeatedly.
I get a very very tiny bit of flicker in thisbuffer_bloom_temporal.blend (526.2 KB)
edit - video of tinkering to change the FX incoming.
edit2:
the flickiering is a product of the lowest level of mimpmap level having large chunks
maybe we disable this layer?
Brvdbury
(Brvdbury)
April 6, 2019, 5:28pm
28
I think it must be the version of the UPBGE causing your scripts to not work since this is the outcome from your .blend on 0.2.3 lol
I’d try 0.2.4 but the download page is down so I’m stuck with my version.
https://drive.google.com/open?id=12PabAgmGK7X5huwDGrQorswc8vrJ9KI_
win_64
this is upbge 0.2.4 + (current master I think)
here is a adjusted version of the file trying to counter some of the flicker
buffer_bloom_temporal_2.blend (526.2 KB)
edit:
did that work for you ? @Brvdbury
Brvdbury
(Brvdbury)
April 6, 2019, 5:53pm
30
It’s working but I’m still trying to understand all the new things you’ve added to the scripts. The shader.py adds motion blur to the effect, is it possible to remove that?
then it won’t have temporal sampling (averaging over time) - making it pop-ier
see where I do
bloom = bloom*1023;
and later
bloom = bloom /1024;
if that was
*1
and / 2
it would be instant
here is something instant without near the popping
buffer_bloom_temporal_3.blend (589.1 KB)
Adamantil1
(Diego Santos)
October 16, 2019, 5:46am
34
Hello everyone, I’m using this bloom script, but when I’m in game and using “restart” the scene screen appears without this bloom script triggered. Can anyone help?
is it printing anything in the console?
Adamantil1
(Diego Santos)
October 18, 2019, 6:30am
36
No.
Example
I make a scene using the bloom script.
I create a logic bricks by clicking “space” key the scene will restart.
I click “P” to start the scene, the bloom script works perfectly.
When the scene restarts by clicking spacekey the script bloom no longer works.
so this sounds like a GLSL issue / not getting the buffers again when you restart
it could be I am bad at glsl or a deeper structural issue.
do you think you could do
storedData = []
for object in scene.objects:
if 'Tracked' in objects:
props = []
for prop in object.getPropertyNames:
props.append( prop, object[prop] )
storeData.append( (object.name, object.worldTransform, props))
#using unique names is quite handy
and store data about all the objects in the scene and use this to ‘reset’ in py?
Max_Taylor
(Max Taylor)
December 6, 2019, 1:12am
38
The bloom shader script seems to break on scene restart, like Adamantil1 said.
The console says -
SystemError: Blender Game Engine data has not been freed, cannot use this python variable.
Usually I’d be able to fix this issue by enabling continuous reload on the python module, but then I run into a problem with the “shader module”?
I have a screenshot of the console here.
Any idea how to fix this?
Liebranca
(دانتي باولا)
December 6, 2019, 1:36am
39
Actuators->Game->Start game from file.
Adamantil1
(Diego Santos)
January 1, 2020, 6:16pm
40
Very simple and solved … thanks