2 registered members (AndrewAMD, VoroneTZ),
831
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Adding effects to 2D panels
#479722
04/20/20 14:32
04/20/20 14:32
|
Joined: Feb 2013
Posts: 122 Maysville, Ga
Evo
OP
Member
|
OP
Member
Joined: Feb 2013
Posts: 122
Maysville, Ga
|
I'm currently working on an (open-source) lightweight 2D game development library. Basically it's a lite-c plugin full of command methods that will have all the features needed to quickly and easily create 2D games. So far everything is going very well and it currently includes : Topdown Gameplay, Platformer Gameplay, New 2D collision system, 2D Simulated Camera System, Parallax background/Foreground system, and many other easy to use 2d features.
I'm now creating various other features and there are some things I would like to add but am unsure how to actually code.
I need to know if there's a way to add special effects to panel/bmaps. * Is there a way to apply a shader to a pure 2d object. (Panels/Bmaps) (No 3D Level) (No 2D View Entities) * If I wanted a panel to have a waving effect (Such as being underwater or other similar ideas), how would I code/apply those things to actually affect the panel/bmap? * Does anyone have a working 2d shader or working code effect that alters/affects a 2d panel/bmap?
Last edited by Evo; 04/21/20 15:16.
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479724
04/20/20 14:47
04/20/20 14:47
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey! Long time ago, txesmi helped me out with adding postprocessing shader over panels, maybe it will be useful: Postprocessing over panelsBest regards!
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479736
04/21/20 14:15
04/21/20 14:15
|
Joined: Feb 2013
Posts: 122 Maysville, Ga
Evo
OP
Member
|
OP
Member
Joined: Feb 2013
Posts: 122
Maysville, Ga
|
I just can't seem to get that code to work the way I need it to. I think I need an actual 2d shader for testing it.
2D MATERIAL EFFECT (Need a real 2d shader) It needs to be applied and to add the material effect to the panels bmap/window of the panel that's targeted. (Something that actually affects the panels image automatically once applied.
It would be greatly appreciated If anyone with knowledge of this can create a basic working example.
If I use : bmap_process ( sprite_A, player_pan.target_map, mtlEffect ); How do I target a panels (bmap/window sprite) and apply the effect directly to the image? How can I get the view materials to work with this method?
Last edited by Evo; 04/21/20 18:29.
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479740
04/21/20 19:16
04/21/20 19:16
|
Joined: Feb 2013
Posts: 122 Maysville, Ga
Evo
OP
Member
|
OP
Member
Joined: Feb 2013
Posts: 122
Maysville, Ga
|
I seem to have gotten it to work in a different way. Basically all I have to do to target a defined BMAP and apply a view shader is :
bmap_process ( sprite_A, sprite_A, mtl_emboss );
It applies the material effect to the BMAP. Changes apply to any panels using the BMAP.
Q. What material code do I use to make the sprites transparent? When applied to a window sprite, it colors the transparent pixels.
(Note : Not all view material work since they don't seem to be set up for this purpose. Only certain materials like "Negative" seem to work, but transparency is not correct.)
Last edited by Evo; 04/21/20 20:44.
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479741
04/21/20 21:38
04/21/20 21:38
|
Joined: Oct 2008
Posts: 679 Germany
Ayumi
User
|
User
Joined: Oct 2008
Posts: 679
Germany
|
maybe you should write your own small Shader because of controlling. Example: Set alpha to View-Bitmap (clear the bitmap)
Texture TargetMap;
sampler2D SrcColor = sampler_state
{
texture = <TargetMap>;
MinFilter = linear;
MagFilter = linear;
MipFilter = linear;
AddressU = Clamp;
AddressV = Clamp;
};
float4 FillAlpha( float2 texCoord : TEXCOORD0 ) : COLOR0
{
float4 color;
color = tex2D(SrcColor, texCoord);
color.a = 0;
color.rgb = 1;
return color;
}
technique PostProcess
{
pass p1
{
AlphaBlendEnable = false;
VertexShader = null;
PixelShader = compile ps_1_0 FillAlpha();
}
}
MATERIAL* MatObjFillAlpha =
{
effect ="FillAlpha.fx";
}
View.bmap = bmap_for_entity(my, 1);
bmap_process (View.bmap, NULL, MatObjFillAlpha);
And your bmap_process is wrong, set NULL to Source. If you want to set Alpha Channel to Emboss, set AlphablendEnable to true and set Color.a
Texture TargetMap;
sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear; };
float4 vecViewPort;
float4 postprocessing_emboss( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color = float4(0.5,0.5,0.5,1.0);
Color -= tex2D( g_samSrcColor, Tex.xy-vecViewPort.zw)*2.0f;
Color += tex2D( g_samSrcColor, Tex.xy+vecViewPort.zw)*2.0f;
Color.rgb = (Color.r+Color.g+Color.b)/3.0f;
Color.a = 0.2;
return Color;
}
technique PostProcess
{
pass p1
{
AlphaBlendEnable = true;
VertexShader = null;
PixelShader = compile ps_2_0 postprocessing_emboss();
}
}
Last edited by Ayumi; 04/21/20 21:49.
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479747
04/22/20 10:43
04/22/20 10:43
|
Joined: Jul 2007
Posts: 619 Turkey, Izmir
Emre
User
|
User
Joined: Jul 2007
Posts: 619
Turkey, Izmir
|
(Note : Not all view material work since they don't seem to be set up for this purpose. Only certain materials like "Negative" seem to work, but transparency is not correct.) In that effect (Negative), transparency is indicated by number. That's the problem. float4 postprocessing_negative( float2 Tex : TEXCOORD0 ) : COLOR0
{
//you have the color of the texture but not the alpha!
float3 Color = 1. - tex2D( g_samSrcColor, Tex.xy).xyz;
//you set the alpha by number (1) that means your texture doesn't have transparent parts.
return float4(Color,1.);
}
If you change it like this, the problem will disappear: float4 postprocessing_negative( float2 Tex : TEXCOORD0 ) : COLOR0
{
//you have the color and alpha of the texture.
float4 Color = tex2D( g_samSrcColor, Tex.xy);
//now you change colors, but not touch the alpha.
Color.xyz=1. - tex2D( g_samSrcColor, Tex.xy).xyz;
return Color;
} Color.xyz means rgb and Color.a means alpha. So if you specify the alpha in numbers float4(Color.xyz,1), it won't affect texture. First, you should get rgb and alpha with float4. Then you can change it as you wish. I would like to help more, but i'm not familiar of bmap_process.
|
|
|
Re: Adding effects to 2D panels
[Re: Evo]
#479749
04/22/20 13:19
04/22/20 13:19
|
Joined: Feb 2013
Posts: 122 Maysville, Ga
Evo
OP
Member
|
OP
Member
Joined: Feb 2013
Posts: 122
Maysville, Ga
|
My evo2d method library will now have a custom 2D FX system for material effects.
So far it's only standard material effects that alter the color. But now I need a final test of a shader that alters shape or some other cool effect.
If anyone can create a basic effect to alter the shape (such as a wave effect that changes the bmap), that would verify if a real effect works or not. Sorry to ask for help in creating it, but I know little about shader code at this time.
Thanks for everyone's help so far. I appreciate your time and effort.
Last edited by Evo; 04/22/20 14:59.
|
|
|
|