Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17071

Vertex shader spriteframe origin and size

$
0
0

@natweiss wrote:

I have a fragment shader that basically converts texture coordinates (UV) to sprite frame coordinates (a subset of the total UV), then blurs the current pixel based on that spriteframe-relative Y pos. Pixels at y == 0 (again, in sprite frame coordinates) are not blurred at all. Pixels at y == 1 are blurred to the max.

The way I'm currently accomplishing this is to pass in two uniforms:

  1. vec2 containing the sprite frame's origin
  2. vec2 containing the sprite frame's size

Now this performs badly with lots of sprites because custom uniforms cannot currently be batched by cocos2d-x. An ideal solution would be to use a vertex shader and no custom uniforms.

I've tried messing with a_position and even multiplying it by the MV matrix and the P matrix, but no luck. It would help if somebody could explain what exactly is a_position within the cocos2d-x paradigm.

I see that cocos2d-x already has a_texCoord, a_texCoord1, a_texCoord2, a_texCoord3. It appears that 1-3 are not being used.

Would it be possible to go about passing in the current sprite frame's origin as a_texCoord1 and size as a_texCoord2? If so, where in cocos2d-x' rendering code would I start doing that?

I'm looking at Texture2D::drawAtPoint and Texture2D::drawInRect maybe but not sure if these are the right places or if this crazy strategy is even on the right track.

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>