Ok, time to have some more fun with gideros: GIDEROS LUA SHADERS
I am playing around to see what I can understand from the gideros lua shader demo. I have mixed two shaders wave + bloom and I see that I can get the outline of the character already So my goal has become to "code" a shader to have the outline of my character Please don't help me yet. Relax cafe category
still trying to understand shaders For normal shaders (glsl for example), I need 2 files: 1 for the vertex shader and 1 for the fragment shader. Then we pass them to Shader.new(...).
For lua shaders, we must include (or link to) Gideros\Library\luashader files in our projects. Then we write our vertex shader and our fragment shader in lua. Then lua shaders calls Shader.new(...).
Is that correct? I am trying to sort out shaders in the wiki
PS: there is a typo in luashader.lua?
function Shader.lua(vf,ff,opt,uniforms,attrs,varying,funcs,const,debug)local lang=Shader.getShaderLanguage()local mtd=Shader["lua_"..lang]assert(mtd,"Language not supported: "..lang)local _vshader,_fshader=mtd(vf,ff,opt,uniforms,attrs,varying,funcs or{},const)if funcs thenfor _,fg inipairs(funcs)do fg.code=nilendendifdebugthenprint("VSHADER_CODE:\n".._vshader)print("FSHADER_CODE:\n".._fshader)endifnot vdebug thenreturn Shader.new(_vshader,_fshader,Shader.FLAG_FROM_CODE|opt,uniforms,attrs)endend
It works great prior gideros 2022.1. My problem is I still don't understand nothing about shaders and I would like to port it to newer gideros version 2022.3.1
This is my attempt but gideros doesn't like it and throws errors:
local Outline1Effect=Core.class(ShaderEffect)
ShaderEffect.Outline1=Outline1Effect
makeEffect("Outline1", vertexShader,
function(vVertex, vColor, vTexCoord): Shader
local vertex = hF4(vVertex, 0.0, 1.0)
fTexCoord = vTexCoord
return vMatrix*vertex
THIS HAS BEEN REMOVED, NSFW ;-)
I tried to understand the other shaders as an example but I couldn't wrap my head around those, somebody please help me
hgy29 you are so kind to us, I knew it since day 1 but this shader thing, you gave everything to make our lifes simpler. I trully respect the LOVE you put in gideros and its users (us). So thank you, thank you, thank you.
After starting afresh I realised I had everything at my disposal in the gideros samples
So I picked the shader example and it was using the same logic as previous gideros (which I was more used to) with minor tweaks. And, to my surprise, I had clear explanations of what was not working!!! (hgy29 super kindness in action):
function TheStage:xRenderTarget()-- first render target so we can apply shaderslocal rt = RenderTarget.new(self.canvasw or8, self.canvash or8)local rbmp = Bitmap.new(rt)
rt:clear(0x0, 0)
rt:draw(self.camera.view)if self.outline then rbmp:setShader(Effect.outline)end-- then the actual output image
self.rt2:clear(0x0, 0)
self.rt2:draw(rbmp)
self.bmprt:setTexture(self.rt2)-- to show actual frame in the app (not needed for the output image)end
dear gideros people, do you know if it is possible to change the lighting color in the 3dbase shader (3DLighting.lua)?
A beginning of an answer it seems to be in 3DShaders.lua
local color0 = lF4(g_Color)local mycolor = lF4(1.0,0.0,0.0,1.0)--< here?-- if OPT_TEXTURED then color0 = color0*texture2D(g_Texture,texCoord) endif OPT_TEXTURED then color0 = color0*texture2D(g_Texture,texCoord)*mycolor end
How could I pass some external values (parameters) to work in this lua shader please? 3DShaders.lua
function D3._FLUA_Shader() : Shader
--mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)function cotangent_frame(N,p,uv)--// récupère les vecteurs du triangle composant le pixellocal dp1 = dFdx( p )
...
end--vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord )function perturb_normal( N, V, texcoord )--// N, la normale interpolée et--// V, le vecteur vue (vertex dirigé vers l'œil)local ret=hF3(0,0,0)
...
end
...
if OPT_NORMMAP then normal=perturb_normal(normal, viewDir, texCoord)endlocal diff =max(0.0, dot(normal, lightDir))-- 0.0 => CHANGE THIS ONE?local spec =0.0-- => MAYBE THIS ONE TOO?-- calculate shadowlocal shadow=1.0-- 1.0, 0.5, -- this seems to control the shadow width, in practice this blows the light!if(diff>=1)thenlocal nh =max(0.0, dot(reflect(-lightDir,normal),viewDir))
spec = pow(nh, 64.0)*shadow -- => 64.0 AND MAYBE THIS ONE TOO?end
diff=max(diff*shadow,ambient);local frag = lF4(color0.rgb * diff + color1 * spec, color0.a)return frag
end
Yes, you can use Shader.setConstant if you want to set a property on a shader for all sprites that use this shader, or Sprite:setShaderConstant if you want to set a constant specifically for a given Sprite
Shaders have floor() and ceil(), so trunc(n)=floor(n) if n is positive or ceil(n) otherwise. round(n) is same as floor(n+0.5) for n positive and ceil(n+0.5) for n negative.
But you can add bindings for trunc and floor in luashader.lua, for all three languages (GLSL,HLSL and MSL)
Comments
It works with lua already (but only in docking branch
https://github.com/MultiPain/Gideros_ImGui/blob/952ddd90a3cb54b8bdc4b3b793d2ad303025c6bb/main.cpp#L10346
So, I can give it a try.
Likes: MoKaLux, hgy29, luyimoon
For normal shaders (glsl for example), I need 2 files: 1 for the vertex shader and 1 for the fragment shader. Then we pass them to Shader.new(...).
For lua shaders, we must include (or link to) Gideros\Library\luashader files in our projects. Then we write our vertex shader and our fragment shader in lua. Then lua shaders calls Shader.new(...).
Is that correct? I am trying to sort out shaders in the wiki
PS: there is a typo in luashader.lua?
Likes: MoKaLux
I have this old outline shader made by great mister rrraptor
This is my attempt but gideros doesn't like it and throws errors:
I tried to understand the other shaders as an example but I couldn't wrap my head around those, somebody please help me
Likes: SinisterSoft
hgy29 you are so kind to us, I knew it since day 1 but this shader thing, you gave everything to make our lifes simpler. I trully respect the LOVE you put in gideros and its users (us). So thank you, thank you, thank you.
After starting afresh I realised I had everything at my disposal in the gideros samples
So I picked the shader example and it was using the same logic as previous gideros (which I was more used to) with minor tweaks. And, to my surprise, I had clear explanations of what was not working!!! (hgy29 super kindness in action):
1st attempt:
FragmentShader:
0(28) : error C0000: syntax error, unexpected '~', expecting ',' or ')' at token "~"
0(34) : error C1503: undefined variable "original"
0(36) : error C0000: syntax error, unexpected '}' at token "}"
2nd attempt:
FragmentShader:
0(28) : error C7011: implicit cast from "float" to "bool"
0(28) : error C1020: invalid operands to "=="
And the working result:
I wish you all the best, a special thought for our friend Oleg and his people, and my best wishes to you Nicolas (alias hgy29)
PS: this outline shader is the work of genius mister RRRAPTOR, THANK YOU!
Viva Gideros Luau, Peace &
Likes: SinisterSoft
Likes: SinisterSoft
Likes: MoKaLux, talis, hito9
There are those values
Can somebody point me in the right direction? Thank you for your help
3DShaders.lua
EDIT: https://wiki.gideros.rocks/index.php/Shader:setConstant
Likes: pie
Likes: MoKaLux
round round(x) Returns a value equal to the nearest integer to x.
https://wiki.gideros.rocks/index.php/Lua_Shader_Common_Functions
Some functions seem not implemented?
I tried with this code:
I tried with math.round but not working
Is there a work around please?
EDIT: looking into luashader.lua
Shaders have floor() and ceil(), so trunc(n)=floor(n) if n is positive or ceil(n) otherwise.
round(n) is same as floor(n+0.5) for n positive and ceil(n+0.5) for n negative.
But you can add bindings for trunc and floor in luashader.lua, for all three languages (GLSL,HLSL and MSL)
Likes: MoKaLux
https://godotshaders.com/shader/color-reduction-and-dither/#comment-1927
Gideros:
I think I got this cc0 one working as expected?
https://godotshaders.com/shader/256-colour-pixelation/
Gideros:
Viva Gideros