Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Bloom and decay without a custom shader... — Gideros Forum

Bloom and decay without a custom shader...

Was tinkering and had some advice from some friends about alternative ways to do bloom and I realised that it could be done without using a custom shader at all - just standard Gideros commands, the problem was that it over-bloomed and needed fading, so I used the setColorTransform to fade and keep the bloom under control. The result is kinda pretty...



First you need to setup the screen
oddEven=0
local width=application:getContentWidth()
local height=application:getContentHeight()
local screenSizeX,screenSizeY=application:getDeviceHeight(),application:getDeviceWidth()
 
bloomScale=2
screenTexture={}
screenDraw={}
bloomCapture={}
oldScreen={}
for loop=1,2 do
	screenTexture[loop]=RenderTarget.new(screenSizeX,screenSizeY,true)
	screenTexture[loop]:clear(0,1)
	screenDraw[loop]=Bitmap.new(screenTexture[loop])
	screenDraw[loop]:setScale(width/screenSizeX,height/screenSizeY)
	screenDraw[loop]:setVisible(false)
	stage:addChild(screenDraw[loop])
end
bloomCapture[1]=Bitmap.new(screenTexture[2])
bloomCapture[2]=Bitmap.new(screenTexture[1])
bloomCapture[1]:setScale(1/bloomScale)
bloomCapture[2]:setScale(1/bloomScale)
print(screenSizeX,screenSizeY)
bloomScreen=RenderTarget.new(screenSizeX/bloomScale,screenSizeY/bloomScale,true)
bloomSprite=Bitmap.new(bloomScreen)
bloomSprite:setScale(bloomScale,bloomScale)
bloomSprite:setColorTransform(0.96,0.96,0.96)  -- this is the decay, smaller for faster decay
 
screenRender=Sprite.new()
screenRender:setScale(screenSizeX/width,screenSizeY/height)
screenRender:setBlendMode("add")
Then in your main game enter_frame loop (I have one running constantly) add this just before the end:
	local oo=(oddEven%2)+1
	oddEven+=1
	local oe=(oddEven%2)+1
	bloomScreen:draw(bloomCapture[oe])
	screenTexture[oe]:draw(bloomSprite)
	screenTexture[oe]:draw(screenRender)
	screenDraw[oe]:setVisible(true)
	screenDraw[oo]:setVisible(false)
Then just add all your game sprites to screenRender rather than stage. If you use sceneManager then add it like this rather than to stage...
screenRender:addChild(sceneManager)
This is the result:
https://deluxepixel.com/players/bacteria/


2019-12-15_20-19-39.png
2003 x 1252 - 1M
2019-12-15_20-19-39.png
2003 x 1252 - 1M
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
+1 -1 (+5 / -0 )Share on Facebook

Comments

Sign In or Register to comment.