Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, VoroneTZ, Quad), 901 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Copy part of a bitmap #444355
08/07/14 10:14
08/07/14 10:14
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
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?

Re: Copy part of a bitmap [Re: jenGs] #444378
08/08/14 00:11
08/08/14 00:11
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
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?

Last edited by jenGs; 08/08/14 03:25. Reason: bmap_process crap
Re: Copy part of a bitmap [Re: jenGs] #444381
08/08/14 04:43
08/08/14 04:43
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline OP
Member
jenGs  Offline OP
Member
J

Joined: Jul 2010
Posts: 283
Germany
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.


Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1