-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to render shapes without graphics #2933
Comments
Certainly something we could look at :) |
Well, you can use "Graphics._renderSpriteRect" approach. Graphics uses renderTexture and sprites for sipmle rectangles, you can do the same: create renderTexture, then use sprites. var rect = this.graphicsData[0].shape;
if(!this._spriteRect)
{
if(!Graphics._SPRITE_TEXTURE)
{
Graphics._SPRITE_TEXTURE = RenderTexture.create(10, 10);
var currentRenderTarget = renderer._activeRenderTarget;
renderer.bindRenderTexture(Graphics._SPRITE_TEXTURE);
renderer.clear([1,1,1,1]);
renderer.bindRenderTarget(currentRenderTarget);
}
this._spriteRect = new Sprite(Graphics._SPRITE_TEXTURE);
}
if (this.tint === 0xffffff) {
this._spriteRect.tint = this.graphicsData[0].fillColor;
} else {
var t1 = tempColor1;
var t2 = tempColor2;
utils.hex2rgb(this.graphicsData[0].fillColor, t1);
utils.hex2rgb(this.tint, t2);
t1[0] *= t2[0];
t1[1] *= t2[1];
t1[2] *= t2[2];
this._spriteRect.tint = utils.rgb2hex(t1);
}
this._spriteRect.alpha = this.graphicsData[0].fillAlpha;
this._spriteRect.worldAlpha = this.worldAlpha * this._spriteRect.alpha;
Graphics._SPRITE_TEXTURE._frame.width = rect.width;
Graphics._SPRITE_TEXTURE._frame.height = rect.height;
this._spriteRect.transform.worldTransform = this.transform.worldTransform;
this._spriteRect.anchor.set(-rect.x / rect.width, -rect.y / rect.height);
this._spriteRect.onAnchorUpdate();
this._spriteRect._renderWebGL(renderer); |
We render rectangles, triangles and circles using only custom shaders. It's much faster than using Pixi Graphics objects and all edges are completely anti-aliased due to using a distance field calculation in the shader. Adding outlines, glows, shadows and other effects to these shapes is trivial. We simply adjust color, strokeWidth, strokeColor and various effects uniforms for the shaders. I would suggest looking into shader based shape/primitives rendering for a future version of Pixi, as it is infinitely superior to the current approach. |
Yeah but the thing is that render textures are much more cpu heavy than simple primitives (a rectangle is a textureless quad with a shader) should be, and if I have to resize that shape a lot (which i usually do) then either performance will take a hit or it will require a lot more code. |
That sounds really interesting @GordoRank ! Would love to see your implementation! @Dadibom - Graphics Rectangles are super optimised in pixi at the moment as they are batched into the sprite system. This is all done behind the scenes :) I guess what your asking for is a short hand way of creating a rectangle? |
Yeah but I still have to clear a texture and redraw it every frame, instead of just moving the individual rectangles |
How comes you need to clear them each frame? |
@Dadibom use multiple graphics, change position every time. As for your primitives, if you have something custom set, please make it a plugin. Especially if your stuff is tied to plots. https://github.com/pixijs/pixi-plugin-example . It will help others too. |
Doesn't work if I want to change the size :( |
Sure, I can use scale. But it's a lot more code than it has to be |
We basically have a complete PIXI powered desktop publishing application (shader based SDF text rendering / formatting, photo editing, page layout, drawing, bezier curves etc.) We simply extended PIXI a lot to meet our needs. This is an old PIXI 3.0 version of a circle / ellipse shader that lets you set the width, height, opacity, strokeWidth, fillColor and strokeColor. It's a bit messy and could be improved but it works perfectly for us. We have similar shaders for rectangles, triangles and pointed stars. These shaders are applied to a custom Pixi renderer that simply applies the shaders to a textureless quad.
I've stripped out the property definitions to keep this comment concise. |
@GoodBoyDigital because i need to get rid of the old rectangle |
@Dadibom good. You're on the half-way there to be official pixi plugin. For v4 you can remove "args" parameter of the shader, arguments will be extracted automagically. Also, you cant set anything to uniforms unless shader is bound . When renderer sets value for uniforms it must be something like that: myShader.bind();
myShader.uniforms.strokeWidth = ...; Look at example renderer. Also, shader code can be separated into "frag" and "vert" files, using glsify, example has it too. |
@GordoRank This is really exciting stuff! Would you consider sharing what you have - I think a lot of pixi users would find what you guys have created really awesome :) |
@GoodBoyDigital Of course. The team are currently tied up building a social networking and real time messaging infrastructure for the collaboration/community/social aspect of our app, and we therefore won't be out of beta until December at the earliest, so I can't really let anyone have a play now. But as soon as we are we will be setting up a developers blog describing our journey, challenges and techniques etc. As soon as that's up i'll share with you guys. And once we have migrated to PIXI version 4, we will start to look at what we can potentially put back into PIXI in terms of plugins etc. I think the text layout and SDF font rendering would be a huge boon for you guys for starters. |
Amazing! I (and i'm sure the rest of the pixi community) look forward to December :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Kicking life into this old thread since I am interested in two aspects that @GordoRank mentions.
Did you ever publish any of your work to the public? |
Hey, I think I should be able to render rectangles without having to draw to graphics objects. It would make a lot of my code so much easier! :)
The text was updated successfully, but these errors were encountered: