Sign in to follow this  
krzysztof.s

Is there any possibility to set custom color in Sprite2D ?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.