Forum

Increase alpha value according to white mask ? in hlsl way

hello all.
I would like to increase alpha value at every white point of my mask.

here’s my code:

float4 PS(vs2ps In): COLOR
{
    float4 col1 = tex2D(Samp1, In.TexCd);


	if (all(col1)==1) {
		curseur=curseur+0.1;
	col.rgba=float4(1,0,0,curseur);}
	
	return col; 
}

my issue is that curseur value doesn’t increase at all… it stays at 0.1…

how can I do to increase it at every pixel where col1 is white ?

thanks in advance,
I hope I’m clear.

Bt the way, would you have any good docs about directx shading, hlsl ?
tiouss

Is there a particular reason why you assign the new curseur to col.rgba into the if?

Shouldn’t

col.rgba=float4(1,0,0,curseur);

be outside the if?

Also all(x) returns true if ALL components of x are non-zero… so even with x = (0.1,0.1,0.1) it would return true, and this is not what you’re looking for, I think.
To check if x is (1.0,1.0,1.0) you should iterate through all components of x.

I don’t know a better snippet than

if(x.r == 1.0 && x.g == 1.0 && x.b == 1.0){
    curseur...
  }
  col.rgba = ...

There is for sure something better than this.

thanks h99 !
but nothing occurs still… even with your code…
this is the clean code:

float4 PS(vs2ps In): COLOR
{
    float4 col1 = tex2D(Samp1, In.TexCd);


	if (col1.r == 1.0 && col1.g == 1.0 && col1.b == 1.0) {
		curseur+=0.1;
		}
	col=float4(1,0,0,curseur);
	
	return col; 
}

curseur never raises up
it seems to stay at 0.1…
I’m still searching…
thanks !

A patch + .fx would give others a chance to help you.
A stupid thought: is curseur = 0.0 when declared? Are you using “correct” texture format?

here’s patch and fx.
curseur is correctly declared I guess…
I don’t really know if texture’s type is correct…
thanks !

analyse_pixel.v4p (14.9 kB)
curseur_blend.fx (2.8 kB)

Well, there’s no time value in your patch, nor something that would raise curseur value through time. There’s no trigger event to increase curseur (nor to stop increasing it).
It is not enough rising curseur one time in the if; I’d add a pin

float curseurIncrease;
... // and then change
    curseur+= curseurIncrease;

and link a node that goes 0 to 1 in a specified amount of time with the use of some more logic, or patch your way to this without a shader.
I honestly never thought about something like this, so I have not fresh ideas; if you browse through EX9.Texture category you should find some fitting examples.

increment parameter according to time value is for me “every time the mask is white at pixel at xy location, the alpha curseur parameter is increased at this pixel position”.
so it has to be done into the fx file I guess…

M2C… that ain’t gonna happen that way.
In other words, once you “create” another sphere, the corresponding pixels become white, this texture is passed to the .fx, the .fx reads the white pixels and update its own texture once, since the input texture ain’t changing the already white pixels.

In order to increase x.a you should be working with white objects with an alpha, for example.

In my attached example, every frame a new sphere is created/overlaps an old one, so you get an update in the texture, leading to more solid white/red out of the .fx.
You do get then the time/number of frames needed to go from black to white into source texture = 1 / sourceAlphaValue since every frame a new sphere with specified alpha color (in my example 0.002) is added. A bit more math goes to get the time in output texture - it will be faster, since every frame adds up the new source white.

But you can easily see how the .fx is almost useless. That said, this is a way, not the way.

EDIT:
Actually that’s an almost nice effect the one in the destination renderer. I’m gonna treat myself, later.
EDIT2:
Too good to be true, indeed; the path to the .fx is wrong, you should drag and drop it. No treats, I knew it.

forjulius.zip (3.5 kB)

Thanks h99.
but my final purpose is to compose a picture from 10 different images.
when the white mask is at xy position, the cursor is increased. at this position, if cursor is between 0 and 0.1? image 1 is displayed, if cursor is between 0.1 and 0.2 image 2 is displayed…

so i guess i have to deal with time value, I mean duration of the white mask which increases the cursor at this location…
little bit tricky ? I hope I’m clear…
thanks anyway, but I’m little bit confused and lost about this issue…

shaders cannot store values and access them in the next frame, this is only possible with texture feedback (then the value needs to be stored in the texture) or compute shaders.

also in the shader you are sampling col1, but you are not using it to do the comparison. i think you mixed that up with col.

anyway, the shader could look like this:

float CurseurOffset = 0.05;
float4 PS(vs2ps In): COLOR
{
	//just the red channel channel from R32F texure in the texture 
    float curseur = tex2D(SampCurseur, In.TexCd).r;
	float4 mask = tex2D(SampMask, In.TexCd);

	if (all(mask.rgb >= 1))
	{
		curseur += CurseurOffset;
	}
	
    //clamp curseur value to 0..1 
	curseur = saturate(curseur);
	
	//just write curseur value into red channel of the output
	return float4(curseur, 0, 0, 1); 
}

and work with a texture feedback, see patch:

cur.zip (8.2 kB)

thanks tonfilm !
would it be possible to create a texture which goes from black to white at the position where my white mask is still at the same position during 10 sec for instance… then I can analyse this color texture to draw the final one…
the question is how to deal with time in shaders…?
thanks !

shaders do not know time, but if you think about it, its just a matter of how much you increase the value per frame. so Timing -> FrameDifference -> / should do the trick.
then you calculate the CurseurOffset you put int to the shader in your patch like that:

CurseurOffset = FrameDurationTime / TimeToWhite;

thanks tonfilm… but I’m not sure to understand well what you mean…

maybe I’m completely wrong…

fx is maybe not the answer…

just want a “brush”,like photoshop tool, which reveals 9 layers (like psd) everywhere it goes…
I have to say I’m pretty lost about that…

Hi julius_berlin, maybe you are looking for something like this:


kind of volumetric paint?

@rogalag
really nice approach !
this seems to be be a little bit tricky ?
this is maybe a way to explore
thanks

@Julius, there is a nice vvvv contribution: Slitscan & Ringbuffer (DX11), which can produce similar results…

i think you just have to calculate the correct CurseurOffset in the patch and pass it to the shader and then use the texture as a mask for your 10 layers… that’s all.

lower values for CurseurOffset will take longer to fade to white and higher values shorter. if you want to be precise use the formuala from my post above.