The Daily Click ::. Forums ::. Klik Coding Help ::. Pixel shading help "image" parameter
 

Post Reply  Post Oekaki 
 

Posted By Message

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
26th April, 2016 at 26/04/2016 05:44:09 -

Okay, I've been trying to fiddle around with the shader effects editor in MMF2/CF2.5. Sketchy's article ( http://create-games.com/article.asp?id=2275 ) and examples have been a big help, but I keep running into little things that I think SHOULD work, but for reasons I can't understand, don't.

The latest is my attempt at using a second texture as a parameter. There's support for this, and as far I as I can tell, I set it up right, but it's not working.

Here's what I've got:

xml file: ( disregard the ' in the <c'ode> )
<effect>

<name>Texture Test</name>
<description>Trying to get texture loading to work</description>
<author>Me</author>

<parameter>
<name>Pattern</name>
<c'ode>pattern</c'ode>
<type>IMAGE</type>
<property>IMAGE</property>
<value></value>
</parameter>

</effect>


fx file:
sampler2D img : register(s0);

sampler2D pattern : register(s2);

float4 ps_main(in float2 texCoord : TEXCOORD0) : COLOR0 {
float4 inColor = tex2D( img, texCoord);
float4 ptrColor = tex2D( pattern, texCoord);

float4 newColor = (inColor * float4(0.0, 0.0, 0.0, 1.0))+(ptrColor * float4(1.0, 1.0, 1.0, 0.0));

return newColor;
}


technique tech_main { pass P0 { PixelShader = compile ps_2_0 ps_main(); } }



...What I WANT this to do is take the alpha channel of the original object, and display the color channels of the second texture that I'm including. But the texture is showing up as completely black, no matter what I try.

What have I got wrong?

 
Go Moon!

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49567

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
26th April, 2016 at 26/04/2016 05:56:13 -

Man I should really learn how shaders work so I can help you.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th April, 2016 at 26/04/2016 14:26:18 -

The problem is here:

sampler2D img : register(s0);
sampler2D pattern : register(s2);

The registers need to be consecutive, so you just want to change the "s2" to "s1", and it will work.


Having said that, you could simplify things a bit:


sampler2D img : register(s0);
sampler2D pattern : register(s1);

float4 ps_main(in float2 texCoord : TEXCOORD0) : COLOR0 {

float4 inColor = tex2D( img, texCoord);
float4 ptrColor = tex2D( pattern, texCoord);
return float4( ptrColor.rgb, inColor.a );

}

technique tech_main { pass P0 { PixelShader = compile ps_2_0 ps_main(); } }



You can see that it's not strictly necessary to store the return value in another variable before returning it.
Also:

return float4( ptrColor.rgb, inColor.a );

...is exactly the same as...

return float4( ptrColor.r, ptrColor.g, ptrColor.b, inColor.a );

...which is the same as your long and complicated formula.
The technical term for it is "swizzling", and it lets you do some neat tricks.
eg. "Color.rgb = Color.grb;" is an easy way to swap the red and green color channels.

 
n/a

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
27th April, 2016 at 27/04/2016 01:52:34 -

Awesome, thanks! I didn't know that the registers needed to be consecutive. And for some reason, I thought that s1 was reserved for the background, and if you weren't using it it should be skipped. I have no idea why that was.

But it works now, thanks! And that "swizzling" bit it good to know, too!


Here it is working properly. The texture that the two diamonds are using is shown in the middle there. I've got it stretched across them using some parameters for X and Y scaling.
And the second texture repeats automatically! I was hoping that'd be the case, heh.
Image

 
Go Moon!

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
27th April, 2016 at 27/04/2016 03:33:21 -

Sweet, got my end goal working:

Image

This takes the alpha channel of an object and subtracts from it the provided pattern image. It's weighed against a threshold, and ends up either visible or invisible based on that.

The test here is just a bunch of feathered circles over a sort of bumpy noise pattern.

EDIT:

Okay, I'm having fun with this thing.

Image

Edited by Fifth

 
Go Moon!

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49567

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
27th April, 2016 at 27/04/2016 16:42:59 -

That's really slick. Thing you could have it fade the opacity instead of fading to black?

 
n/a

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
2nd May, 2016 at 02/05/2016 01:23:48 -

Probably! But I actually have no idea why it's fading to black in the first place. In the first one, the circle objects are solid red. Some side effect of the additive blending + alpha-blending + the shader I'm using, I guess?

 
Go Moon!

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
2nd May, 2016 at 02/05/2016 06:47:30 -

And while I'm at it, a video game staple:

Image

Shiny water.
(This one was really easy)

 
Go Moon!

nim



Registered
  17/05/2002
Points
  7233
2nd May, 2016 at 02/05/2016 15:00:12 -

Nice work, Fifth

Maybe I'm doing something wrong (likely) but I've never been able to get shaders working on layers, only on individual objects or the entire frame. Is this normal?

 
//

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49567

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
2nd May, 2016 at 02/05/2016 16:36:48 -


Originally Posted by nim
Maybe I'm doing something wrong (likely) but I've never been able to get shaders working on layers, only on individual objects or the entire frame. Is this normal?



Same.

I actually kinda avoid shaders since I want my stuff to work on as many of the runtimes as possible.

I do kinda miss going crazy with extensions and not worrying about it though.

 
n/a

LordHannu

Crazy?

Registered
  22/04/2007
Points
  7909

VIP MemberStarTeddy BearRibbonGame of the Week Winner2021 Halloween Competition Winner2022 Hi-Score Mash-up Competition (Bronze)2023 Halloween Competition (Bronze)2023 Halloween Competition Entrant
4th May, 2016 at 04/05/2016 21:28:42 -

Hi! Is it possible to have moving water? ripples?

 
n/a

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
5th May, 2016 at 05/05/2016 02:16:47 -

Ooh man, good idea!

This is what I managed to come up with (the .gif didn't really capture all the colors):

Image

I'll try to work in some "splash" ripples, too, but I have no idea how many parameters I'm allowed to include.

 
Go Moon!

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
5th May, 2016 at 05/05/2016 03:23:28 -


Originally Posted by nim
Nice work, Fifth

Maybe I'm doing something wrong (likely) but I've never been able to get shaders working on layers, only on individual objects or the entire frame. Is this normal?



Well, I know that you can only apply shaders (even the normal ink effects) to layers if you've got a HWA-enabled build mode selected, but otherwise I can't imagine why that why that would be.

Anyway, if anybody wants to play with these, I've zipped up the ones I've made so far, along with some example files. Just let me know if anything needs clarification:

http://www.l-ames.com/logan/fifth-effects.zip

 
Go Moon!

Fifth

Quadruped

Registered
  07/05/2003
Points
  5815

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
5th May, 2016 at 05/05/2016 07:22:15 -

Aaaand experimenting with some distortion. It's kind of a hack job, though.
...Maybe I should wait until I finish these things before I share them?

Image

 
Go Moon!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
5th May, 2016 at 05/05/2016 15:11:25 -

Nice job! Those ripples look great
I think you probably want to make it so the amplitude of the waves increases with the Y coordinate.

eg.
Image

 
n/a

Pan-tosser



Registered
  24/10/2008
Points
  520

Has Donated, Thank You!
5th May, 2016 at 05/05/2016 15:53:50 -

Would waves like this be only for the foreground. Or could it be used in the background and look nice with scrolling and everything else.

 
https://www.facebook.com/nathon.brown.7

LordHannu

Crazy?

Registered
  22/04/2007
Points
  7909

VIP MemberStarTeddy BearRibbonGame of the Week Winner2021 Halloween Competition Winner2022 Hi-Score Mash-up Competition (Bronze)2023 Halloween Competition (Bronze)2023 Halloween Competition Entrant
6th May, 2016 at 06/05/2016 21:16:54 -

Nice work lootks amazing
When i was thinking ripples i thought off castelvania X when the background is on fire.
28 seconds in. https://youtu.be/sKVdTmD-tsc?t=28
Wish i knew how todo that.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click