Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Easier use of lua shaders — Gideros Forum

Easier use of lua shaders

Hi all,

Lua shaders is a fantastic feature of Gideros, I use them a lot myself but one need a bit of understanding about how they work and how to set them up in Gideros to actually take advantage of it. They became much more easier to write thanks to Luau, but even I still need to look at my previous code and Gideros built in shaders to use them again.

So I decided to write an utility class to help with that. It contains all gideros standard shaders re-written in lua so that you can just query for a standard lua shader template for a specific use, change the part you want (usually the frargment shader), and use it.

Example:
application:setBackgroundColor(0)
local font = TTFont.new("OpenSans-ExtraBold.ttf", 40, "")
local tf = TextField.new(font, "Funny colored text")
tf:setLayout{w = 400, h = 100, flags = 1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER}
tf:setPosition(0,40)
tf:setTextColor(0xFFFFFF,1)
stage:addChild(tf)
 
local shader=StandardShaders:getShaderSpecification(Shader.SHADER_PROGRAM_TEXTUREALPHA)
function shader.fragmentShader() : Shader
	local frag=lF4(fColor)*texture2D(fTexture, fTexCoord).aaaa
	frag.r=(sin(fTexCoord.x*300)+1)/2
	frag.g=(cos(fTexCoord.y*300)+1)/2
	frag.b=(cos((fTexCoord.y+fTexCoord.x)*100)+1)/2
	if (frag.a==0.0) then discard() end
	return frag
end
 
tf:setShader(shader:build())
I share it now, but I will make it part of luashader library in next Gideros.
lua
lua
stdluashaders.lua
10K
Tagged:
+1 -1 (+4 / -0 )Share on Facebook

Comments

  • Just in time for Christmas. :)
    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
  • MoKaLuxMoKaLux Member
    edited December 2022
    very nice +1. Some more info:
    - copy the stdluashaders.lua to the luashader folder
    - before the example code I needed to add this code (see: https://wiki.gideros.rocks/index.php/Loading_Order_of_Lua_Files):
    --!NEEDS:luashader/stdluashaders.lua
    application:setBackgroundColor(0)
    local font = TTFont.new("OpenSans-ExtraBold.ttf", 40, "")
    local tf = TextField.new(font, "Funny colored text")
    tf:setLayout{w = 400, h = 100, flags = 1280|FontBase.TLF_CENTER|FontBase.TLF_VCENTER}
    ...
    - you may need to get your own ttf font

    PS: doesn't look so nice on my mobile :/


    Likes: SinisterSoft, pie

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.