Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to apply Alpha Masks that move around and affect only specific objects (no fullscreen masks)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Icebone1000   Members   -  Reputation: 1087

Like
0Likes
Like

Posted 19 August 2014 - 08:19 PM

Imagine a tiled 2D game where your character goes behind a wall (found a secret spot). Say I want to apply an alpha mask (a circle with faded borders) in the same position the player is, but only for the tiles/sprites hiding the secret spot, not for surrounding environment tiles (where the mask will overlap (due its big size) but not affect, cause theres notting behind then, its a solid wall)

lFgxXkS.png

check how the mask affects only specific tiles

 

Whats the best way to accomplish that?

 

#1# With stencil buffer Id need to render in lots of passes. (I suppose, I dont remember have ever used the stencil buffer before)

Render unaffected tiles + player;

Render the mask in the player position to the stencil buffer;

Render the tiles hiding the secret spot;

 

#2# With specific pixel shader:

Render unaffected tiles + player;

Render the tiles hiding the secret spot w/ a specific pixel shader, that also takes the mask and its screen position.

 

Which method is better?

The pixel shader method sounds better to me, but I dont know how/if it would work.

Id need to check if it overlap with the mask (comparing SV_Position witht the given mask screen position constant), and compute the equivalent uv on the mask..?

 

Computing the equivalent mask uv would be something like

mask uv: (mask_pos - SV_Position) / mask resolution?

What if the current pixel does not overlap (generating negative uvs, or greater than 1)? (if the mask is constrained to have black on the borders than clamping the computed uv to [0,1] would work I guess?)

 

Would #1 or #2 work?

Any better way of doing this?


Edited by Icebone1000, 19 August 2014 - 08:40 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13600

Like
1Likes
Like

Posted 19 August 2014 - 08:32 PM

#1 will not give you a smooth fall-off.
 
Using #2 is very simple.  The only extra input is the screen-space point from which the alpha should be increasing from 0 (closer to the [X,Y] a pixel is the lower the alpha modifier).
 

float fAlphaModifier = sin( saturate( length( SV_Position - vTargetPos ) / 256.0f /* Size if the fade area. */ ) * 1.570796 );

 
The final color’s standard w (the same w you would have otherwise) is multiplied by fAlphaModifier on output.

 

 

L. Spiro


Edited by L. Spiro, 19 August 2014 - 08:35 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS