Author Topic: Psx blending to opengl.  (Read 10192 times)

Akari

  • Moderator
  • *
  • Posts: 766
    • View Profile
Psx blending to opengl.
« on: 2006-11-20 12:12:46 »
I'm try to implement PSX blending in OpenGL.
The trouble is I can't set texture alpha to 0.5 and 0.25 together. I set it to 0.5f.

// 0.5xB+0.5 x F
case BLEND_PSX_0: glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); break;
// 1.0xB+1.0 x F
case BLEND_PSX_1: glBlendFunc(GL_ONE, GL_ONE); break;
 // 1.0xB+0.25 x F (not this exactly)
case BLEND_PSX_3: glBlendFunc(GL_SRC_ALPHA, GL_ONE); break;

Can someone with good knowledge in OpenGL check if I'm right and help me to add  1.0xB-1.0 x F blending. And maybe fix my last blending.

gigaherz

  • *
  • Posts: 105
    • View Profile
    • gigaherz's shitty stuff
Re: Psx blending to opengl.
« Reply #1 on: 2006-11-21 15:48:15 »
That's most probably why psx emulators use alpha multipass (one for the 0.25 and then the other 0.25 left I suppose).

I don't really know what do the B and F in there mean so, assuming F=source and B=dest, seems right.

As for subtractive blending, there is an extension that lets you change the blending equation from D=D+S to D=D-S or D=S-D:
http://oss.sgi.com/projects/ogl-sample/registry/EXT/blend_subtract.txt

if you want to get more accurate results, and subtractive blending is available, you can do two passes like:
if you have 0.5*B + 0.25*F, you could do a 0.5*B+0.5*F, and then a 1*B-0.25*F, so it effectively gets you 0.5 and 0.25.

EDIT: just as a note, the extension depends on EXT_blend_minmax, so here is the link to that extension:
http://oss.sgi.com/projects/ogl-sample/registry/EXT/blend_minmax.txt
« Last Edit: 2006-11-21 15:52:19 by gigaherz »

einherjar

  • *
  • Posts: 38
    • View Profile
Re: Psx blending to opengl.
« Reply #2 on: 2006-11-21 16:36:37 »
That's most probably why psx emulators use alpha multipass (one for the 0.25 and then the other 0.25 left I suppose).

Agreed. After turning the equation upside down, I can't see how to implement this using
common/standard GL blending functions in one pass.

... fragment shader, anyone?  :wink:
(OK, it's overkill, but it would work)

Micky

  • *
  • Posts: 300
    • View Profile
Re: Psx blending to opengl.
« Reply #3 on: 2006-11-21 18:22:40 »
... fragment shader, anyone?  :wink:
(OK, it's overkill, but it would work)
Would that help? From what I understand the problem is not the texture combiner / fragment shader stage, but the blending between fragment and framebuffer.

einherjar

  • *
  • Posts: 38
    • View Profile
Re: Psx blending to opengl.
« Reply #4 on: 2006-11-21 20:44:36 »
... fragment shader, anyone?  :wink:
Would that help? From what I understand the problem is not the texture combiner / fragment shader stage, but the blending between fragment and framebuffer.

I was thinking about a fragment shader which would multiply the input colors by a constant (-1.0 for mode 2; 0.25 for mode 3),
and a (GL_ONE, GL_ONE) blending.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: Psx blending to opengl.
« Reply #5 on: 2006-11-21 21:42:06 »
Surprisingly the best place to ask about this is a Playstation GPU developer.
Pete is a good one to try as he implemented an OGL plugin that had to deal with the subtractive and various blending modes in the PS1.

Here is a start http://www.pbernert.com/ another place to ask would be http://forums.ngemu.com/plugin-questions-troubleshooting/
If Lewpy or Pete are about they are the ones who will know. Why do I say that? Ummm I made a simple plugin once based like Pete on someone elses code for the GPU.  It actually worked surprisingly well. I was startled however once I started textures that was my undoing. :D

Before killing yourself with such things, I recomend oserving what blending modes are used.  I believe only the additive one is used.

By the way I believe F B are foreground and background.  Foreground being the screen background being the texture.
The playstation allowed blending to ocure anywhere in the display and because of the way textures were used this means that one could do textures or other things in another section of the screen.  That being said I don't believe this to be used by FF7.

Cyb
« Last Edit: 2006-11-21 21:45:55 by Cyberman »

gigaherz

  • *
  • Posts: 105
    • View Profile
    • gigaherz's shitty stuff
Re: Psx blending to opengl.
« Reply #6 on: 2006-11-21 23:27:00 »
The only place where "special" texture usage (basically, framebuffer reads) make sense is in the battle start effect (I can't really remember how did the ff7 battles start tho), but unless that part is scripted, it can just be reimplemented using simple PC methods...

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: Psx blending to opengl.
« Reply #7 on: 2006-11-22 01:43:05 »
Unfortunately this is NOT where they are prominently (if at all) used.
Yes FIELD locations are it!

Wall market is one and the other is the field location for crossing the mountain range into North Coral and the Gold Saucer.  The first field location you enter as you go in has a bright sunny disposition which is done by... using a nice big sprite pasted on the screen.

Wall market has halo's on luminaries created by ... the same method using a nice sprite and pasting it on the screen.

These both use blending methods to work.   I thought it was scene lighting but Ficedula corrected me on that, and examining the aforementioned background data disclosed the halo textures used.

Cyb

einherjar

  • *
  • Posts: 38
    • View Profile
Re: Psx blending to opengl.
« Reply #8 on: 2006-11-22 07:20:49 »
As for subtractive blending, there is an extension that lets you change the blending equation from D=D+S to D=D-S or D=S-D:

Yes, it is part of the imaging operation subset, which was introduced in openGL 1.2 (april 1999)
as a set of extensions (ARB_imaging). It was only specified as mandatory in openGL 1.4 (july 2002).

If the implementation supports it, you have access to:

- glBlendColor and GL_CONSTANT_ALPHA
- glBlendEquation

So that you can write:

{
  // 0.5xB + 0.5 x F
 case BLEND_PSX_0:
   glBlendEquation(GL_FUNC_ADD);
   glBlendColor(1.0, 1.0, 1.0, 0.5);
   glBlendFunc(GL_CONSTANT_ALPHA, GL_CONSTANT_ALPHA);
   break;

   // 1.0xB + 1.0 x F
 case BLEND_PSX_1:
   glBlendEquation(GL_FUNC_ADD);
   glBlendFunc(GL_ONE, GL_ONE);
   break;

   // 1.0xB - 1.0 x F
 case BLEND_PSX_2:
   glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
   glBlendFunc(GL_ONE, GL_ONE);
   break;

   // 1.0xB + 0.25 x F
 case BLEND_PSX_3:
   glBlendEquation(GL_FUNC_ADD);
   glBlendColor(1.0, 1.0, 1.0, 0.25);
   glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE);
   break;
}

Notice that by using this, you do not need "explicit" alpha channel anymore.


The subsidiary question is: what openGL version/extensions are required for running q-gears ?
« Last Edit: 2006-11-22 07:56:24 by einherjar »

Synergy Blades

  • Guest
Re: Psx blending to opengl.
« Reply #9 on: 2006-11-22 14:29:13 »
Quote
I thought it was scene lighting but Ficedula corrected me on that

I thought I told you that  :lol:

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: Psx blending to opengl.
« Reply #10 on: 2006-11-23 02:24:42 »
All right someone corrected me on that ;)

In any case I believe only 2 modes of addition are used.  You may want to see if shadows are used, but I don't believe they are.

There are some interesting issues too. Since the scenes are permanently lit, to my knowledge there aren't any shadows in the game at all. IE no place where your character fades light to dark and visa versa.

Is this correct or is my memory just a toad in a whirring blender?

Cyb

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Re: Psx blending to opengl.
« Reply #11 on: 2006-11-23 03:38:51 »
Well, it's used in battles a lot. You have the shadows under the characters mosters. Also it's in some battle effects too. (I think some gavity attacks and ultima?)

gigaherz

  • *
  • Posts: 105
    • View Profile
    • gigaherz's shitty stuff
Re: Psx blending to opengl.
« Reply #12 on: 2006-11-23 13:25:42 »
I was thinking, fragment programs were introduced with opengl 2.0 right? IIRC, then they are "equivalents" to Pixel Shaders 2.0 in Direct3d... and none of my 2 gfx cards can do them (yes I klnow I need new gfx cards... :P)

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: Psx blending to opengl.
« Reply #13 on: 2006-11-23 15:39:53 »
Well firstly pixel shaders et al won't be needed until say... FF8 (wink nudge).  Sadly which I am starting to work on, gentleman and ladies please pray for my soul (Cough cough hack).

All right halkun I stand corrected (how else should I stand?), and thanks for giving insite.  That means that lightly subtractive blending is used in the battle module and it means we have to 'walk this way'.  I know FF8 supports them so I suppose we have to work on drawing shadows?  What about field scenes? I'll load up FF7 real quick play an hour and let you know... :D

Cyb