It looks like you're new here. If you want to get involved, click one of these buttons!
function GShape:initShader(blurLevel) local texw, texh = self:getSize() --Initial blur level self.blurShader:setConstant("fRad",Shader.CINT,1,blurLevel) --Initial texel size self.blurShader:setConstant("fTexelSize",Shader.CFLOAT4,1,{1/texw,1/texh,0,0}) self.blurBG = RenderTarget.new(texw,texh,false) self.blurBG:draw(stage) self.blurIMG = Bitmap.new(self.blurBG) self.blurIMG:setShader(self.blurShader) self.RT = RenderTarget.new(texw,texh,true) self:setTexture(self.RT) self:setShader(self.blurShader) end -- function GShape:updateBlur() local x,y = self:getPosition() local offsetX, offsetY = 0, 0 local texw, texh = self:getSize() -- circle is centerd, so we need to offset drawing position by its radius if (self.name == "circle") then offsetX = self.r offsetY = self.r end -- render stage except this object self:setVisible(false) self.blurBG:draw(stage, -x+offsetX, -y+offsetY) self:setVisible(true) self.blurShader:setConstant("fTexelSize",Shader.CFLOAT4,1,{0,1/texh,0,0}) --Step 1: Vertical blur self.RT:draw(self.blurIMG) self.blurShader:setConstant("fTexelSize",Shader.CFLOAT4,1,{1/texw,0,0,0}) --Step 2: Horizontal blur end -- function GShape:setPosition(x, y) Path2D.setPosition(self, x, y) self:updateBlur() end |
Comments
What exactly is your problem I don't really get it?
For your second question I think it's a mess because the shader is on top of another.
I am sure you have read this https://wiki.giderosmobile.com/index.php/Writing_Shaders
but that's pretty hard core, so beware
@hgy29 how can I pass vec2 value to shader instead of vec4?
For vec4 I must use this:
I tried to use Shader.DFLOAT, but it wont work, maybe I missed something... I think its an overkill for just a blur shader
Likes: Yan
Likes: rrraptor
Also, maybe its better to rewrite Shader constatnts description to somethink like:
Whole problem was in background rendering. So I did this:
I also modifed the shader (not by myself ofcourse ).
Source link
Project attached.
And the final queston, how can a recolor the texture? I mean, equivalent to setColorTransform, that only applies to texture. I understand that to achieve this I need to edit fragment shader, but idk how)))
Tried this:
I need you @hgy29
Likes: rrraptor
Likes: rrraptor
Blur works very strange. Every shape that is not rectangle offsets the background a bit (as you can see on a picture above). Need to fix it somehow... Probably texel size issue, but idk, need to do some tests.
Source
Also, to render shadow I downscale original shape, then render it to RenderTarget, apply blur, and upscale Bitmap to shape scale like that: 1/downScale. And for shadows I use different shader. I use shape:getSize() and set texel size to a {1/w, 0} for horizontal blur, and {0, 1/h} for vertical, but something is wrong...
EDIT: BTW gideros can compute the texel size for you with Shader.SYS TEXTUREINFO, with this attribute on a CFLOAT4 constant, gideros will fill it with the extent of the original texture in x and y, and the texel size in z and w
Btw, I added SYS_TEXTUREINFO flag, but they now flicking and look a bit strange:
Your issue is that you apply your blur to a Path2D shape, which only use texture coordinates for the 'filled' part, not for the outline. Since there is an outline in your case, the shape size is slightly bigger than the filled part (by the line thickness exactly). In theory, substracting the line width from the shape size before creating the render target should fix it.
Likes: rrraptor
It works even if I just use
But i discovered a very strange bug.
First, shape that is on top blures incorrectly (even with your fix), it dont have shadow, and its stroke is blured somehow.
Second, the circle also dont have shadow, and also have blured stroke, BUT! Its texture is 100% correct
Also, Im using Path2D because I didt find another way of applying some sort of mask on shader. Pixel and Bitmap are squares, Mesh is a black box for me, Shape... well I almost forgot about it, because we have more powerful and friendly Path2D
Now its all good, except this weird stoke blur effect...
P.S. lol, looking like this cat xDDD
EDIT: Ok, i tried the Shape object aaaand i got this
Stroke looks like a mess with virtices, but also texture itself is a small square (idk why).
In initBlurShader I added this:
Likes: MoKaLux
Shape do not have a stroke anymore.
Works on 2019.9, but does not on 2021.1
It uses Path2D as a shape.
@hgy29 is it possible to make it work again?)
Here is a simple version (lua shaders):
Old version (using glsl shaders):
To do so, setShader() was extended to take three more parameters, see https://wiki.gideros.rocks/index.php/Sprite:setShader
Extra parameters allows to select which kind of default shader to override, default being all. So if you don't specify a programType, your shader will be used for stroking too.
Since you want the blur to be applied to the shape fill operation, select program type Shader.SHADER PROGRAM TEXTURE:
Likes: rrraptor