Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Can I ask some help with Shader understanding — Gideros Forum

Can I ask some help with Shader understanding

YanYan Member
edited January 2017 in Suggestions & requests
I have no experience in low level programming, so I cant make own Shader because the documentation is very poor. (Needed the simplest blur effect on sprite)

Ive read about GLSL shaders, but in the Gideros shader documentation there are some things I cant find in Google.

Heres the documentation example:
local shader=Shader.new("vShader","fShader",0,
{
{name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true},
{name="fTexelSize",type=Shader.CFLOAT4,vertex=false},
{name="fRad",type=Shader.CINT,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},
});
 
    vertex shader: (string) The path and name for the vertex shader without its extension
    fragment shader: (string) The path and name for the fragment shader without its extension
    flags: (number) A set of numerical flags or 0 if none
    uniform descriptor: (table) An array of uniforms/constants descriptors
    attribute descriptor: (table) An array of attributes descriptors
Now the questions: what means uniform descriptor and attribute descriptor, didnt found in Google and no info in documentation at all. How do they should be set, and for what those params are responsible.

uniform descriptor:
{name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true},
name, type, sys, vertex - what they are do and what for ?

attribute descriptor:
{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0},
what does this params do ? and what for ?

Also I cant understand how many and wich descriptor table indexes are required to shader work properly ?

I ready to pay for Skype lesson, better if it would be on Russian or with Russian speaker, because its not to easy for me undderstand such hard stuff on english. Please help me rise my skill !

Dislikes: stetso

vk.com/yan_alex
+1 -1 (+0 / -1 )Share on Facebook

Comments

  • Did you ever find this post? It has code for a blur, maybe it will suffice?

    http://giderosmobile.com/forum/discussion/6682/radial-blur-effect-class#Item_1

    It has been acknowledged that there needs to be better documentation for shaders. Hopefully that will happen soon :)
  • YanYan Member
    vitalitymobile, great thanks, ill back to thius theme after I read this =)
    vk.com/yan_alex
  • YanYan Member
    Did you ever find this post? It has code for a blur, maybe it will suffice?

    http://giderosmobile.com/forum/discussion/6682/radial-blur-effect-class#Item_1

    It has been acknowledged that there needs to be better documentation for shaders. Hopefully that will happen soon :)
    Yes, I saw, but it wouldnt work for me, I cant figure out why it doesnt works for, me so I decided to learn more about it

    vk.com/yan_alex
  • YanYan Member
    Did you ever find this post? It has code for a blur, maybe it will suffice?

    http://giderosmobile.com/forum/discussion/6682/radial-blur-effect-class#Item_1

    It has been acknowledged that there needs to be better documentation for shaders. Hopefully that will happen soon :)
    Hi, short question, please. Why I should draw my shader on RenderTarget , why its not applied if i setShader on my Sprite and then add it to the stage ? Is that shader specific ?
    vk.com/yan_alex
  • hgy29hgy29 Maintainer
    Accepted Answer
    Hi @Yan,

    It depends on what you want to achieve, you actually can use it on your sprite directly, but bear in mind that in that case it won't affect children of the sprite (shader is applied to the sprite itself only).
    That's why I used a rendertarget to first capture the whole sprite hierarchy then blur it.
  • YanYan Member
    edited January 2017
    Hi @Yan,

    It depends on what you want to achieve, you actually can use it on your sprite directly, but bear in mind that in that case it won't affect children of the sprite (shader is applied to the sprite itself only).
    That's why I used a rendertarget to first capture the whole sprite hierarchy then blur it.
    Works fine , thanks for advise.

    Can you try your shader on Shape - gives me very glitchy result if Filled by one color, and no blur if filled with texture. (Works fine only if I use RT)

    P.S. If shape has setLine style Gideros Player drops windows error. Next code wil produce error in v. 2016.10
    BlurEffect={}
     
    BlurEffect.VS_GL=[[
    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;
    }
    ]]
     
    BlurEffect.FS_GL=[[
    uniform lowp vec4 fColor;
    uniform lowp sampler2D fTexture;
    varying mediump vec2 fTexCoord;
    uniform mediump vec4 fTexSize;
     
    void main() {
     mediump vec4 frag=vec4(0,0,0,0); 
     mediump vec2 centerDir=normalize((fTexSize.xy/2.0-fTexCoord)/fTexSize.xy)*fTexSize.zw;
     for (int k=0;k<=5;k++)
    	frag=frag+texture2D(fTexture, fTexCoord-centerDir*float(k));
     frag=frag/6.0;
     if (frag.a<=0.0) discard;
     gl_FragColor = frag;
    }
    ]]
     
    BlurEffect.Shader=Shader.new(BlurEffect.VS_GL,BlurEffect.FS_GL,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="fTexSize",type=Shader.CFLOAT4,sys=Shader.SYS_TEXTUREINFO,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},
    });
     
    	local shape = Shape.new()
     
    	shape:setLineStyle(4, 0x000000)
     
    	shape:beginPath()
    	shape:moveTo(160, 50)
    	shape:lineTo(74, 284)
    	shape:lineTo(272, 130)
    	shape:lineTo(48, 130)
    	shape:lineTo(246, 284)
    	shape:closePath()
    	shape:endPath()
     
    	shape:setShader(BlurEffect.Shader)
     
    stage:addChild(shape)
    vk.com/yan_alex
  • hgy29hgy29 Maintainer
    Accepted Answer
    Not sure about why it crashes in some conditions, but I can explain why it doesn't look like you would expect. Gideros internaly uses a few standard shaders (6 iirc) depending on what it needs to draw (plain shapes, textured shapes, complex paths, etc). Each of those shader have specific inputs, and when using a custom shader with setShader(), your custom shader needs to strictly conform to what gideros supplies to it.

    Blur shader expects a texture and texture coordinates, and can be used in Bitmap, Pixel, some forms of Mesh and probably TileMap. It ought to work with Shape only if they are textured with no outline, and even in that case I am not sure that Shape sprite supplies the SYS_TEXTUREINFO values (which can be fixed).

    Does this help understanding ?
  • YanYan Member
    Not sure about why it crashes in some conditions, but I can explain why it doesn't look like you would expect. Gideros internaly uses a few standard shaders (6 iirc) depending on what it needs to draw (plain shapes, textured shapes, complex paths, etc). Each of those shader have specific inputs, and when using a custom shader with setShader(), your custom shader needs to strictly conform to what gideros supplies to it.

    Blur shader expects a texture and texture coordinates, and can be used in Bitmap, Pixel, some forms of Mesh and probably TileMap. It ought to work with Shape only if they are textured with no outline, and even in that case I am not sure that Shape sprite supplies the SYS_TEXTUREINFO values (which can be fixed).

    Does this help understanding ?
    Yes, totally, thanks a LOT ! This is almot intersects my own thoughts, that Shape aint works as Sprite with Texture, and requires different coding approach in Shader. Currently studing about shaders, I think i will have more questions to you in future, sorry about ))))
    vk.com/yan_alex
Sign In or Register to comment.