12/24/2023 0 Comments Texturepacker polygonGl_FragColor = texture2D(CC_Texture0, fract(vec2(v_texCoord.x + offset, v_texCoord.y))). Last, the shader is using the offset like this: #ifdef GL_ESįloat height = 1.0 - (v_texCoord.y - heightOffset) * heightScale Grass2->getGLProgramState()->setUniformFloat("heightScale", 1 / ) Next I pass the height offset and scale to shader as uniforms using: grass2->getGLProgramState()->setUniformFloat("heightOffset", ) Grass2->getTextureRect().size.height / grass2->getTexture()->getContentSize().height Grass2->getTextureRect().size.width / grass2->getTexture()->getContentSize().width, If the images in a directory dont fit on the max size of a single page, multiple pages. For each directory of images TexturePacker encounters, it packs the images on to a larger texture, called a page. Given a directory, it recursively scans for image files. Grass2->getTextureRect().origin.y / grass2->getTexture()->getContentSize().height, TexturePacker can pack all images for an application in one shot. Grass2->getTextureRect().origin.x / grass2->getTexture()->getContentSize().width, I calculated offsets using following code: Rect grass2Offset( The solution was to calculate offsets in cocos2d-x and pass them to shader. The problem was with TexturePacker trimming but also with offsets in v_texCoord. Grass2->getGLProgramState()->setUniformFloat("bendFactor", RandomHelper::random_real(0.1f, 0.2f)) Grass2->getGLProgramState()->setUniformFloat("speed", RandomHelper::random_real(0.5f, 3.0f)) Grass2->setGLProgramState(mat->getTechniqueByName("grass")->getPassByIndex(0)->getGLProgramState()->clone()) Here is the code used to generate the grass sprite: // Smaller grassĪuto grass2 = Sprite::createWithSpriteFrameName("grass2.png") If what is happening is not clear I can provide some videos. Free plugins for all major software and renderers including Cycles, Vray, Corona, Octane, Redshift & Arnold. Gl_FragColor = texture2D(CC_Texture0, fract(vec2(v_texCoord.x + offset, v_texCoord.y))).rgba Sprite sheet packed with TexturePacker's polygon algorithm. This requires a game engine that supports polygon sprites. Offset *= (sin(CC_Time * speed) * bendFactor) Polygon The polygon algorithm removes transparent parts of the sprites to pack them even tighter. The problem is that if I'm using Sprite::createWithSpriteFrameName() and applying the same shader it looks like the offsets are wrong when calculating height also because it is moving at a larger degree, like it is using the height of the full texture from plist file: The shader works OK on texture loaded with Sprite::create() and it looks like this: Packing polygons is more efficient but slower and requires knowing the project file. I'm trying to implement a shader for grass in cocos2d-x. Packing during data export Running the texture packer separately.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |