Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Problem with TargetMap #467297
07/25/17 09:27
07/25/17 09:27
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hey there,

I played around with a little shockwave shader that I found recently here in the board and modified it to my needs.
In my testlevel everything works fine, but when I use the same shader in my project it just displays a white plane.

Here's what the code does:

- create a sprite with a normal map on skin1
- use a view (camera.stage) to project to rendered pic onto the sprite surface (TargetMap)
- the shader uses the normal map to do some bump mapping on the rendered pic

This works fine in my testlevel, but once built into my project the sprite just gets white.

When I replace the use of the TargetMap inside the shader by the bumpTexture I see the texture on skin1 bump mapped as expected. So it seems that there is a problem with the TargetMap.

Even if I just use a very simple pixel shader like:

float4 ps_test(float2 tex : TEXCOORD0) : COLOR {
float4 Color = tex2D(targetmap, tex);
return Color;
}

I just get this white plane.

I tried to extract as much of the project code as I can to find out where's the difference between my testlevel (that uses the same models and textures as in my project), but I wasn't successful yet.

Any hints where to search or what might be the problem with the TargetMap?

Best regards,
Sascha

Last edited by pegamode; 07/25/17 10:03.
Re: Problem with TargetMap [Re: pegamode] #467306
07/25/17 18:32
07/25/17 18:32
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Ok, I just figured out that when I save the rendered view in a bmap like that:

camera_scene = bmap_createblack(screen_size.x, screen_size.y, 24);
camera.bmap = camera_scene;

And then use "camera_scene_bmap" within the shader instead of "TargetMap" everything works fine.

But shouldn't be TargetMap set automatically?

I only add this single stage to the camera. I really can't figure out what's wrong here.

Any ideas?

Sascha.

Re: Problem with TargetMap [Re: pegamode] #467313
07/26/17 06:56
07/26/17 06:56
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
Tex2D uses sampler2D and texture coordinates as parameters. It looks like you are using the TargetMap texture directly. But that's hard to say with this short code snippet. Better post your full code.

Re: Problem with TargetMap [Re: Ezzett] #467316
07/26/17 07:15
07/26/17 07:15
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Here's the shader code that works fine in my testlevel, but not inside the whole project:

Code:
texture mtlSkin1;
texture TargetMap;

float4 vecSkill41;
float3 vecViewPort;
float4x4 matWorldViewProj;

sampler targetmap = sampler_state
{
	texture = (TargetMap);
	MinFilter = linear;
	MagFilter = linear;
	MipFilter = linear;
	AddressU = Wrap;
	AddressV = Wrap;
};

sampler bumpTex = sampler_state
{
	texture = (mtlSkin1);
	MinFilter = linear; 
	MagFilter = linear; 
	MipFilter = linear; 
	AddressU = Clamp;
	AddressV = Clamp;
};

struct VS_INPUT
{
	float4 Position	: POSITION;
	float2 tex0 : TEXCOORD0;
	
};
struct VS_OUTPUT
{
	float4 PosWorld	: POSITION; 
	float2 tex0	: TEXCOORD0; 
	
};

VS_OUTPUT vs_main( VS_INPUT In ) 
{
	VS_OUTPUT Out;

	float4 Position = mul(In.Position, matWorldViewProj);
	Out.PosWorld = Position;
	Out.tex0 = In.tex0.xy;

	return Out;
}

float4 ps_main( VS_OUTPUT In,in float4 vScreenPos : VPOS) : COLOR
{
	float2 TexcoordScreen = ( vScreenPos.xy + 0.5) / (vecViewPort.xy);
	float2 pixel = ((tex2D(bumpTex, In.tex0).rg) -0.5-(1/254))*( 0.001 * vecSkill41.x  );
	float4 pixel2 = tex2D(targetmap,((TexcoordScreen.xy) + (pixel.xy ) ));		
	return pixel2;
}

technique tech_00
{
	pass pass_00
	{
		vertexshader = compile vs_3_0 vs_main();
		pixelshader = compile ps_3_0 ps_main();		
	}
}
technique fallback { pass one { } }



Lite-C:

Code:
VIEW* vShockwave = 
{ 	
	flags = PROCESS_TARGET|CHILD;
}

MATERIAL* shockwave_mat =
{	
	skin1 = shockwave_bmap;
	effect = "shockwave.fx";
}



The material is just set to a sprite and skin1 is a simple normal map texture.

Re: Problem with TargetMap [Re: pegamode] #467317
07/26/17 08:25
07/26/17 08:25
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
This looks fine to me, except vecViewPort is a float4 and I would write texture = <textureName> instead of texture = (textureName). But I don't know if one of these things is even relevant because it works in your test level. Maybe your normalmap got corrupted? What happens if you replace mtlSkin1 with shockwave_bmap_bmap or use another bitmap file?

Re: Problem with TargetMap [Re: Ezzett] #467318
07/26/17 09:09
07/26/17 09:09
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
The normalmap looks ok. I also tried different ones. But as far as I can see the TargetMap isn't set correctly by the engine.

I thought that it should be enough to set "camera.stage" to force the engine to set render_target??? "render_target" is just a global pointer to a BMAP, isn't it?

Re: Problem with TargetMap [Re: pegamode] #467322
07/26/17 09:46
07/26/17 09:46
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
Yes, you set the stage and if the following view doesn't have the PROCESS_SCREEN flag set then everything should be working.

I just saw that your view vShockwave hasn't a material assigned.

Re: Problem with TargetMap [Re: Ezzett] #467323
07/26/17 10:08
07/26/17 10:08
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
The material is assigned to the sprite not to the view.

I uploaded my working testlevel here ... maybe that's easier to follow how the shader is used (though the testlevel is working):

http://www.meteormess.de/files/shockwave_test.rar

I also couldn't figure out why some of the models get invisible when they are behind the sprite with the shader (also in the testlevel) ...

Re: Problem with TargetMap [Re: pegamode] #467331
07/26/17 15:47
07/26/17 15:47
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
Your shockwave_alpha.png is broken. It even crashed one of my image editing tools. I made simply a new one in Gimp with an alpha channel and replaced the one in your test level. The models aren't disappearing anymore. It seems that Gamestudio uses the broken PNG as if it were nontransparent so every model behind it gets culled away by the renderer.

Do you use several views with stages inside your project? Maybe the pointer to the render target is set to the wrong TargetMap when when your shader is being processed?

Re: Problem with TargetMap [Re: Ezzett] #467332
07/26/17 15:54
07/26/17 15:54
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Oh wow. The alpha.png is the only one I never replaced while debugging. That's great to know ... one big problem less. Thank you very much for helping.

I don't use other views and there is only this one stage. But maybe the corrupted png is also responsible for the strange behaviour in my prohect. I will check it out once back home this evening.

Thanks again.

Sascha

Re: Problem with TargetMap [Re: pegamode] #467334
07/26/17 17:40
07/26/17 17:40
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Ok ... I replaced the shockwave_alpha.png and now the models are not disappearing any more. Really great ... thanks again.

Unfortunately it's not fixing the TargetMap issue. I hope it's not a bug in my project that overwrites the render_target pointer in some way.
But then again the render_target should be updated with every frame, shouldn't it. So I guess it would lead into an engine crash if something would write into its address.

Re: Problem with TargetMap [Re: pegamode] #467335
07/26/17 19:56
07/26/17 19:56
Joined: Aug 2003
Posts: 118
Deutschland
E
Ezzett Offline
Member
Ezzett  Offline
Member
E

Joined: Aug 2003
Posts: 118
Deutschland
The render target pointer should change for every view that renders into a render target. Maybe you are using some other shaders with multiple view stages that use render targets like shadow mapping.

Your problem is that your material doesn't belong to the second stage after the camera view. There is no sequential order. When your material is processed, the render target pointer could point to another/changed render target of another view that was calculated in the meantime.

I think you already did the right thing by rendering into a seperate bitmap and using this bitmap in your shader instead of TargetMap.

You can also draw the render_target bitmap onto the screen with help of the Debug_Bmap macro. Maybe do this and remove other views and shaders and check if its rendered content is correct.

Re: Problem with TargetMap [Re: Ezzett] #467337
07/26/17 21:11
07/26/17 21:11
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Actually there's no other view, but I will give Debug_Bmap a try tommorow.
I'm really happy that everything is working now inside my project ... though I would still like to know why I can't use the render_target bitmap.

Maybe Ezzett is right that the reason is that the material is not assigned to the view.

Page 1 of 2 1 2

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