Jump to content

What is it with vTextureCoord (shaders)


Recommended Posts

So, I have set up my first shaders which just change colours.

Now I wanted to make a gradient shader but it won't work right.

It says: vTextureCoord is between 0 and 1. It is not. I apply the shader to some 16x16 Images, scaled to 2, and coords are way under 0.5.

To get the ALMOST right coordinate, I had to multiply it with 16. But also then, the gradient was a few pixels away from where they should be.

With x, it works "almost" right, but with y it works...not right. It's 1 in about the first quarter. (with *16.0, else it is black)

Can anyone explain that to me? PS: The screen is in a div with varying size (x) and 400px height.

It SHOULD work with that one, but if I copy that code, the above behaviour is given.

http://codepen.io/anon/pen/ORgkgY (not from me)

Thanks for your reply. Code is at work place, I will post it soon.

Link to comment
Share on other sites

I found a solution to this. (Still using pixijs v3)

In another post on another page, it stated that the first filter in the filter array does it wrong but if you add the shader a second time, it will work.

I did NOT use that solution, because there is a .shader variable. Using this, vTexCoord works just fine.

MySprite.filters = [shader, shader] <-- the mentioned fix, which I do NOT use.

MySprite.shader = shader <-- This works just fine. But you can use just one shader. I need only one shader so this is fine.

Maybe we can use multiple "simple" shaders in the .filters array and one "complex" shader in the .shader variable. I hope the two do not overwrite each other.

Link to comment
Share on other sites

There is a difference between the shader and the filter. A filter is run as a "post processing" step after the sprite renders itself normally (to a framebuffer). The shader property replaces the shader the sprite uses to draw itself, it is not run as a post-process step with the rendered sprite as the input.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...