Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
[2016.10] Sprite:setBlendMode(src, dst) - Page 2 — Gideros Forum

[2016.10] Sprite:setBlendMode(src, dst)

2»

Comments

  • hgy29 said:

    but you can override the shader to use with a custom one on a sprite by sprite basis.

    I dont get it :D

    The only thing I can think is this:

    local fragmentShaderText = 
    [[
    uniform lowp vec4 fColor;
    uniform lowp sampler2D fTexture;
     
    varying mediump vec2 fTexCoord;
     
    void main(){
    	vec4 col = texture2D(fTexture, fTexCoord);
    	vec3 gammCorrection = pow(col.rgb, vec3(1.0/2.2));	
    	gl_FragColor = vec4(gammCorrection, col.a);
    }]]
    local vertexShaderText = [[
    attribute highp vec3 vVertex;
    attribute mediump vec2 vTexCoord;
    uniform highp mat4 vMatrix;
    varying mediump vec2 fTexCoord;
     
    void main() {
    	vec4 vertex = vec4(vVertex,1.0);
    	gl_Position = vMatrix*vertex;
    	fTexCoord=vTexCoord;
    }]]
    local shader=Shader.new(vertexShaderText,fragmentShaderText,Shader.FLAG_FROM_CODE,
    {
    	{name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true},
    	{name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false},
    	{name="fTexture",type=Shader.CTEXTURE,vertex=false},
    },
    {
    	{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0},
    	{name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0},
    	{name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0},
    })
     
    function Sprite:postInit()
    	self:setShader(shader)
    end

    Likes: hgy29

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    edited March 2020
    @rraptor, sure you can do that :)

    But that shader won't work for non textured shapes, particles, Path2D, etc...

    There are 11 shaders types used in Gideros:
    - Basic (Solid color, no texture, no per vertex color)
    - Color (Per vertex color)
    - Texture (Texture + color multiplier)
    - TextureAlpha (colored grey-scale/alpha texture, for fonts)
    - TextureColor (Texture + per vertex color)
    - TextureAlphaColor (Alpha Texture + per vertex color)
    - Particle (For liquidfun particles rendering)
    - Particles (For Gideros Particle sprite)
    - 3 shaders for Paths2D to render curves and outlines

    https://github.com/gideros/gideros/blob/master/2dsg/gfxbackends/Shaders.h#L68
  • well, i mostly composite meshes with a colored background, i guess as mesh inherits from sprite, i can change the shader of my meshes. am i right?
    also i don't know how i could change the background to linear color space, as that's not an element of the sprite hierarchy.
    (worst case i can make a mesh/pixel that has the background color but then i need to resize is any time the window is resized, also when i have an additional second screen then i need to resize it for that too, so it's a bit inconvenient).

    thanks for the tips so far.
Sign In or Register to comment.