Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Using Shader — Gideros Forum

Using Shader

totebototebo Member
edited May 2016 in General questions
The example used for the Shader class causes a crash with no error (in build 2016-04). How would I get a simple test with Shader going?

http://docs.giderosmobile.com/reference/gideros/Shader#Shader
My Gideros games: www.totebo.com

Comments

  • hgy29hgy29 Maintainer
    Did you include vShader.glsl and pShader.glsl files in your project ?
    This example is more of a syntax example than a fully working one. Have a look at shader example projects from gideros example collection.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    Great, I thought I may have missed something basic. I didn't include those files. Thanks!

    PS. May be an idea to mention that in the online reference?
    My Gideros games: www.totebo.com
  • totebototebo Member
    I've started playing with this. Exciting! Can I confirm that nested sprites are not supported?

    If I want to blur a game world, for instance, with hundreds of nested sprites inside, would I have to loop through all sprites and apply the shader to each individual one?
    My Gideros games: www.totebo.com
  • keszeghkeszegh Member
    @totebo, probably it's simpler in this case to render the sprite hierarchy to a rendertarget and then apply the shader to this rendertarget only (And add this to the stage, not the sprite hierarchy).

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • totebototebo Member
    Genius. Thanks, I was just about to start scratching my head. :)
    My Gideros games: www.totebo.com
  • keszeghkeszegh Member
    i always imagine rendertarget being the equivalent of merging layers in a painting application. (actually it's of course better then merging as you still have the separate layers as well, not just the merged one).
  • totebototebo Member
    I just remembered the new Viewport, as maybe a more efficient option. My first test failed, however, so probably not supported. I would need to update the blurred background every frame or so, which is why I'm wondering if RenderTarget is up to the task.
    My Gideros games: www.totebo.com
  • totebototebo Member
    Update: I tested this on an iPod touch 5th gen (one of my slowest devices) and there is little to no slowdown. RenderTarget for the win!
    My Gideros games: www.totebo.com
  • totebototebo Member
    As a side note; the blur works on the desktop player, but not on mobile.

    iOS:

    FragmentShader:
    ERROR: 0:12: '*' does not operate on 'vec2' and 'int'
    ERROR: 0:15: Use of undeclared identifier 'tc'
    ERROR: 0:16: Use of undeclared identifier 'tc'
    ERROR: 0:18: '/' does not operate on 'vec4' and 'int'

    Android:

    FragmentShader:
    ERROR: 0:12: '*' : wrong operand types no operation '*' exists that takes a left-hand operand of type '2-component vector of float' and a right operand of type 'uniform int' (or there is no acceptable conversion)
    ERROR: 0:18: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type '4-component vector of float' and a right operand of type 'int' (or there is no acceptable conversion)
    ERROR: 2 compilation errors. No code generated.

    It feels like I've stumbled on a whole new kettle of fish here, and I feel a little lost. :)

    The above errors happen with this code (from the docs):
    local shader=Shader.new("vShader","fShader",0, {
     {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="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}, });
    My Gideros games: www.totebo.com
  • hgy29hgy29 Maintainer
    Yeah, the Blur fragment shader syntax should be modified to cope with more stringent shader requirement on GL ES.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • john26john26 Maintainer
    @totebo, we desperately need tutorials on this. I'm going to add some soon! (but 3d graphics first)

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    BTW I fixed the blur shader for next release.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • YanYan Member
    edited May 2022
    totebo said:

    The example used for the Shader class causes a crash with no error (in build 2016-04). How would I get a simple test with Shader going?

    http://docs.giderosmobile.com/reference/gideros/Shader#Shader

    did you tried Viewport with Shader? Is this works or we can only RT?
    vk.com/yan_alex
Sign In or Register to comment.