Copy part of a bitmap

Posted By: jenGs

Copy part of a bitmap - 08/07/14 10:14

I need a simple postprocessing shader to copy a part of a bitmap. Note: The values in my example are all hardcoded for testing.

Code:
float inrange(in float2 values)
{
	return values[0] > 0.0 && values[1] > 0.0 && values[0] < 1.0 && values[1] < 1.0;
}

float4 process_blit(in float2 vPos: VPOS): COLOR 
{	
	float2 tex = (vPos.xy + 0.5) / vecViewPort.xy;
	float2 ras = (vPos.xy + 0.5); 

	float4 color = 1;
	
	float fx = smoothstep(0.0, 19.0, ras.x);
	float fy = smoothstep(0.0, 22.0, ras.y);
	
	float px = fx * (19.0 / 608.0); // 608 is the width of the source bitmap
	float py = fy * (22.0 / 88.0); // 88 is the height of the source bitmap
	
	color = tex2D(smpSrc, float2(px, py)) *  inrange(float2(fx, fy));
	
	return color;
}



OK, this doesn't work right. The area copied is always too big. I don't get the problem.
Smoothstep should output 0.0 to 1.0 if ras is in the area the source should be copied to.
And so far it does that. it gives a perfect gradient at this position when multiplied with the color.
19.0 / 608.0 should give me the size of part of the source bitmap I want to copy (without offset for now) in 0.0 - 1.0 range.
fx * (...) should increase the area from 0 to the maximum.
Where is the error?
Posted By: jenGs

Re: Copy part of a bitmap - 08/08/14 00:11

Hrmpf,

I debugged all values into a floatingpoint bitmap and accessed the data through bmap.finalbits.
So, now I know that VPOS has no offset.
I debuged every other value, too.
TEXCOORD0 starts with an half pixel offset.

So the thing I do not understand is this.

I have two bitmaps of exactly the same size.
For testing purposes I sampled the second bitmap through tex2D('sampler', 'TEXCOORD0').

Code:
Texture mtlSkin1;

sampler2D smpSrc = sampler_state 
{ 
	texture = <mtlSkin1>;
	MipFilter = NONE;
	MinFilter = NONE;
	MagFilter = NONE;
};

float4 process_debug(in float2 tex: TEXCOORD0): COLOR 
{	
	float4 color = 1;
	
	color = tex2D(smpSrc, tex);
	
	return color;
}



I thought if you want to sample a texture your texture range is always 0.0 - 1.0.
But the output showed me much smaller copy of the original. And it is not even the half of the original.
I can't get, how the ratio between the two bitmaps is calculated.
In my example it is x(1.0 to 0.6) and y(1.0 to ca. 0.7).
Ok, if the bitmaps are not the same size I could imagine that this has to do something with a size ratio between the two bitmaps. But this things have the same size. So the size ratio is 1.0.
Do I have to do something special declaring the sampler?
Posted By: jenGs

Re: Copy part of a bitmap - 08/08/14 04:43

Why ... whhhyyy???

Ok, in the example above I used bmap_process(bitmap1, NULL, mtl)

This somehow fucked the adressing of every other texture up.
For example tex2D(smp, float2(0.56, 0.7)) adressed the last pixel of the bitmap.
Keep in mind, that the externaly used bitmap (through mtlskin1) had the same size.

So now I did that
bmap_process(bitmap1, bitmapSource, mtl)
Again the bitmaps had the same size. AND NOW it works.

I know that the manual states that you have to multiply the adressing of the sourcebitmap with the size ratio.
But this should exclude the adressing of other bitmaps. Especially if they have the SAME SIZE.
© 2024 lite-C Forums