Jump to content
  • Advertisement
Sign in to follow this  

Question about applying multiple decals in 2D via shader

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a 2d topdown game (C#, 2d slimdx-based lib Gorgon), and I'm trying to get a way to apply decals to individual sprites when they are drawn. I'd like to be able to apply more than one decal per sprite. The decal sprites are all in a single texture atlas. The base sprites may or may not be in an atlas.

I've attached the shader I'm currently using.

Right now, I've got it working so that I can apply a decal to a sprite in a little test app by feeding in some coordinates and a constant to transform texcoord sizes and display only the relevant part of the sprite.

The problem is that it seems I can only set the parameters once from within the application, causing the same decal to be applied in the same place every time I draw a sprite in the frame.

How do I specify a parameter that I can change for every sprite I draw in a single frame? I was looking at how to do uniform top level shader parameters, but I just wasn't able to make complete sense of it.

Also, what would be the most efficient way to feed in an array of parameters so that I can draw multiple decals per execution of the shader?

Here's the C# code I'm using to generate and set the parameters:

public void Draw()
Gorgon.CurrentShader = decalShader.Techniques["drawWithDecal"];


private Vector4D decalParms1(Vector2D decalBToffset, Vector2D baseTexAtlasSize, Vector2D decalSize)
float BTXDTL_x = decalBToffset.X / baseTexAtlasSize.X;
float BTXDTL_y = decalBToffset.Y / baseTexAtlasSize.Y;
float BTXDBR_x = (decalBToffset.X + decalSize.X) / baseTexAtlasSize.X;
float BTXDBR_y = (decalBToffset.Y + decalSize.Y) / baseTexAtlasSize.Y;
return new Vector4D(BTXDTL_x, BTXDTL_y, BTXDBR_x, BTXDBR_y);

private Vector4D decalParms2(Vector2D decalAtlasSize, Vector2D baseTexAtlasSize, Vector2D decalAtlasOffset)
float CFx = (float)decalAtlasSize.X / (float)baseTexAtlasSize.X;
float CFy = (float)decalAtlasSize.Y / (float)baseTexAtlasSize.Y;
float DOtc_xtl = (float)decalAtlasOffset.X / (float)decalAtlasSize.X;
float DOtc_ytl = (float)decalAtlasOffset.Y / (float)decalAtlasSize.Y;
return new Vector4D(CFx, CFy, DOtc_xtl, DOtc_ytl);

Any help rendered is much appreciated!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!