krzysztof.s Posted January 26, 2017 Share Posted January 26, 2017 Is there any possibility to set custom color in Sprite2D? For now there is only opacity property. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 27, 2017 Share Posted January 27, 2017 Hiya K, welcome to the forum. Generally Sprite2D's are images... and use the image colors. http://babylonjs-playground.com/#20MSFF#16 In the Canvas2D overview doc, see the "Shape based"? THOSE type of primitives have some "you draw it" abilities. Perhaps that is more appropriate? I'm not sure how/where you would apply a "custom color" to a Sprite2d. Perhaps background color... for images with alpha transparency? (use a filled rectangle2d behind it) Can you elaborate a bit? thx. Quote Link to comment Share on other sites More sharing options...
krzysztof.s Posted January 27, 2017 Author Share Posted January 27, 2017 I want to have only one texture and have a possibility to have multiple instances on a scene, and multiply original texture's pixels' colors by some custom color, like color property in NGUI's Sprite, or like material's color in Unity's Image, or like 'tint' property in Phaser's Sprite. In every engine using OpenGl it is finally done on GPU with cusom shader like this: CGPROGRAM #pragma vertex vert #pragma fragment frag sampler2D _MainTex; struct appdata_t { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; fixed4 color : COLOR; }; struct v2f { float4 vertex : SV_POSITION; half2 texcoord : TEXCOORD0; fixed4 color : COLOR; }; v2f o; v2f vert (appdata_t v) { o.vertex = mul( MATRIX_MVP, v.vertex ); o.texcoord = v.texcoord; o.color = v.color; return o; } fixed4 frag (v2f IN) : COLOR { return tex2D(_MainTex, IN.texcoord) * IN.color; } ENDCG You can see that vertex color ( my 'custom color' ) is multiplied with texture color. I am looking this behaviour in Babylon's Sprite2D. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.