Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Iso 2D engine using CG Shaders [video]

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Iso 2D engine using CG Shaders [video]
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dario ff
Member #10,065
August 2008
avatar

Yup, it seems again, my code never builds on an ATI GPU! :D

I'll be able to debug this later more properly with a friend, so don't worry. It'll work, it's just that there are always some quirks I forget.

EDIT: Yeah, I did the same stupid mistake I did once of mixing up ints and floats. NVidia GPUs are more forgiving in that, and it's been nearly an year from using these that I forgot, sorry. Wait for take #2. :P

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

AMCerasoli
Member #11,955
May 2010
avatar

Dario ff said:

Yup, it seems again, my code never builds on an ATI GPU!

I'll be able to debug this later more properly with a friend, so don't worry. It'll work, it's just that there are always some quirks I forget.

Yes yes yes... I want my money back.

Dario ff
Member #10,065
August 2008
avatar

Try out these two shaders if you want. They're pretty horrible at the moment regarding optimizations obviously, but I didn't really expect to even put something like it online. :P

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

kenmasters1976
Member #8,794
July 2007

Wow! this looks really impressive!. I thought it was 3D until that part where you say it's 2D. Actually, I could've bet that it's 3D.

Nice work!.

GullRaDriel
Member #3,861
September 2003
avatar

Does not work there.
Symptoms are the same as Edgar, 30 second black, and a grey background after.

And the good news is that it's running at my display refresh rates ;-)

"Technique lighting did not validate. Skipping."

Edit: BTW I have a Radeon 5470 and MediaPlayerClassic let me play with it's shaders without problems. I use the latests drivers, 10.12, on W7 64.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Vanneto
Member #8,643
May 2007

Works here: nvidia geforce 8600GT.

EDIT: Forgot to say: awesome. :D

In capitalist America bank robs you.

Dario ff
Member #10,065
August 2008
avatar

Does not work there.
Symptoms are the same as Edgar, 30 second black, and a grey background after.

Did you try the shaders I attached in the last post? Those fixed the problem I had with seeing just a white texture in an integrated 6100GT. Of course, it works incredibly slow, because it's a very crappy card. :P

Of course, it could be that it's still not compiling on ATI, but I can debug that one more in detail later.

I thought it was 3D until that part where you say it's 2D. Actually, I could've bet that it's 3D.

If I rendered much more awesome models(and textured) it would've been more obvious. :) I think the tiles are a pretty good example, those look great since they're textured.

Vanneto said:

Works here: nvidia geforce 8600GT.

Cool, that's my old card.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dario ff
Member #10,065
August 2008
avatar

The shadow shader seems to be compiling correctly, it's the lighting the one with the problem.

Well, I wouldn't know how to debug it without a card for sure. :P All I can say is if you want, start commenting parts, except these lines:

struct PS_OUTPUT
{
    float4 color : COLOR0;
    float depth : DEPTH;
};

PS_OUTPUT ps_main(float2 normalMapTexCoord : TEXCOORD0)
{

    PS_OUTPUT Out;
    float4 color;

color = tex2D(texture, normalMapTexCoord);
Out.color = color;

return Out;

technique lighting {
  pass {
    FragmentProgram = compile glslf ps_main();
    VertexProgram = NULL;
  }
}

So yeah, you can comment pretty much everything inside ps_main(). If you see something visible, then you can try adding more and more lines until it screws up. That would help, if you're willing to do that.

EDIT: Oh, and don't comment the global variables that are above ps_main. Otherwise, the program will fail when setting them.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Neil Walker
Member #210
April 2000
avatar

Dario ff said:

float4 color : COLOR0;
float depth : DEPTH;
PS_OUTPUT ps_main(float2 normalMapTexCoord : TEXCOORD0)

The colons are baffling me? There are many voids in my C/C++ knowledge but all of them I thought I knew what I didn't know. But not these.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Dario ff
Member #10,065
August 2008
avatar

That's CG, not C++. :P Unless I misunderstood what you said.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Neil Walker
Member #210
April 2000
avatar

Well, that shows I should read the whole thread instead of random bits and why I didn't follow the syntax. I guess if I read all the code and saw the lighting bit at the end I might have realised something was up.

Still, glad to see there's nothing I don't know about C/C++ that I didn't already know I didn't know :)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Jones64
Member #10,718
February 2009

I tested it just now, it's pretty impressive :)
I haven't seen much of this way of 2D rendering before. Do you have any plans of making a full engine or a game with this? Would be interesting :p

Performance seems fine, but one thing I noticed is that the application uses about 236MB of video memory. Will this increase a lot if you build this into a full game?

Works smooth with a GeForce 8800GT in Win7-64.

Dario ff
Member #10,065
August 2008
avatar

Jones64 said:

Performance seems fine, but one thing I noticed is that the application uses about 236MB of video memory.

Well, the images I included had some useless empty spaces, and were very high-res, so it's expected. I could map the height map into the normal's alpha channel to reduce it 1/3 ;). And the shadow map is unnecesarily big as well, and I'll try to optimize it so it gets cropped as well. That should reduce the usage to a bit more than 1 half probably.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Mark Oates
Member #1,146
March 2001
avatar

Vanneto said:

Works here: nvidia geforce 8600GT.

That's the card I have!

Dario ff said:

Cool, that's my old card.

It's my new card. :-/

Then again, I did buy it like 2 years ago. That's "new" to me, since I'm old now.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Chris Katko
Member #1,881
January 2002
avatar

That's the card I have!

That's the same card my friend has. :o He's looking into a 460 for an upgrade. (Only $160)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Dario ff said:

So yeah, you can comment pretty much everything inside ps_main(). If you see something visible, then you can try adding more and more lines until it screws up. That would help, if you're willing to do that.

Speaking of the second object_light.cgfx :

First, I went back to using
FragmentProgram = compile latest ps_main();

Then if I comment out lines 79-234 (everything), then I get to see the assorted isometric diamond floors, the mansion, the guy in armor, and the column. I tried to take a screen shot, but it captures the desktop underneath for some reason.

If I comment out line 219
// Out.color = color;
and line 233
// Out.depth = 1.0-depth;
which effectively returns the color retrieved from the Tex2D call at the beginning, then I get a gray screen, which makes no sense, since it is returning the same PS_OUTPUT as it was when I commented everything out.

If I comment out lines 113-158 (the while (i<32) { block), then I get a gray screen again, so I don't think there's anything wrong with that chunk of code.

If I comment out lines 161-203 (the if (directional_strength > 0) { block, then I still get a gray screen.

If I comment out lines 113-203 (both of the previous blocks of code) then I get a gray screen with all the objects in black, which makes sense since final_light is initialized to 0.0.

What values of final_light would make every color turn grey(transparent?)?

I don't really know how I could isolate the problem anymore.

Something else that doesn't make sense is why it works for some people, but not for others. All ps_main is doing is returning a color, and that should be the same for everyone.

Dario ff
Member #10,065
August 2008
avatar

Interesting. Could you do another test? Try these and replace object_light by renaming each of these.

Version _a will just pass the color and output with no depth whatsoever. So you'll likely see an isometric floor.

Version _b will pass both color and depth, but no lighting whatsoever.

Version _c will pass the directional light, but it won't cast any shadows.

Version _d will pass the directional light and cast shadows.

I've removed the parts for iluminating with dynamic lights. The full version would be the one you already have. If one of the versions doesn't work, then we've narrowed down the culprit. The reason it's grey is that it's most likely not compiling well. A final_light with a value of 0 would just turn it black.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

All four versions have the same result, a white screen with dark grey cutout rectangle on the bottom of the screen.

I changed all the
FragmentProgram = compile glslf ps_main();
to
FragmentProgram = compile latest ps_main();
and reran each test.

Results :

version _a -
Displayed all the objects.

version _b -
Same as _a.

version _c -
Looked somehow different than _a and _b, and the column was tinted pink.

version _d -
Only showed a gray screen.

So it looks like the problem is with casting shadows somehow.

Dario ff
Member #10,065
August 2008
avatar

Great. Version _d only has this (horrible I know) chunk of code added:

#SelectExpand
1 if (tz < shadow_f) { 2 float4 new_col; 3 float al; 4 al = 1.0; 5 6 new_col = tex2D(texture_shadow_map, screen_pos+float2((2.0/screen_w), (2.0/screen_h))); 7 float shadow_t; 8 shadow_t = new_col.r*255.0 + new_col.g*255.0*255.0; 9 if (tz < shadow_t) al+=1.0; 10 11 new_col = tex2D(texture_shadow_map, screen_pos+float2((2.0/screen_w), (-2.0/screen_h))); 12 shadow_t = new_col.r*255.0 + new_col.g*255.0*255.0; 13 if (tz < shadow_t) al+=1.0; 14 15 new_col = tex2D(texture_shadow_map, screen_pos+float2((-2.0/screen_w), (2.0/screen_h))); 16 shadow_t = new_col.r*255.0 + new_col.g*255.0*255.0; 17 if (tz < shadow_t) al+=1.0; 18 19 new_col = tex2D(texture_shadow_map, screen_pos+float2((-2.0/screen_w), (-2.0/screen_h))); 20 shadow_t = new_col.r*255.0 + new_col.g*255.0*255.0; 21 if (tz < shadow_t) al+=1.0; 22 23 al /= 5.0; 24 luminance2 -= 0.12*al*directional_strength; 25 }

So I guess you can comment there and see what happens. My guess is that ATI doesn't allow to read from outside the texture, so that's why it crashes probably. If commenting those lines between al=1.0; and al /= 5.0; works, then it's that I guess. I'll try and fix those coordinates inside the texture's limits.

EDIT: Try the attached shader if you want. And thanks, this will help me a lot later. :)

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Using version _d, if I comment out this line :
luminance2 -= 0.12*al*directional_strength;
Then it displays like version _c, with a pink glow on the column and rectangular prism.

Edit for your edit :
I tried the shader you attached in your last post, and it was back to the white screen with dark grey cutout rectangle again. I changed 'compile glslf' to 'compile latest' again, and then it was back to the gray screen.

If I comment out the same line I did with version _d, then it works like version _c again.

Dario ff
Member #10,065
August 2008
avatar

I see. Then I guess you should try either:

luminance2 -= 0.12;
or
luminance2 -= 0.12*al;
or
luminance2 -= 0.12*directional_strength;

To see which of them won't let it compile.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Using all the different combinations you posted, I still get a gray screen.

I just noticed on line 218 you have this :
if (luminance2 < 0.0) luminance = 0.0;

See how it sets luminance to 0.0 instead of luminance2?

Well I changed it to :
if (luminance2 < 0.0) luminance2 = 0.0;
and I still get a gray screen.

The only way it works is if I comment out
// luminance2 -= 0.12*al*directional_strength;
and leave
if (luminance2 < 0.0) luminance = 0.0;
as it was.

Dario ff
Member #10,065
August 2008
avatar

That weird behaviour reminds me of what might happen when using way too much RAM for the current shader.

I really don't have any clue how to solve that weird problem, other than trying to lower the amount of memory used.

Try lowering these arrays' size:

float light_x[32];
float light_y[32];
float light_z[32];
float light_r[32];
float light_g[32];
float light_b[32];
float light_range[32];

To 24, or 16.

And yeah, I couldn't figure out how to pass float3's arrays instead. :P

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

 1   2   3 


Go to: