Qhimm.com Forums

Final Fantasy 7 => Other Mods => WIP => Topic started by: DLPB_ on 2017-05-07 15:33:42

Title: [FF7PC] Post bug reports here [use The Reunion thread instead]
Post by: DLPB_ on 2017-05-07 15:33:42
FF7 The Reunion Database (https://goo.gl/MUP4i9)

Final Fantasy VII suffers from a very large number of bugs, across all modules. Some are small and insignificant; others can hang or crash the game. White Wind and I are attempting to log all known bugs with Final Fantasy VII PC (1.02 English with Aali's Driver/Steam English version) and then find a solution. 

We can't possibly find and fix all the bugs, so if you see a bug that isn't in the database above (see the tabs at the bottom), or you think you can fix a bug, please don't hesitate to post here.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-07 15:40:34
I bet I can fix number 14 (reviving dead characters with damaging scripts). That'll either be a field fix or a exe tweak.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Covarr on 2017-05-07 16:04:31
I bet I can fix number 14 (reviving dead characters with damaging scripts). That'll either be a field fix or a exe tweak.
Make sure to specify which tab. There are a few #14s... though I assume you mean Field #14.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-07 16:13:21
Field 14 is unlikely to be fixed by field script. I tried it.  Field functions don't support a check for current HP or anything, so all you can do is take off an amount of HP (in this case, 10000 - then add 1).  The only way I can see to fix it would be an entirely new function or something?

There are some issues that can be fixed by new code in exe though, like Menu #5.

The order of the database is subject to change, due to arrangement by alphabetical order.  I guess that's not a good idea.  I'll simply add new entries to the bottom from now on.  I am still in the progress of adding The Reunion Database entries to this database also.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-07 17:02:44
Make sure to specify which tab. There are a few #14s... though I assume you mean Field #14.
didn't notice the tabs. Yes, I meant the field bug. The trick is "don't revive, but don't kill either". The field opcode probably needs an asm edit.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-07 17:16:19
I think the function needs to be able to do that in other places though.  To be able to revive or kill based on simple assignments to HP of a character.  I'm not sure where else it's used. What was really needed was a function to set HP to an absolute number rather than "decrease" and "increase".  They likely came up with the idea of "make HP 1 after being hit with the needles" later in development. 

What I am doing for Weapon is simply making these needles and so on an instant death or other bad effect like decrease HP.  If all 3 chars are 0 HP, then game over.  The latter is already another bug (all 3 chars can be dead on field), which will need fixing.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-08 07:05:12
#FMV - ending2 - Clouds model is mirrored in one scene - https://youtu.be/22Dqy2jVqY0?t=397

#General - FF7 -exe - the coordination for the light sources are wrong (field and WM), which produce a different light on PC as on PSX (I would say its 90° clock-wise, it looks as if x and y are swapped[?]). The field could be fixed by changing the values in the model loader.

#Aali's driver - Broken effects in battle (see Aerith final limit - PSX: https://youtu.be/rGWUP6W5170?t=75
PC: https://youtu.be/KKcNqosC_-Y?t=175) This probably belongs to the alpha blending issue.
The issue is that the game can't display a dynamic transparency effect as the PSX could do. I don't think it's the fault of Aali's driver alone, might be that the engine itself can't mimic the PSX blending effect or wasn't programmed to do it, because they only tested the normal effects. Still, I think that Aali's solution in his previous driver was the right way. While it has broken the opacity level of some textures, these could have been corrected manually and with a better result.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-08 15:55:39
I'll add these.  Aali has already explained the alpha effect issue - that the game has 2 alpha values but does not specify which should be used. At the moment the driver gets it right most of the time, but not always.  I guess it would mean manual work to flag exactly which effect to use where.

Quote
the whole alpha blending transparency issue which also affects the savepoints and other stuff. The issue is that the PC renderer has two different alpha values (vertex alpha, texture alpha) and the game doesn't specify which one to use (AFAIK), so sometimes the correct thing to do is to just use texture alpha, sometimes vertex alpha and sometimes the two should be combined to produce the correct result. The way it works now is correct most of the time but not always.


I also forgot to note there that the world map colour itself is broken compared to PSX.  Also, something else Aali notes:

Quote
the world map is already completely broken (shadows follow the rotation of the camera instead of being fixed in the world)
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-08 16:23:08
I think the function needs to be able to do that in other places though.  To be able to revive or kill based on simple assignments to HP of a character.  I'm not sure where else it's used. What was really needed was a function to set HP to an absolute number rather than "decrease" and "increase".  They likely came up with the idea of "make HP 1 after being hit with the needles" later in development. 

What I am doing for Weapon is simply making these needles and so on an instant death or other bad effect like decrease HP.  If all 3 chars are 0 HP, then game over.  The latter is already another bug (all 3 chars can be dead on field), which will need fixing.
Then the fault is in the field script. I just checked it and it just removes 501 HP and restores 1. That will heal all dead characters.
What needs to happen is the field script needs to be rewritten AND new codes need to be added. It needs to remove 500 and trigger the game over if all HP are 0. As you mentioned before there is no way for the field to check the HP of the party members. That needs to change. Codes 3C and 3D could be hijacked to return the HP and MP values of the party members.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-08 16:29:32
It should be possible to change script to remove an HP amount and then trigger game over if all chars HP is 0 by checking char HP from main loop (which will also fix other issues where all 3 characters can be dead).  It wouldn't be too difficult to fix.  Field would be amended so that it doesn't ever restore any HP with the needles and so on. If all else fails, adding the HP MP retrieval could be added too.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-08 16:34:03
Which part of the main loop? The field's main script or the game's main loop?
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-08 16:38:29
There are a lot of places you could do it really... especially since I am now using my own dll.  All it would require is me checking three vars and then calling the field game over function.  Not sure where would be best to check, but even a check in the frame limiter I have added (30 times a second) would work.  All the game over function does is set a few vars and call the music / terminate sound effects (well, it does now that I've fixed it).  So yeah it would be a simple exe addition.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-08 19:10:19
You should probably do it at the end of each field script. That way you can Game Over at a reasonable time. In the case like this, where you do damage then heal, it would kill at the appropriate time and not mid-dialog.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-08 22:06:31
Quote
#General - FF7 -exe - the coordination for the light sources are wrong (field and WM), which produce a different light on PC as on PSX (I would say its 90° clock-wise, it looks as if x and y are swapped[?]). The field could be fixed by changing the values in the model loader.

kaldarasha, do you have a picture of this to illustrate?
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-09 11:11:36
(http://i.imgur.com/jlUhv7q.jpg)(http://www.gameranx.com/img/13-May/ff7-ps-vs-pc-version-1-1.jpg)
(Now I see it isn't x and y which are swapped)

To be fair I have to mention that on PC the models are illuminated in real time while on PSX the light is backed at the models at the start of every scene. However on PSX the light comes most times from above, while on PC it seems to come from the front. Maybe the game reads the light information in the wrong order.

Okay, this is harder to fix as I thought it would be. I still would call this a minor bug and on PC we could and should use the three lights more effectively. Still needs Makoureactor to have the preview function for it.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Covarr on 2017-05-09 18:59:10
I can't believe I never noticed that before. The lighting on the PC version looks almost... inverted. It's not flipped on an axis. Rather, the areas that should be dark are light and the areas that should be light are dark. It's like a sign on a variable for light value got flipped somewhere.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-09 20:18:06
I can't believe I never noticed that before. The lighting on the PC version looks almost... inverted. It's not flipped on an axis. Rather, the areas that should be dark are light and the areas that should be light are dark. It's like a sign on a variable for light value got flipped somewhere.

Sadly not. I played around with the light on field and even reverted it. Nothing results in a similar look. However as you said it,  barely anyone does notice it, that's why I would give it a low priority.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-09 20:31:19
Is this related to the picture I popped up a while back regarding colour difference between World Map PSX and PC?

Something is very wrong here.  Since the Wm is entirely a 3D model, it could be why all of it is knackered.


How are you attempting to fix this, Kal?  It might also be related to other broken graphic functions.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-09 22:24:27
I think that the whole shading engine is broken. As you have posted somewhere else the shine effect (KAWAI?) is also wrong. I think that on PSX the objects on the WM did have baked light on them. At first, I thought it's actually stupid to do so, but I guess they wanted to save memory on the disk this way.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 01:24:34
What we need to know the most is if this has always been the case.  How does this look when using Win 98?
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-10 01:36:56
I'm pretty sure it's always been this way.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 01:39:09
I'm on it.  Certainly changing those values (model light and global light) has a big impact in game.  If I can track down what is using it where, we may be able to tweak it.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-10 02:49:18
It looks like the y and z coordinate of the light source may have gotten reversed.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 03:33:28
I'm not seeing much difference (I can't see any actually :P ) when reversing the Y Z.  I do see a good improvement when increasing the global light, though.

Got a before and after?  If it is a Y Z issue, then that can prob be fixed in exe.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: nfitc1 on 2017-05-10 04:55:19
I was speaking in theory. It looks like some pair of coordinates got reversed.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 05:07:44
Yeah, I agree. I've started mixing and matching. But if this fails, it may just be as Kal said and the whole thing is crapped out.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-10 19:09:57
I guess I knew what's going on. See this:
(http://i.imgur.com/fXotPfk.jpg)
(seen from the models position: Red comes from the right, green from below behind and blue from upper behind)

The light is calculated by the camera position.

Quote from: http://www.neogaf.com/forum/showthread.php?t=879050&page=3
The PSOne has a co-processor called the Graphics Transform Engine, which is meant to perform many 3D operations like matrix-vector multiplication, lighting and fog. It was fixed-point
  • (aka: integer) based and couldn't work with floating point numbers. The X, Y and Z coordinates of vectors are stored as 16-bit values: 1-bit for sign, 3-bits for integral part and 12-bits for the decimal part. It only supported 3x3 rotation matrices with translation being a separate operation using vectors with 32-bit XYZ integer components (no fractional parts).


This seems to be one reason behind the wobbliness: while drawing a scene, the objects's polygons must be transformed from their local space into world space (at the very least one rotate and one translate command) and then from world into camera space (another rotate and translate). Since translation is integer-only (no fractional), it will "snap" around, the severity depending on the scale of the scene elements. Also, if you have multiple rotations and translations stacking on top of each other, the precision errors will build up quickly.

If I'm correct, then every shader effect should be rendered in the world space. Though, I don't know if the PC version does render in that way.  :-[
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: luksy on 2017-05-10 20:08:47
The double transform itself is nothing unusual, are you saying the PC and PS1 versions apply lighting at different stages?
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-10 20:33:37
That would explain why swapping the values between the axis doesn't work and how such a bug could occur. I guess the port team didn't notice that there was a difference in the look.
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 21:30:19
Are we sure that's what is causing the fault?  Could it not just be a mix up of the X Y Z values - or the global light not being processed correctly?  What happens if you mess about with the X Y Z order?
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: Kaldarasha on 2017-05-10 22:18:17
Did that already and you won't get any good result. That's why I got the idea with the colored light and the cube to see where actually the axis are. I post tomorrow more pictures which show only one axis (color at the time) and another scene.

Edit:
Now where I think about it maybe the the game was meant to use the field orientation but wrongly use the orientation of the camera. ???
Title: Re: [FF7PC] The Big Bug List - post bug reports here
Post by: DLPB_ on 2017-05-10 23:39:39
What is your global light set to in your test?  Black 0 0 0?  I guess I'd need a way to put the model into the game too though.  Someone else like Green_Goblin would have to do this test for us for the PSX version.

Why did they even do this anyway?  Why do all models have differerent light on different fields?  Was all this nonsense really necessary?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-12 21:16:39
The Global light is uninteresting because it only handles the brightness of the model.
Here some pictures with only one color active:


x-axis
(http://i.imgur.com/ei3C9Cz.jpg)(http://i.imgur.com/xLXEEAd.jpg)
positive valuenegative value

y-axis
(http://i.imgur.com/Qm2rGw2.jpg)(http://i.imgur.com/ZADHJsF.jpg)
positive valuenegative value

z-axis
(http://i.imgur.com/gyuKGU8.jpg)(http://i.imgur.com/YVrFOm2.jpg)
positive valuenegative value

Here is the cube for testing (inside is the Cloud model, Kimera refused for some reason to use only the cube attached to the skeleton).
https://mega.nz/#!GdVzCYZa!7cD9leLanRd8WjPAd881QHjYxZl1TKuUr_1Y7Hizv10
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-12 21:20:39
I may be being thick here since I don't understand this stuff well enough, but where is the bug?  How should these look?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-12 22:56:24
That's the big problem, I don't know where the bug has its origin. The values in the flevel.lgp are the same as on the psx files. The y and z seems to be wrong displayed. The y value should come from above of the model, but on PC it comes from the front. Let me demonstrate it with Kimera
PC
(http://i.imgur.com/iEk8fOi.jpg)

PSX
(http://i.imgur.com/nayOUgX.jpg)

From the tests I made the light is somehow connected to the camera. Now is the question, is that behavior wrong or does have the PSX different values for the camera when calculating the light?
I simply cannot imagine that they added some factors or mixed something up. It seems more practical to me that they didn't understand what the PSX did do and they have written their own way to implement the light.

As I said it's a very minor bug, which we can't solve yet at last I have no time to deal with it further. But maybe when MR gets the preview for the light we can fix it manually.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-13 10:31:34
Looking at your pics again, it does look like Z and Y are wrong way around?  The Z should go inside and out, not up and down. Depends how it decides what X Y Z is.  We need to see this test on the PSX somehow.


Kal... do all the colours work fine too with each direction?  If you test all three X with red 4000, then all three Y with 4000  etc (but one at a time).
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-13 23:28:41
http://vignette1.wikia.nocookie.net/finalfantasy/images/e/e4/Sephiroth-FFVIIArt.png/revision/latest?cb=20141008012137

Sep's hair is grey not white... so turns out grey would prob be closer anyway.  But whatever.  I tracked down part of game that adds all shading.  This is what happens when it's nopped (68EAC5):


https://ibb.co/dF2bvk

perhaps even if all else fails, we can just add our own shading to the models and forget real time?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-14 04:25:20
I'm beginning to wonder whether the PC version is actually correct colour and the PSX is wrong due to how it is forced to use colour. PC can have a full range, whereas the PSX could not, right?  Sep's hair is more correct in PC for example - and certainly is correct to the model itself, which is all grey. The sin colour looks right in PC too.

I am experimenting now changing light using the engine... so I may be able to get the psx look eventually anyway.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: JWP on 2017-05-14 10:39:27
If it helps, here's what a frame rendering looks like in ff7 when using Aali's opengl driver:
gliInterceptLog.txt (http://www.extapathy.co.uk/gliInterceptLog.txt)

(I'm using a modified version of glintercept (https://github.com/dtrebilco/glintercept) to add FF7 related data)
and the shaders that were in memory at the time:
Code: [Select]

//== PROGRAM LINK STATUS = TRUE
//== PROGRAM VALIDATE STATUS = TRUE

//======================================================
//   Vertex Shader 2
//======================================================

//== SHADER COMPILE STATUS = TRUE
#version 110

uniform int vertextype;
uniform bool fb_texture;
uniform int blend_mode;

uniform mat4 d3dprojection_matrix;
uniform mat4 d3dviewport_matrix;

void main()
{
vec4 pos = gl_Vertex;

gl_FrontColor.rgba = gl_Color.bgra;

// TLVERTEX
if(vertextype == 3)
{
pos.w = 1.0 / pos.w;
pos.xyz *= pos.w;
pos = gl_ProjectionMatrix * pos;
}
// LVERTEX and VERTEX
else
{
pos = d3dviewport_matrix * d3dprojection_matrix * gl_ModelViewMatrix * pos;

if(gl_FrontColor.a > 0.5) gl_FrontColor.a = 0.5;
}

// BLEND_NONE
if(blend_mode == 4) gl_FrontColor.a = 1.0;
// BLEND_25P
else if(blend_mode == 3) gl_FrontColor.a = 0.25;

gl_TexCoord[0] = gl_MultiTexCoord0;

if(fb_texture) gl_TexCoord[0].t = 1.0 - gl_TexCoord[0].t;

gl_Position = pos;
}

//======================================================
//   Fragment Shader 3
//======================================================

//== SHADER COMPILE STATUS = TRUE
#version 110

uniform int vertextype;

uniform sampler2D tex;
uniform bool texture;
uniform bool fb_texture;
uniform bool modulate_alpha;

void main()
{
vec4 color = gl_Color;
vec4 texture_color;

texture_color = texture2D(tex, gl_TexCoord[0].st);

if(texture)
{
if(fb_texture && texture_color.rgb == vec3(0.0, 0.0, 0.0)) discard;

if(texture_color.a == 0.0) discard;

color *= texture_color;

if(!modulate_alpha) color.a = texture_color.a;
}

gl_FragColor = color;
}

interestingly, I can't see any calls to the lighting functions in opengl, so I wonder if the lighting calcs are just done with the shader.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-14 12:27:46
The function I posted above seems to handle all light calcs. Not sure if that relates to a shader calc somewhere.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: JWP on 2017-05-14 13:28:51
I nooped the function and the only difference between the 2 log traces was the texture used, so the change is either in a texture or a value not explicitly stated e.g. matrices or stuff in the buffers.
I think the texture changes are more likely to be animations though e.g. sea/eyes.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-14 18:27:06
All i think it does it assign colour and brightness to the model from that other function.  When it's removed, all shading disappears too.  It's not at all complex. Somewhere in there I think there is probably an easy way to tweak the calcs to make the light behave like psx.  I already made all the models brighter in one of the functions by just adding fmul 1.5 to red green blue. But that's assuming the colour in psx wasn't there by the very nature of NTSC/PAL colour.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-14 23:56:45
I asked JWP to add me a contrast and gamma changing shader. It does seem to make the game better.  Pretty sure 1.2 is closer to the PSX levels than what we have currently, which is overly dark. I have also added min max levels to the shader.  I am learning.

But I am doing some tests.  In any case, I am still not sold on the idea that there is any problem here other than PC colour being more correct than the PSX was.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 01:30:02
Covarr brought to my attention a shading issue in del3 (Costa del Sol with the beach), where Cloud's head is shaded differently to PSX. I think this is unrelated to the shading issue we have been discussing.

Field Model graphic filter - UNKNOWN9
Wait 1 frame
Field Model graphic filter - UNKNOWN9


is being set on the characters in this field, which makes them shine and shimmer as they walk. It looks pretty poor to be honest in PC version, since it's the KAWAI function, which is broken. The effect is hardly even noticeable on the PSX version.

Speaking of KAWAI, the field opcode function is only a basic set up. It sends values that are used in the main function (called all the time to draw and sort all 3d objects) at 6392BB.  For example, the main operation to be carried out is found at points like 63959E
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 03:58:31
Also, I don't think the "shading issue" is all that much of a problem.  When you compare to PSX, using my own tweaked shaders, the colour and so on is superior in PC (right).

https://e63i.imgup.net/test1fef9.png

Something tells me that the image Kaldarasha uploaded has had some brightness added to it by emulator or what not.  It's not what mednafen outputs.  I'll check the truck scene soon.


Edit.

As I suspected... that picture by Kaldarasha has been modified from what a direct output gives (probably captured from Youtube or something)

https://d76i.imgup.net/mednafenfffffd.png

That is the PSX output of the truck scene.  Yeah, the shading is still not the same on PC... but it's pretty small fry isn't it when you look at the overall difference in quality including colour / filtering and so on.  I'll see if I can tweak graphics to make PC do what the PSX is.  The shading is certainly wrong on PC.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: luksy on 2017-05-16 05:26:38
Could this be anything to do with

Quote
The Playstations RGB values aren't linear to normal RGB values (as used on PCs). The min/max values are of course the same, but the medium values differ:
  Intensity        PC      PSX
  Minimum          0       0
  Medium (circa)   16      8
  Maximum          31      31
Ie. on the PSX, the intensity increases steeply from 0 to 15, and less steeply from 16 to 31.

http://problemkaputt.de/psx-spx.htm

Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 05:32:39
It's certainly possible, but I know sod all about how ff7 is even calculating the so called shading :P  If this is the issue, perhaps a shader could correct it?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Covarr on 2017-05-16 14:01:17
Could this be anything to do with

http://problemkaputt.de/psx-spx.htm



I doubt it. Lighting isn't just operating at a weird steepness. It's almost as if it's reversed.

PSX left, PC right:
(http://i.imgur.com/Qg9ZYS1.png)(http://i.imgur.com/2oILyJf.png)

What can be seen here is that the angle itself seems to be near-completely wrong. In the PSX version, the light source appears to be coming from below and to the right. In the PC version, it's coming from above and to the left. It's especially obvious in his hair; the brightest areas in the PSX version are the darkest in the PC version, and vice versa. As strictly backwards as it is, I'm inclined to think it's a calculation error, with some variable being sign flipped, or subtracted from 255 instead of added to 0, or something like that.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 16:14:55
I think I've tracked down the dodgy function.  Here's how mine looks after a few multiplications were nopped:

https://pasteboard.co/71xZaBQQY.png
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: obesebear on 2017-05-16 22:16:39
Also, I don't think the "shading issue" is all that much of a problem.  When you compare to PSX, using my own tweaked shaders, the colour and so on is superior in PC (right).

https://e63i.imgup.net/test1fef9.png

A bit off topic, but why is the background such better quality on the psx?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 22:22:45
I've enhanced the gamma and levels and saturation using shader, but that's not what's making the biggest difference.  It's probably just how the PC and PSX are being rendered.  PC isn't applying any sort of filtering to the background - you're getting sharp pixellation. The PSX doesn't have the pixellation as much so you get blurring instead.

This is also why I refuse to add any of the background packs around here... because when you lose pixellation, you lose clarity. The human brain is good at imagining/adding detail when it sees a pixellated image... it can't do that if you've blended all the pixels together and made it either blurred or plastic.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: obesebear on 2017-05-16 23:38:10
So it's the exact same image?  The PSX gold framed image looks like it might say POKER, whereas the PC version is just a blob of pixels
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-16 23:46:58
I prefer the PC version tbh haha.  I think PSX suffers with blurriness and washed out colours because of it. I don't mind the pixellation.  Well, OK writing suffers a lot, as you just noted.

But yeah, they are the same image... both 320 * 224,
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-17 12:54:26
A bit off topic, but why is the background such better quality on the psx?

As Luksy has posted the PSX calculates and renders the colors differently. And now I understand what Sunwalkers shader port does:
(http://i.imgur.com/YrwmSFr.jpg)(http://i.imgur.com/sFDbPKq.jpg)
no shaderwith shader
Look how much better the shadow area at the firs G-Bike gaming machine does blend.

The shader:
Code: [Select]
/*===============================================================================*\
|#######################   [FINAL FANTASY 7 SHADER FX]    ########################|
|#########################   By Sunwalker 21/Jan/2017   ##########################|
||                                Version 1.05                                   ||
||                                                                               ||
||          This program is free software; you can redistribute it and/or        ||
||          modify it under the terms of the GNU General Public License          ||
||          as published by the Free Software Foundation; either version 2       ||
||          of the License, or (at your option) any later version.               ||
||                                                                               ||
||          This program is distributed in the hope that it will be useful,      ||
||          but WITHOUT ANY WARRANTY; without even the implied warranty of       ||
||          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        ||
||          GNU General Public License for more details. (c)2016                 ||
||                                                                               ||
|#################################################################################|
\*===============================================================================*/
#version 120

#extension GL_NV_gpu_shader5 : enable
#extension GL_ARB_gpu_shader5 : enable
#extension GL_ARB_shader_precision : enable
#extension GL_ARB_sample_shading : enable
#extension GL_ARB_texture_rectangle : enable
#extension GL_ARB_shader_storage_buffer_object : enable
#extension GL_ARB_shader_image_load_store : enable
#extension GL_ARB_bindless_texture : enable
#extension GL_ARB_shading_language_420pack : enable


/*------------------------------------------------------------------------------
[DEFINITIONS & ON/OFF OPTIONS]
------------------------------------------------------------------------------*/
//--------------------------#[CHOOSE EFFECTS]#--------------------------------\\
//#[ANTIALIASING TECHNIQUES]   [1=ON|0=OFF]  # NOTE:
#define USE_FXAA                  0      //# [0 or 1] FXAA Fast Anti-aliasing

//#[LIGHTING & COLOUR]         [1=ON|0=OFF]  # NOTE: This one can enable all
#define GAMMA_CORRECTION            0      //# RGB Gamma Correction. Fixed expansion to variable compression gamma correction curve.
#define BLENDED_BLOOM               0      //# High Quality SP Bloom. Soft lighting with blending techniques, for a natural looking bloom.
#define SCENE_TONEMAPPING           0      //# HDR Scene Tonemapping. Layered component conversion, and applies scene tone mapping.
#define COLOR_CORRECTION            0      //# Component Color Correction. Colorspace conversion, with correction curves, and multiple palette types.
#define CROSS_PROCESSING            0      //# Filmic Cross Processing. Alters the tone of the scene, crossing the game's color set, with another.
#define PIXEL_VIBRANCE              0      //# Pixel Vibrance. Intelligently adjusts pixel vibrance depending on original color saturation.
#define COLOR_GRADING               0      //# Post-Complement Colour Grading. Alters individual colour components on a scene, to enhance selected colour tones.
#define USE_CURVES            0    //# [0 or 1] Curves : Contrast adjustments using S-curves.


//#[MISC]                      [1=ON|0=OFF]  # NOTE: Enable one only
#define NTSC_TV_EMULATION           1      //# SimoneT's TV Colors Emulation Shader. Use to emulate the original PSX color space tone, and vibrancy.
/*------------------------------------------------------------------------------
[EFFECT CONFIG OPTIONS]
------------------------------------------------------------------------------*/

//##[GAMMA_CORRECTION]
#define Gamma 2.40                            //[1.5 to 4.0] Gamma correction. Decrease for lower gamma(darker). Increase for higher gamma(brighter). (Default: 2.2)

//##[BLENDED_BLOOM]
#define BloomType BlendScreen                   //[BlendGlow, BlendAddGlow, BlendAddLight, BlendScreen, BlendLuma, BlendOverlay] The type of blended bloom. Light<->Dark.
#define BloomStrength 0.200                   //[0.000 to 1.000] Overall strength of the bloom. You may want to readjust for each blend type.
#define BlendStrength 1.000                   //[0.000 to 1.000] Strength of the blending. This is a modifier based on bloom. 1.0 equates to 100% strength.
#define BloomDefocus 2.000                    //[1.000 to 4.000] The initial bloom defocus value. Increases the softness of light, bright objects, etc.
#define BloomWidth 3.200                      //[1.000 to 8.000] Width of the bloom. Adjusts the width of the spread and soft glow. Scales with BloomStrength.
#define BloomReds 0.040                       //[0.000 to 1.000] Red channel correction of the bloom. Raising will increase the bloom of reds.
#define BloomGreens 0.030                     //[0.000 to 1.000] Green channel correction of the bloom. Raising will increase the bloom of greens.
#define BloomBlues 0.020                      //[0.000 to 1.000] Blue channel correction of the bloom. Raising will increase the bloom of blues.

//##[SCENE_TONEMAPPING]
#define TonemapType 2                         //[0|1|2|3] The base tone mapping operator. 0 is LDR, 1 is HDR(original), 2 & 3 are Filmic HDR(slight grading).
#define TonemapMask 1                         //[0 or 1] Enables an ALU tone masking curve. Produces a nice cinematic look. Suits some games more than others.
#define MaskStrength 0.10                     //[0.000 to 1.000] Strength of the tone masking. Higher for a stronger effect. This is a dependency of TonemapMask.
#define ToneAmount 0.360                      //[0.050 to 1.000] Tonemap strength (tone correction). Higher for stronger tone mapping, lower for lighter.
#define BlackLevels 0.060                     //[0.000 to 1.000] Black level balance (shadow correction). Increase to deepen blacks, lower to lighten them.
#define Exposure 1.000                        //[0.100 to 2.000] White correction (brightness). Higher values for more scene exposure, lower for less.
#define Luminance 1.000                       //[0.100 to 2.000] Luminance average (luminance correction). Higher values will lower scene luminance average.
#define WhitePoint 1.075                      //[0.100 to 2.000] Whitepoint average (wp lum correction). Higher values will lower the maximum scene white point.

//##[COLOR_CORRECTION]
#define CorrectionPalette 1                   //[1|2|3|4|5] The colorspace palette type. 1: RGB, 2: YXY, 3: XYZ, 4: HSV, 5: YUV. Each one will produce a different combination of shades & hues.
#define ChannelR 1.40                         //[0.00 to 8.00] R(1), Y(2), X(3), H(4), Y(5) component channel varies with the colorspace used. Higher values increase correction strength.
#define ChannelG 1.60                         //[0.00 to 8.00] G(1), X(2), Y(3), S(4), U(5) component channel varies with the colorspace used. Higher values increase correction strength.
#define ChannelB 1.80                         //[0.00 to 8.00] B(1), Y(2), Z(3), V(4), V(5) component channel varies with the colorspace used. Higher values increase correction strength.
#define PaletteStrength 2.00                  //[0.00 to 4.00] The interpolated strength ratio between the base color, and the corrected color. Raise to increase saturation.

//##[PIXEL_VIBRANCE]
#define Vibrance 0.15                          //[-1.00 to 1.00] Overall vibrance strength. Locally adjusts the vibrance of pixels depending on their original saturation.
#define RedVibrance 1.00                       //[-8.00 to 8.00] Red channel coefficient of the vibrance strength. Adjusting the vibrance of the red channel independently.
#define GreenVibrance 1.00                     //[-8.00 to 8.00] Green channel coefficient of the vibrance strength. Adjusting the vibrance of the green channel independently.
#define BlueVibrance 1.00                      //[-8.00 to 8.00] Blue channel coefficient of the vibrance strength. Adjusting the vibrance of the blue channel independently.

//##[CROSS_PROCESSING]
#define FilmicProcess 1                         //[1|2|3] The color conversion type for the cross process. 1: cool, 2: warm, 3: dusk. You can achieve different results with each.
#define RedShift 0.65                           //[0.10 to 1.00] Red color component shift of the filmic processing. Alters the red balance of the shift.
#define GreenShift 0.50                         //[0.10 to 1.00] Green color component shift of the filmic processing. Alters the green balance of the shift.
#define BlueShift 0.50                          //[0.10 to 1.00] Blue color component shift of the filmic processing. Alters the blue balance of the shift.
#define ShiftRatio 0.50                         //[0.10 to 2.00] The blending ratio for the base color and the color shift. Higher for a stronger effect.

//##[COLOR_GRADING]
#define RedGrading 1.20                         //[0.00 to 3.00] Red colour grading coefficient. Adjust to influence the red channel coefficients of the grading, and highlight tones.
#define GreenGrading 1.10                       //[0.00 to 3.00] Green colour grading coefficient. Adjust to influence the Green channel coefficients of the grading, and highlight tones.
#define BlueGrading 1.10                        //[0.00 to 3.00] Blue colour grading coefficient. Adjust to influence the Blue channel coefficients of the grading, and highlight tones.
#define GradingStrength 0.35                    //[0.00 to 1.00] The overall max strength of the colour grading effect. Raise to increase, lower to decrease the amount.
#define Correlation 1.00                        //[0.10 to 1.00] Correlation between the base colour, and the grading influence. Lower = more of the scene is graded, Higher = less of the scene is graded.

//##[USE_CURVES]
#define Curves_mode        2             //[0|1|2] Choose what to apply contrast to. 0 = Luma, 1 = Chroma, 2 = both Luma and Chroma. Default is 0 (Luma)
#define Curves_contrast 0.30         //[-1.00 to 1.00] The amount of contrast you want

//##[Advanced curve settings]
#define Curves_formula      3             //[1|2|3|4|5|6|7|8|9|10] The contrast s-curve you want to use.
                                      //1 = Sine, 2 = Abs split, 3 = Smoothstep, 4 = Exp formula, 5 = Simplified Catmull-Rom (0,0,1,1), 6 = Perlins Smootherstep
                                      //7 = Abs add, 8 = Techicolor Cinestyle, 9 = Parabola, 10 = Half-circles.
                                      //Note that Technicolor Cinestyle is practically identical to Sine, but runs slower. In fact I think the difference might only be due to rounding errors.
                                      //I prefer 2 myself, but 3 is a nice alternative with a little more effect (but harsher on the highlight and shadows) and it's the fastest formula


//[END OF USER OPTIONS]

/*------------------------------------------------------------------------------
[GLOBALS|FUNCTIONS]
------------------------------------------------------------------------------*/

//Global variables
#define saturate(x) clamp(x, 0.0, 1.0)
#define lerp mix
#define frac fract
#define fmod mod
#define mul(x, y) (y * x)
#define float4x3 mat4x3
#define float3x3 mat3
#define float4x4 mat4
#define lumCoeff vec3(0.212656, 0.715158, 0.072186)
#define PI 3.1415972

//OGL Uniforms
uniform sampler2D OGLTexture;
uniform sampler2D OGLTexture0;

//varying
uniform vec2 texcoord;

float Epsilon = 1e-10;

#define texture_width   1024.0
#define texture_height  1024.0

#define texel_size_x  (1.0 / texture_width)
#define texel_size_y  (1.0 / texture_height)

#define OGLSize     vec2(texture_width, texture_height)
#define OGLInvSize  vec2(texel_size_x, texel_size_y)

//Average Relative Luminance (HSP Color Model)
float AvgLuminance(vec3 color)
{
return sqrt(dot(color * color, lumCoeff));
}

//Smoothstep alt
float smootherstep(float a, float b, float x)
{
x = saturate((x - a) / (b - a));
return x*x*x*(x*(x * 6 - 15) + 10);
}

//Conversion matrices
vec3 RGBtoXYZ(vec3 RGB)
{
const mat3 RGBtoXYZ = mat3(
0.6068909, 0.1735011, 0.2003480,
0.2989164, 0.5865990, 0.1144845,
0.0000000, 0.0660957, 1.1162243);

return RGBtoXYZ*RGB;
}

vec3 XYZtoRGB(vec3 XYZ)
{
const mat3 XYZtoRGB = mat3(
1.9099961, -0.5324542, -0.2882091,
-0.9846663, 1.9991710, -0.0283082,
0.0583056, -0.1183781, 0.8975535);

return XYZtoRGB*XYZ;
}

vec3 XYZtoSRGB(vec3 XYZ)
{
const mat3 XYZtoSRGB = mat3(
3.2404542, -1.5371385, -0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434, -0.2040259, 1.0572252);

return XYZtoSRGB*XYZ;
}

vec3 RGBtoYUV(vec3 RGB)
{
const mat3 RGBtoYUV = mat3(
0.2126, 0.7152, 0.0722,
-0.09991, -0.33609, 0.436,
0.615, -0.55861, -0.05639);

return RGBtoYUV*RGB;
}

vec3 YUVtoRGB(vec3 YUV)
{
const mat3 YUVtoRGB = mat3(
1.000, 0.000, 1.28033,
1.000, -0.21482, -0.38059,
1.000, 2.12798, 0.000);

return YUVtoRGB*YUV;
}

vec3 XYZtoYxy(vec3 XYZ)
{
float w = (XYZ.r + XYZ.g + XYZ.b);
vec3 Yxy;

Yxy.r = XYZ.g;
Yxy.g = XYZ.r / w;
Yxy.b = XYZ.g / w;

return Yxy;
}

vec3 YxytoXYZ(vec3 Yxy)
{
vec3 XYZ;
XYZ.g = Yxy.r;
XYZ.r = Yxy.r * Yxy.g / Yxy.b;
XYZ.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;

return XYZ;
}

/*------------------------------------------------------------------------------
[FXAA CODE SECTION]
Code from http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/
Credit to original Author
------------------------------------------------------------------------------*/
#if USE_FXAA == 1
float xbrthreshold = 0.020;
vec2 rcpFrame = OGLInvSize;
vec3 FXAA(sampler2D OGLTexture, vec2 texcoord)
{
float FXAA_SPAN_MAX = 8.0;                     //[4.0 t0 8.0]             
float FXAA_REDUCE_MUL = (1.0 / FXAA_SPAN_MAX); //[Default]
float FXAA_REDUCE_MIN = (1.0 / 128.0);         //[Default]
float FXAA_SUBPIX_SHIFT = (1.0 / 4.0);         //[Default]

vec4 posPos = vec4(texcoord.xy, texcoord.xy - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT)));

/*---------------------------------------------------------*/
vec3 rgbNW = texture2D(OGLTexture, posPos.zw, 0.0).rgb;
vec3 rgbNE = texture2D(OGLTexture, posPos.zw + vec2(1., 0.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbSW = texture2D(OGLTexture, posPos.zw + vec2(0., 1.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbSE = texture2D(OGLTexture, posPos.zw + vec2(1., 1.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbM = texture2D(OGLTexture, texcoord.xy, 0.0).rgb;
/*---------------------------------------------------------*/
//vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = AvgLuminance(rgbNW);
float lumaNE = AvgLuminance(rgbNE);
float lumaSW = AvgLuminance(rgbSW);
float lumaSE = AvgLuminance(rgbSE);
float lumaM = AvgLuminance(rgbM);
/*---------------------------------------------------------*/
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));

float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
/*---------------------------------------------------------*/
vec2 dir;

dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));

dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
/*---------------------------------------------------------*/
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);

float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);

dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * rcpFrame.xy;
/*--------------------------------------------------------*/

vec3 rgbA = (1.0 / 2.0) * (texture2D(OGLTexture, texcoord.xy + dir * (1.0 / 3.0 - 0.5)).rgb + texture2D(OGLTexture, texcoord.xy + dir * (2.0 / 3.0 - 0.5)).rgb);
vec3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (texture2D(OGLTexture, texcoord.xy + dir * (0.0 / 3.0 - 0.5)).rgb + texture2D(OGLTexture, texcoord.xy + dir * (3.0 / 3.0 - 0.5)).rgb);

float lumaB = AvgLuminance(rgbB);

return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? rgbA.rgb : rgbB.rgb;
}

//Hyllian's xBR Level 2 shader
//Copyright(C) 2011 / 2014 Hyllian / Jararaca - [email protected]
//Credit to Hyllian
float x_Width = texture_width;
float y_Height = texture_height;

float x_coef = texel_size_x;
float y_coef = texel_size_y;

float coef = 2.0;
vec3 rgbw = vec3(14.352, 28.176, 5.472);

float x = 0.5 * (1.0 / x_Width);
float y = 0.5 * (1.0 / y_Height);

//vec2 dx = vec2(x, 0.0);
//vec2 dy = vec2(0.0, y);
vec2 dx = vec2(0.0009765625, 0.0);//vec2(x, 0.0);//
vec2 dy = vec2(0.0, 0.001953125);//vec2(0.0, y);//
vec2 x2 = vec2(0.001953125, 0.0);//vec2(y, 0);//
vec2 y2 = vec2(0.0, 0.00390625);//vec2( 0.0 , y*2.0 );//
vec4 xy = vec4(0.0009765625, 0.001953125, -0.0009765625, -0.001953125);//vec4( x, y,-x,-y);//
vec4 zw = vec4(0.001953125, 0.001953125, -0.001953125, -0.00390625);//vec4( y , y,-y ,-(y*2.0));//
vec4 wz = vec4(0.0009765625, 0.00390625, -0.0009765625, -0.00390625);  //vec4( x, y*2.0 ,-x,-(y*2.0));//

vec4 df(vec4 A, vec4 B)
{
return abs(A - B);
}

vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h)
{
return (df(a, b) + df(a, c) + df(d, e) + df(d, f) + 4.0*df(g, h));
}


vec3 xBR(sampler2D OGLTexture, vec2 texcoord)
{
vec4 edr, edr_left, edr_up; bvec4 px; // px = pixel, edr = edge detection rule
vec4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
bvec4 nc; // new_color
vec4 fx, fx_left, fx_up; // inequations of straight lines.

vec2 fp = fract(texcoord.xy*vec2(x_Width, y_Height));
vec2 vTex = texcoord.xy - fp*vec2(0.0009765625*x_coef, 0.001953125*y_coef);//vec2(x, y);

vec3 A = texture2D(OGLTexture, vTex + xy.zw).rgb;
vec3 B = texture2D(OGLTexture, vTex - dy).rgb;
vec3 C = texture2D(OGLTexture, vTex + xy.xw).rgb;
vec3 D = texture2D(OGLTexture, vTex - dx).rgb;
vec3 E = texture2D(OGLTexture, vTex).rgb;
vec3 F = texture2D(OGLTexture, vTex + dx).rgb;
vec3 G = texture2D(OGLTexture, vTex + xy.zy).rgb;
vec3 H = texture2D(OGLTexture, vTex + dy).rgb;
vec3 I = texture2D(OGLTexture, vTex + xy.xy).rgb;
vec3 A1 = texture2D(OGLTexture, vTex + wz.zw).rgb;
vec3 C1 = texture2D(OGLTexture, vTex + wz.xw).rgb;
vec3 A0 = texture2D(OGLTexture, vTex + zw.zw).rgb;
vec3 G0 = texture2D(OGLTexture, vTex + zw.zy).rgb;
vec3 C4 = texture2D(OGLTexture, vTex + zw.xw).rgb;
vec3 I4 = texture2D(OGLTexture, vTex + zw.xy).rgb;
vec3 G5 = texture2D(OGLTexture, vTex + wz.zy).rgb;
vec3 I5 = texture2D(OGLTexture, vTex + wz.xy).rgb;
vec3 B1 = texture2D(OGLTexture, vTex - y2).rgb;
vec3 D0 = texture2D(OGLTexture, vTex - x2).rgb;
vec3 H5 = texture2D(OGLTexture, vTex + y2).rgb;
vec3 F4 = texture2D(OGLTexture, vTex + x2).rgb;

vec4 b = vec4(dot(B, rgbw), dot(D, rgbw), dot(H, rgbw), dot(F, rgbw));
vec4 c = vec4(dot(C, rgbw), dot(A, rgbw), dot(G, rgbw), dot(I, rgbw));
vec4 d = b.yzwx;
vec4 e = vec4(dot(E, rgbw));
vec4 f = b.wxyz;
vec4 g = c.zwxy;
vec4 h = b.zwxy;
vec4 i = c.wxyz;
vec4 i4 = vec4(dot(I4, rgbw), dot(C1, rgbw), dot(A0, rgbw), dot(G5, rgbw));
vec4 i5 = vec4(dot(I5, rgbw), dot(C4, rgbw), dot(A1, rgbw), dot(G0, rgbw));
vec4 h5 = vec4(dot(H5, rgbw), dot(F4, rgbw), dot(B1, rgbw), dot(D0, rgbw));
vec4 f4 = h5.yzwx;

vec4 Ao = vec4(1.0, -1.0, -1.0, 1.0);
vec4 Bo = vec4(1.0, 1.0, -1.0, -1.0);
vec4 Co = vec4(1.5, 0.5, -0.5, 0.5);
vec4 Ax = vec4(1.0, -1.0, -1.0, 1.0);
vec4 Bx = vec4(0.5, 2.0, -0.5, -2.0);
vec4 Cx = vec4(1.0, 1.0, -0.5, 0.0);
vec4 Ay = vec4(1.0, -1.0, -1.0, 1.0);
vec4 By = vec4(2.0, 0.5, -2.0, -0.5);
vec4 Cy = vec4(2.0, 0.0, -1.0, 0.5);
vec4 Ci = vec4(0.25, 0.25, 0.25, 0.25);

// These inequations define the line below which interpolation occurs.
fx = vec4(greaterThan(Ao*fp.y + Bo*fp.x, Co));
fx_left = vec4(greaterThan(Ax*fp.y + Bx*fp.x, Cx));
fx_up = vec4(greaterThan(Ay*fp.y + By*fp.x, Cy));

interp_restriction_lv1 = vec4(notEqual(e, f))*vec4(notEqual(e, h));
interp_restriction_lv2_left = vec4(notEqual(e, g))*vec4(notEqual(d, g));
interp_restriction_lv2_up = vec4(notEqual(e, c))*vec4(notEqual(b, c));

edr = vec4(lessThan(weighted_distance(e, c, g, i, h5, f4, h, f), weighted_distance(h, d, i5, f, i4, b, e, i)))*interp_restriction_lv1;
edr_left = vec4(lessThanEqual(coef*df(f, g), df(h, c)))*interp_restriction_lv2_left;
edr_up = vec4(greaterThanEqual(df(f, g), coef*df(h, c)))*interp_restriction_lv2_up;

nc = bvec4(edr*(max(max(fx, edr_left*fx_left), edr_up*fx_up)));

px = lessThanEqual(df(e, f), df(e, h));

vec3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;

return res;
}

float diff2D(vec2 coord)
{
vec3 dt = vec3(1.0, 1.0, 1.0);

vec3 c00 = texture2D(OGLTexture, coord + 0.25*(-dx - dy)).xyz;
vec3 c20 = texture2D(OGLTexture, coord + 0.25*(dx - dy)).xyz;
vec3 c02 = texture2D(OGLTexture, coord + 0.25*(-dx + dy)).xyz;
vec3 c22 = texture2D(OGLTexture, coord + 0.25*(dx + dy)).xyz;

vec3 mn = min(min(c00, c20), min(c02, c22));
vec3 mx = max(max(c00, c20), max(c02, c22));

return dot(mx - mn, dt);
}

vec4 FXAAPass(vec4 color, vec2 texcoord)
{
vec2 fp = fract(texcoord * OGLSize);
vec2 vTex = texcoord - fp * OGLInvSize + 0.5 * OGLInvSize;
vec2 locator = sign(fp - vec2(0.5000000001, 0.5000000001));

float maxdiff = max(max(diff2D(vTex + locator*dx), diff2D(vTex + locator*dy)), diff2D(vTex));

if (maxdiff <= xbrthreshold) { color.rgb = xBR(OGLTexture, texcoord); }
else { color.rgb = FXAA(OGLTexture, texcoord); }

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[GAMMA CORRECTION CODE SECTION]
------------------------------------------------------------------------------*/

vec3 EncodeGamma(vec3 color, float gamma)
{
color = saturate(color);
color.r = (color.r <= 0.0404482362771082) ? color.r / 12.92 : pow((color.r + 0.055) / 1.055, gamma);
color.g = (color.g <= 0.0404482362771082) ? color.g / 12.92 : pow((color.g + 0.055) / 1.055, gamma);
color.b = (color.b <= 0.0404482362771082) ? color.b / 12.92 : pow((color.b + 0.055) / 1.055, gamma);

return color;
}

vec3 DecodeGamma(vec3 color, float gamma)
{
color = saturate(color);
color.r = (color.r <= 0.00313066844250063) ? color.r * 12.92 : 1.055 * pow(color.r, 1.0 / gamma) - 0.055;
color.g = (color.g <= 0.00313066844250063) ? color.g * 12.92 : 1.055 * pow(color.g, 1.0 / gamma) - 0.055;
color.b = (color.b <= 0.00313066844250063) ? color.b * 12.92 : 1.055 * pow(color.b, 1.0 / gamma) - 0.055;

return color;
}

#if GAMMA_CORRECTION == 1
vec4 GammaPass(vec4 color, vec2 texcoord)
{
const float GammaConst = 2.233333;
color.rgb = EncodeGamma(color.rgb, GammaConst);
color.rgb = DecodeGamma(color.rgb, float(Gamma));
color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[PIXEL VIBRANCE CODE SECTION]
------------------------------------------------------------------------------*/

#if PIXEL_VIBRANCE == 1
vec4 VibrancePass(vec4 color, vec2 texcoord)
{
float vib = Vibrance;

float lum = AvgLuminance(color.rgb);
vec3 luma = vec3(lum, lum, lum);

float colorMax = max(color.r, max(color.g, color.b));
float colorMin = min(color.r, min(color.g, color.b));

float colorSaturation = colorMax - colorMin;
vec3 colorCoeff = vec3(RedVibrance * vib, GreenVibrance * vib, BlueVibrance * vib);

color.rgb = lerp(luma, color.rgb, (1.0 + (colorCoeff * (1.0 - (sign(colorCoeff) * colorSaturation)))));
color.a = AvgLuminance(color.rgb);

return saturate(color); //Debug: return colorSaturation.xxxx;
}
#endif

/*------------------------------------------------------------------------------
[BLENDED BLOOM CODE SECTION]
------------------------------------------------------------------------------*/

#if BLENDED_BLOOM == 1
vec3 BlendAddLight(vec3 bloom, vec3 blend)
{
return saturate(bloom + blend);
}

vec3 BlendScreen(vec3 bloom, vec3 blend)
{
return (bloom + blend) - (bloom * blend);
}

vec3 BlendGlow(vec3 bloom, vec3 blend)
{
float glow = AvgLuminance(bloom);
return lerp((bloom + blend) - (bloom * blend), (blend + blend) - (blend * blend), glow);
}

vec3 BlendAddGlow(vec3 bloom, vec3 blend)
{
float addglow = smootherstep(0.0, 1.0, AvgLuminance(bloom));
return lerp(saturate(bloom + blend), (blend + blend) - (blend * blend), addglow);
}

vec3 BlendLuma(vec3 bloom, vec3 blend)
{
float lumavg = smootherstep(0.0, 1.0, AvgLuminance(bloom + blend));
return lerp((bloom * blend), (1.0 - ((1.0 - bloom) * (1.0 - blend))), lumavg);
}

vec3 BlendOverlay(vec3 bloom, vec3 blend)
{
vec3 overlay = step(0.5, bloom);
return lerp((bloom * blend * 2.0), (1.0 - (2.0 *(1.0 - bloom) * (1.0 - blend))), overlay);
}

vec3 BloomCorrection(vec3 color)
{
vec3 bloom = color;

bloom.r = 2.0 / 3.0 * (1.0 - (bloom.r * bloom.r));
bloom.g = 2.0 / 3.0 * (1.0 - (bloom.g * bloom.g));
bloom.b = 2.0 / 3.0 * (1.0 - (bloom.b * bloom.b));

bloom.r = saturate(color.r + float(BloomReds) * bloom.r);
bloom.g = saturate(color.g + float(BloomGreens) * bloom.g);
bloom.b = saturate(color.b + float(BloomBlues) * bloom.b);
color = bloom;
return color;
}

vec4 DefocusFilter(sampler2D OGLTexture, vec2 texcoord, vec2 defocus)
{
defocus = clamp(defocus, 1.0, 1.5);
vec2 texel = vec2(texel_size_x, texel_size_y) * defocus;

vec4 sampleA = texture2D(OGLTexture, texcoord + vec2(0.5, 0.5) * texel);
vec4 sampleB = texture2D(OGLTexture, texcoord + vec2(-0.5, 0.5) * texel);
vec4 sampleC = texture2D(OGLTexture, texcoord + vec2(0.5, -0.5) * texel);
vec4 sampleD = texture2D(OGLTexture, texcoord + vec2(-0.5, -0.5) * texel);

float fx = frac(texcoord.x * texture_width);
float fy = frac(texcoord.y * texture_height);

vec4 interpolateA = lerp(sampleA, sampleB, fx);
vec4 interpolateB = lerp(sampleC, sampleD, fx);
return lerp(interpolateA, interpolateB, fy);
}

vec4 BloomPass(vec4 color, vec2 texcoord)
{
float anflare = 4.0;
float width = BloomWidth;

vec2 defocus = vec2(BloomDefocus, BloomDefocus);
vec4 bloom = DefocusFilter(OGLTexture, texcoord, defocus);

vec2 dx = vec2(texel_size_x * width, 0.0);
vec2 dy = vec2(0.0, texel_size_y * width);

vec2 mdx = vec2(dx.x * defocus.x, 0.0);
vec2 mdy = vec2(0.0, dy.y * defocus.y);

vec4 blend = bloom * 0.22520613262190495;

blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord - mdx + mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - dx + mdy);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord + mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + dx + mdy);
blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord + mdx + mdy);

blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - mdx + dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord - dx + dy);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord + dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord + dx + dy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + mdx + dy);

blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord - mdx);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord - dx);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord + dx);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord + mdx);

blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - mdx - dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord - dx - dy);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord - dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord + dx - dy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + mdx - dy);

blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord - mdx - mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - dx - mdy);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord - mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + dx - mdy);
blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord + mdx - mdy);
blend = lerp(color, blend, float(BlendStrength));

bloom.xyz = BloomType(bloom.xyz, blend.xyz);
bloom.xyz = BloomCorrection(bloom.xyz);

color.w = AvgLuminance(color.xyz);
bloom.w = AvgLuminance(bloom.xyz);
bloom.w *= anflare;

color = lerp(color, bloom, float(BloomStrength));

return color;
}
#endif

/*------------------------------------------------------------------------------
[SCENE TONE MAPPING CODE SECTION]
------------------------------------------------------------------------------*/

#if SCENE_TONEMAPPING == 1

vec3 ScaleLuminance(vec3 x)
{
float W = 1.02; // WhitePoint Scale
float L = 0.16; // Luminance Scale
float C = 1.02; // Compression Scale

float N = clamp(0.82 + ToneAmount, 1.0, 2.0);
float K = (N - L * C) / C;

vec3 tone = L * C + (1.0 - L * C) * (1.0 + K * (x - L) / ((W - L) * (W - L))) * (x - L) / (x - L + K);

vec3 color;
color.r = (x.r > L) ? tone.r : C * x.r;
color.g = (x.g > L) ? tone.g : C * x.g;
color.b = (x.b > L) ? tone.b : C * x.b;

return color;
}

vec3 TmMask(vec3 color)
{
vec3 tone = color;

float highTone = 6.2;
float greyTone = 0.4;
float midTone = 1.62;
float lowTone = 0.06;

tone.r = (tone.r * (highTone * tone.r + greyTone)) / (tone.r * (highTone * tone.r + midTone) + lowTone);
tone.g = (tone.g * (highTone * tone.g + greyTone)) / (tone.g * (highTone * tone.g + midTone) + lowTone);
tone.b = (tone.b * (highTone * tone.b + greyTone)) / (tone.b * (highTone * tone.b + midTone) + lowTone);

const float gamma = 2.42;
tone = EncodeGamma(tone, gamma);

color = lerp(color, tone, float(MaskStrength));

return color;
}

vec3 TmCurve(vec3 color)
{
vec3 T = color;

float tnamn = ToneAmount;
float blevel = length(T);
float bmask = pow(blevel, 0.02);

float A = 0.100; float B = 0.300;
float C = 0.100; float D = tnamn;
float E = 0.020; float F = 0.300;

float W = 1.000;

T.r = ((T.r*(A*T.r + C*B) + D*E) / (T.r*(A*T.r + B) + D*F)) - E / F;
T.g = ((T.g*(A*T.g + C*B) + D*E) / (T.g*(A*T.g + B) + D*F)) - E / F;
T.b = ((T.b*(A*T.b + C*B) + D*E) / (T.b*(A*T.b + B) + D*F)) - E / F;

float denom = ((W*(A*W + C*B) + D*E) / (W*(A*W + B) + D*F)) - E / F;

vec3 black = vec3(bmask, bmask, bmask);
vec3 white = vec3(denom, denom, denom);

T = T / white;
T = T * black;

color = saturate(T);

return color;
}

vec4 TonemapPass(vec4 color, vec2 texcoord)
{
float L = Luminance;

vec3 tonemap = color.rgb;
vec3 luma = vec3(L, L, L);

float blackLevel = length(tonemap);
tonemap = ScaleLuminance(tonemap);

float luminanceAverage = AvgLuminance(luma);

if (TonemapMask == 1) { tonemap = TmMask(tonemap); }
if (TonemapType == 1) { tonemap = TmCurve(tonemap); }

// RGB -> XYZ conversion
vec3 XYZ = RGBtoXYZ(tonemap);

// XYZ -> Yxy conversion
vec3 Yxy;

Yxy.r = XYZ.g;                                  // copy luminance Y
Yxy.g = XYZ.r / (XYZ.r + XYZ.g + XYZ.b);        // x = X / (X + Y + Z)
Yxy.b = XYZ.g / (XYZ.r + XYZ.g + XYZ.b);        // y = Y / (X + Y + Z)

// (Wt) Tone mapped scaling of the initial wp before input modifiers
float Wt = saturate(Yxy.r / AvgLuminance(XYZ));

if (TonemapType == 2) { Yxy.r = TmCurve(Yxy).r; }

// (Lp) Map average luminance to the middlegrey zone by scaling pixel luminance
float Lp = Yxy.r * float(Exposure) / (luminanceAverage + Epsilon);

// (Wp) White point calculated, based on the toned white, and input modifier
float Wp = dot(abs(Wt), float(WhitePoint));

// (Ld) Scale all luminance within a displayable range of 0 to 1
Yxy.r = (Lp * (1.0 + Lp / (Wp * Wp))) / (1.0 + Lp);

// Yxy -> XYZ conversion
XYZ.r = Yxy.r * Yxy.g / Yxy.b;                  // X = Y * x / y
XYZ.g = Yxy.r;                                  // copy luminance Y
XYZ.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;  // Z = Y * (1-x-y) / y

if (TonemapType == 3) { XYZ = TmCurve(XYZ); }

// XYZ -> RGB conversion
tonemap = XYZtoRGB(XYZ);

float shadowmask = pow(saturate(blackLevel), float(BlackLevels));
tonemap = tonemap * vec3(shadowmask, shadowmask, shadowmask);

color.rgb = tonemap;

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[COLOR CORRECTION CODE SECTION]
------------------------------------------------------------------------------*/

// Converting pure hue to RGB
vec3 HUEtoRGB(float H)
{
float R = abs(H * 6.0 - 3.0) - 1.0;
float G = 2.0 - abs(H * 6.0 - 2.0);
float B = 2.0 - abs(H * 6.0 - 4.0);

return saturate(vec3(R, G, B));
}

// Converting RGB to hue/chroma/value
vec3 RGBtoHCV(vec3 RGB)
{
vec4 BG = vec4(RGB.bg, -1.0, 2.0 / 3.0);
vec4 GB = vec4(RGB.gb, 0.0, -1.0 / 3.0);

vec4 P = (RGB.g < RGB.b) ? BG : GB;

vec4 XY = vec4(P.xyw, RGB.r);
vec4 YZ = vec4(RGB.r, P.yzx);

vec4 Q = (RGB.r < P.x) ? XY : YZ;

float C = Q.x - min(Q.w, Q.y);
float H = abs((Q.w - Q.y) / (6.0 * C + Epsilon) + Q.z);

return vec3(H, C, Q.x);
}

// Converting RGB to HSV
vec3 RGBtoHSV(vec3 RGB)
{
vec3 HCV = RGBtoHCV(RGB);
float S = HCV.y / (HCV.z + Epsilon);

return vec3(HCV.x, S, HCV.z);
}

// Converting HSV to RGB
vec3 HSVtoRGB(vec3 HSV)
{
vec3 RGB = HUEtoRGB(HSV.x);
return ((RGB - 1.0) * HSV.y + 1.0) * HSV.z;
}

#if COLOR_CORRECTION == 1
// Pre correction color mask
vec3 PreCorrection(vec3 color)
{
vec3 RGB = color;

RGB.r = 2.0 / 3.0 * (1.0 - (RGB.r * RGB.r));
RGB.g = 2.0 / 3.0 * (1.0 - (RGB.g * RGB.g));
RGB.b = 2.0 / 3.0 * (1.0 - (RGB.b * RGB.b));

RGB.r = saturate(color.r + (float(ChannelR) / 200.0) * RGB.r);
RGB.g = saturate(color.g + (float(ChannelG) / 200.0) * RGB.g);
RGB.b = saturate(color.b + (float(ChannelB) / 200.0) * RGB.b);

color = saturate(RGB);

return color;
}

vec3 ColorCorrection(vec3 color)
{
float X = 1.0 / (1.0 + exp(float(ChannelR) / 2.0));
float Y = 1.0 / (1.0 + exp(float(ChannelG) / 2.0));
float Z = 1.0 / (1.0 + exp(float(ChannelB) / 2.0));

color.r = (1.0 / (1.0 + exp(float(-ChannelR) * (color.r - 0.5))) - X) / (1.0 - 2.0 * X);
color.g = (1.0 / (1.0 + exp(float(-ChannelG) * (color.g - 0.5))) - Y) / (1.0 - 2.0 * Y);
color.b = (1.0 / (1.0 + exp(float(-ChannelB) * (color.b - 0.5))) - Z) / (1.0 - 2.0 * Z);

return saturate(color);
}

vec4 CorrectionPass(vec4 color, vec2 texcoord)
{
vec3 colorspace = PreCorrection(color.rgb);

#if CorrectionPalette == 1
colorspace = ColorCorrection(colorspace);

#elif CorrectionPalette == 2
vec3 XYZ = RGBtoXYZ(colorspace);
vec3 Yxy = XYZtoYxy(XYZ);

Yxy = ColorCorrection(Yxy);
XYZ = YxytoXYZ(Yxy);
colorspace = XYZtoRGB(XYZ);

#elif CorrectionPalette == 3
vec3 XYZ = RGBtoXYZ(colorspace);
vec3 Yxy = XYZtoYxy(XYZ);
XYZ = YxytoXYZ(Yxy);
XYZ = ColorCorrection(XYZ);
colorspace = XYZtoRGB(XYZ);

#elif CorrectionPalette == 4
vec3 hsv = RGBtoHSV(colorspace);
hsv = ColorCorrection(hsv);
colorspace = HSVtoRGB(hsv);

#elif CorrectionPalette == 5
vec3 yuv = RGBtoYUV(colorspace);
yuv = ColorCorrection(yuv);
colorspace = YUVtoRGB(yuv);
#endif

color.rgb = lerp(color.rgb, colorspace, float(PaletteStrength));

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[S-CURVE CONTRAST CODE SECTION]
------------------------------------------------------------------------------*/

#if USE_CURVES == 1

vec4 CurvesPass(vec4 color, vec2 texcoord)
{
float Curves_contrast_blend = Curves_contrast;


/*-----------------------------------------------------------.
/               Separation of Luma and Chroma                 /
'-----------------------------------------------------------*/

// -- Calculate Luma and Chroma if needed --
#if Curves_mode != 2

//calculate luma (grey)
float luma = dot(lumCoeff, color.rgb);

//calculate chroma
vec3 chroma = color.rgb - luma;
#endif

// -- Which value to put through the contrast formula? --
// I name it x because makes it easier to copy-paste to Graphtoy or Wolfram Alpha or another graphing program
#if Curves_mode == 2
vec3 x = color.rgb; //if the curve should be applied to both Luma and Chroma
#elif Curves_mode == 1
vec3 x = chroma; //if the curve should be applied to Chroma
x = x * 0.5 + 0.5; //adjust range of Chroma from -1 -> 1 to 0 -> 1
#else // Curves_mode == 0
float x = luma; //if the curve should be applied to Luma
#endif

    // Contrast formulas
// -- Curve 1 --
#if Curves_formula == 1
x = sin(PI * 0.5 * x); // Sin - 721 amd fps, +vign 536 nv
x *= x;

//x = 0.5 - 0.5*cos(PI*x);
//x = 0.5 * -sin(PI * -x + (PI*0.5)) + 0.5;
#endif

// -- Curve 2 --
#if Curves_formula == 2
x = x - 0.5;
x = (x / (0.5 + abs(x))) + 0.5;

//x = ( (x - 0.5) / (0.5 + abs(x-0.5)) ) + 0.5;
#endif

// -- Curve 3 --
#if Curves_formula == 3
//x = smoothstep(0.0,1.0,x); //smoothstep
x = x*x*(3.0 - 2.0*x); //faster smoothstep alternative - 776 amd fps, +vign 536 nv
//x = x - 2.0 * (x - 1.0) * x* (x- 0.5);  //2.0 is contrast. Range is 0.0 to 2.0
#endif

// -- Curve 4 --
#if Curves_formula == 4
x = (1.0524 * exp(6.0 * x) - 1.05248) / (20.0855 + exp(6.0 * x)); //exp formula
#endif

// -- Curve 5 --
#if Curves_formula == 5
//x = 0.5 * (x + 3.0 * x * x - 2.0 * x * x * x); //a simplified catmull-rom (0,0,1,1) - btw smoothstep can also be expressed as a simplified catmull-rom using (1,0,1,0)
//x = (0.5 * x) + (1.5 -x) * x*x; //estrin form - faster version
x = x * (x * (1.5 - x) + 0.5); //horner form - fastest version

Curves_contrast_blend = Curves_contrast * 2.0; //I multiply by two to give it a strength closer to the other curves.
#endif

// -- Curve 6 --
#if Curves_formula == 6
x = x*x*x*(x*(x*6.0 - 15.0) + 10.0); //Perlins smootherstep
#endif

// -- Curve 7 --
#if Curves_formula == 7
//x = ((x-0.5) / ((0.5/(4.0/3.0)) + abs((x-0.5)*1.25))) + 0.5;
x = x - 0.5;
x = x / ((abs(x)*1.25) + 0.375) + 0.5;
//x = ( (x-0.5) / ((abs(x-0.5)*1.25) + (0.5/(4.0/3.0))) ) + 0.5;
#endif

// -- Curve 8 --
#if Curves_formula == 8
x = (x * (x * (x * (x * (x * (x * (1.6 * x - 7.2) + 10.8) - 4.2) - 3.6) + 2.7) - 1.8) + 2.7) * x * x; //Techicolor Cinestyle - almost identical to curve 1
#endif

// -- Curve 9 --
#if Curves_formula == 9
x = -0.5 * (x*2.0 - 1.0) * (abs(x*2.0 - 1.0) - 2.0) + 0.5; //parabola
#endif

// -- Curve 10 --
#if Curves_formula == 10 //Half-circles

#if Curves_mode == 0
float xstep = step(x, 0.5);
float xstep_shift = (xstep - 0.5);
float shifted_x = x + xstep_shift;
#else
vec3 xstep = step(x, 0.5);
vec3 xstep_shift = (xstep - 0.5);
vec3 shifted_x = x + xstep_shift;

#endif

x = abs(xstep - sqrt(-shifted_x * shifted_x + shifted_x)) - xstep_shift;

//x = abs(step(x,0.5)-sqrt(-(x+step(x,0.5)-0.5)*(x+step(x,0.5)-0.5)+(x+step(x,0.5)-0.5)))-(step(x,0.5)-0.5); //single line version of the above

//x = 0.5 + (sign(x-0.5)) * sqrt(0.25-(x-trunc(x*2))*(x-trunc(x*2))); //worse

/* // if/else - even worse
if (x-0.5)
x = 0.5-sqrt(0.25-x*x);
else
x = 0.5+sqrt(0.25-(x-1)*(x-1));
*/

//x = (abs(step(0.5,x)-clamp( 1-sqrt(1-abs(step(0.5,x)- frac(x*2%1)) * abs(step(0.5,x)- frac(x*2%1))),0 ,1))+ step(0.5,x) )*0.5; //worst so far

//TODO: Check if I could use an abs split instead of step. It might be more efficient

Curves_contrast_blend = Curves_contrast * 0.5; //I divide by two to give it a strength closer to the other curves.
#endif

// -- Curve 11 --
#if Curves_formula == 11 //Cubic catmull
float a = 1.00; //control point 1
float b = 0.00; //start point
float c = 1.00; //endpoint
float d = 0.20; //control point 2
x = 0.5 * ((-a + 3 * b - 3 * c + d)*x*x*x + (2 * a - 5 * b + 4 * c - d)*x*x + (-a + c)*x + 2 * b); //A customizable cubic catmull-rom spline
#endif

// -- Curve 12 --
#if Curves_formula == 12 //Cubic Bezier spline
float a = 0.00; //start point
float b = 0.00; //control point 1
float c = 1.00; //control point 2
float d = 1.00; //endpoint

float r = (1 - x);
float r2 = r*r;
float r3 = r2 * r;
float x2 = x*x;
float x3 = x2*x;
//x = dot(float4(a,b,c,d),float4(r3,3*r2*x,3*r*x2,x3));

//x = a * r*r*r + r * (3 * b * r * x + 3 * c * x*x) + d * x*x*x;
//x = a*(1-x)*(1-x)*(1-x) +(1-x) * (3*b * (1-x) * x + 3 * c * x*x) + d * x*x*x;
x = a*(1 - x)*(1 - x)*(1 - x) + 3 * b*(1 - x)*(1 - x)*x + 3 * c*(1 - x)*x*x + d*x*x*x;
#endif

// -- Curve 13 --
#if Curves_formula == 13 //Cubic Bezier spline - alternative implementation.
vec3 a = vec3(0.00, 0.00, 0.00); //start point
vec3 b = vec3(0.25, 0.15, 0.85); //control point 1
vec3 c = vec3(0.75, 0.85, 0.15); //control point 2
vec3 d = vec3(1.00, 1.00, 1.00); //endpoint

vec3 ab = lerp(a, b, x);           // point between a and b
vec3 bc = lerp(b, c, x);           // point between b and c
vec3 cd = lerp(c, d, x);           // point between c and d
vec3 abbc = lerp(ab, bc, x);       // point between ab and bc
vec3 bccd = lerp(bc, cd, x);       // point between bc and cd
vec3 dest = lerp(abbc, bccd, x);   // point on the bezier-curve
x = dest;
#endif

// -- Curve 14 --
#if Curves_formula == 14
x = 1.0 / (1.0 + exp(-(x * 10.0 - 5.0))); //alternative exp formula
#endif

   //Joining of Luma and Chroma                 
#if Curves_mode == 2 //Both Luma and Chroma
vec3 col = x;  //if the curve should be applied to both Luma and Chroma
color.rgb = lerp(color.rgb, col, Curves_contrast_blend); //Blend by Curves_contrast

#elif Curves_mode == 1 //Only Chroma
x = x * 2.0 - 1.0; //adjust the Chroma range back to -1 -> 1
vec3 col = luma + x; //Luma + Chroma
color.rgb = lerp(color.rgb, col, Curves_contrast_blend); //Blend by Curves_contrast

#else // Curves_mode == 0 //Only Luma
x = lerp(luma, x, Curves_contrast_blend); //Blend by Curves_contrast
color.rgb = x + chroma; //Luma + Chroma
#endif
//Return the result
color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif

/*------------------------------------------------------------------------------
[CROSS PROCESSING CODE SECTION]
------------------------------------------------------------------------------*/
#if CROSS_PROCESSING == 1

vec3 CrossShift(vec3 color)
{
vec3 cross;

vec2 CrossMatrix[3] = vec2[](
vec2(0.960, 0.040 * color.x),
vec2(0.980, 0.020 * color.y),
vec2(0.970, 0.030 * color.z));

cross.x = float(RedShift) * CrossMatrix[0].x + CrossMatrix[0].y;
cross.y = float(GreenShift) * CrossMatrix[1].x + CrossMatrix[1].y;
cross.z = float(BlueShift) * CrossMatrix[2].x + CrossMatrix[2].y;

float lum = AvgLuminance(color);
vec3 black = vec3(0.0, 0.0, 0.0);
vec3 white = vec3(1.0, 1.0, 1.0);

cross = lerp(black, cross, saturate(lum * 2.0));
cross = lerp(cross, white, saturate(lum - 0.5) * 2.0);
color = lerp(color, cross, saturate(lum * float(ShiftRatio)));

return color;
}

vec4 CrossPass(vec4 color, vec2 texcoord)
{
#if FilmicProcess == 1
color.rgb = CrossShift(color.rgb);

#elif FilmicProcess == 2
vec3 XYZ = RGBtoXYZ(color.rgb);
vec3 Yxy = XYZtoYxy(XYZ);

Yxy = CrossShift(Yxy);
XYZ = YxytoXYZ(Yxy);

color.rgb = XYZtoRGB(XYZ);

#elif FilmicProcess == 3
vec3 XYZ = RGBtoXYZ(color.rgb);
vec3 Yxy = XYZtoYxy(XYZ);

XYZ = YxytoXYZ(Yxy);
XYZ = CrossShift(XYZ);

color.rgb = XYZtoRGB(XYZ);
#endif

color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif

/*------------------------------------------------------------------------------
[COLOR GRADING CODE SECTION]
------------------------------------------------------------------------------*/

#if COLOR_GRADING == 1
float RGBCVtoHUE(vec3 RGB, float C, float V)
{
vec3 Delta = (V - RGB) / C;

Delta.rgb -= Delta.brg;
Delta.rgb += vec3(2.0, 4.0, 6.0);
Delta.brg = step(V, RGB) * Delta.brg;

float H;
H = max(Delta.r, max(Delta.g, Delta.b));
return frac(H / 6);
}

vec3 HSVComplement(vec3 HSV)
{
vec3 complement = HSV;
complement.x -= 0.5;

if (complement.x < 0.0) {
complement.x += 1.0;
}
return(complement);
}

float HueLerp(float h1, float h2, float v)
{
float d = abs(h1 - h2);

if (d <= 0.5)
{
return lerp(h1, h2, v);
}
else if (h1 < h2)
{
return frac(lerp((h1 + 1.0), h2, v));
}
else
{
return frac(lerp(h1, (h2 + 1.0), v));
}
}

vec4 ColorGradingPass(vec4 color, vec2 texcoord)
{
vec3 guide = vec3(RedGrading, GreenGrading, BlueGrading);

float amount = GradingStrength;
float correlation = Correlation;
float concentration = 2.00;

vec3 colorHSV = RGBtoHSV(color.rgb);
vec3 huePoleA = RGBtoHSV(guide);
vec3 huePoleB = HSVComplement(huePoleA);

float dist1 = abs(colorHSV.x - huePoleA.x);
if (dist1 > 0.5) dist1 = 1.0 - dist1;

float dist2 = abs(colorHSV.x - huePoleB.x);
if (dist2 > 0.5) dist2 = 1.0 - dist2;

float descent = smoothstep(0.0, correlation, colorHSV.y);

vec3 HSVColor = colorHSV;

    if (dist1 < dist2) {

float c = descent * amount * (1.0 - pow((dist1 * 2.0), 1.0 / concentration));

HSVColor.x = HueLerp(colorHSV.x, huePoleA.x, c);
HSVColor.y = lerp(colorHSV.y, huePoleA.y, c);
}
else
{
float c = descent * amount * (1.0 - pow((dist2 * 2.0), 1.0 / concentration));

HSVColor.x = HueLerp(colorHSV.x, huePoleB.x, c);
HSVColor.y = lerp(colorHSV.y, huePoleB.y, c);
}

color.rgb = HSVtoRGB(HSVColor);

color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif




/*------------------------------------------------------------------------------
[TV COLORS EMU CODE SECTION]
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
SimoneT NTSC TV colors emulation 1.0 Shader
Copyright (C) 2016 SimoneT - [email protected]
Credit to SimoneT.
------------------------------------------------------------------------------*/

#if NTSC_TV_EMULATION == 1

// conversion from NTSC RGB Reference White D65 ( color space used by NA/Japan TV's ) to XYZ
vec3 NTSC(vec3 c)
{
vec3 v = vec3(pow(c.r, 2.2), pow(c.g, 2.2), pow(c.b, 2.2)); //Inverse Companding
return v*mat3(
0.6068909, 0.1735011, 0.2003480,
0.2989164, 0.5865990, 0.1144845,
0.0000000, 0.0660957, 1.1162243);
}

// conversion from XYZ to sRGB Reference White D65 ( color space used by windows )
vec3 sRGB(vec3 c)
{
vec3 v = c*mat3(
3.2404542, -1.5371385, -0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434, -0.2040259, 1.0572252);

//Companding
v.r = (v.r > 0.0031308) ? ((1.055 * pow(v.r, (1.0 / 2.4))) - 0.055) : 12.92 * v.r;
v.g = (v.g > 0.0031308) ? ((1.055 * pow(v.g, (1.0 / 2.4))) - 0.055) : 12.92 * v.g;
v.b = (v.b > 0.0031308) ? ((1.055 * pow(v.b, (1.0 / 2.4))) - 0.055) : 12.92 * v.b;
return v;
}

// NTSC RGB to sRGB
vec3 NTSCtoSRGB(vec3 c)
{
return sRGB(NTSC(c));
}

// Ported from SimoneT TV colors emulation 1.0 Shader
vec4 TvColorsPass(vec4 color, vec2 texcoord)
{
color.rgb = NTSCtoSRGB(color.rgb);

return color;
}
#endif





/*------------------------------------------------------------------------------
[MAIN() & COMBINE PASS CODE SECTION]
------------------------------------------------------------------------------*/

void main()
{
vec2 texcoord = gl_TexCoord[0].xy;
vec4 color = texture2D(OGLTexture0, texcoord);

#if USE_FXAA == 1
color = FXAAPass(color, texcoord);
#endif

#if GAMMA_CORRECTION == 1
color = GammaPass(color, texcoord);
#endif

#if PIXEL_VIBRANCE == 1
color = VibrancePass(color, texcoord);
#endif

#if BLENDED_BLOOM == 1
color = BloomPass(color, texcoord);
#endif

#if SCENE_TONEMAPPING == 1
color = TonemapPass(color, texcoord);
#endif

#if USE_CURVES == 1
color = CurvesPass(color, texcoord);
#endif

#if COLOR_CORRECTION == 1
color = CorrectionPass(color, texcoord);
#endif

#if CROSS_PROCESSING == 1
color = CrossPass(color, texcoord);
#endif

#if COLOR_GRADING == 1
color = ColorGradingPass(color, texcoord);
#endif


#if NTSC_TV_EMULATION == 1
color = TvColorsPass(color, texcoord);
#endif


gl_FragColor = color;
}

Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-17 15:10:59
Turning options on there does lead to a very close psx look. Where did you find that shader?  Is it on this forum?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-17 15:51:56
Yep, in the graphic section: http://forums.qhimm.com/index.php?topic=17411.0

Edit:
Some wrong colored pixels (the blue ones) at the jump-in-holes in gldgate (don't know if this is fixed already):
(http://i.imgur.com/XmYHHHV.png)

Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-18 04:04:24
colour issues are listed there in the database.  Gldgate has now been added to the list (field 24).  Thanks :)

In meantime, I've been tweaking that shader to conform as closely to PSX but with superior colour and so on.  I had to calibrate my monitor, which also led to me getting aura migraine.  But it was worth it.  I don't think it's going to get much better than this on PC:

[Add as psx.post into 'shaders' folder in 1998 game root (when using Aali's driver), then edit ff7_opengl.cfg so that it uses it with post processing option.]

Code: [Select]
/*===============================================================================*\
|#######################   [FINAL FANTASY 7 SHADER FX]    ########################|
|#########################   By Sunwalker 21/Jan/2017   ##########################|
||                                Version 1.05                                   ||
||                                                                               ||
||          This program is free software; you can redistribute it and/or        ||
||          modify it under the terms of the GNU General Public License          ||
||          as published by the Free Software Foundation; either version 2       ||
||          of the License, or (at your option) any later version.               ||
||                                                                               ||
||          This program is distributed in the hope that it will be useful,      ||
||          but WITHOUT ANY WARRANTY; without even the implied warranty of       ||
||          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        ||
||          GNU General Public License for more details. (c)2016                 ||
||                                                                               ||
|#################################################################################|
\*===============================================================================*/
#version 120

#extension GL_NV_gpu_shader5 : enable
#extension GL_ARB_gpu_shader5 : enable
#extension GL_ARB_shader_precision : enable
#extension GL_ARB_sample_shading : enable
#extension GL_ARB_texture_rectangle : enable
#extension GL_ARB_shader_storage_buffer_object : enable
#extension GL_ARB_shader_image_load_store : enable
#extension GL_ARB_bindless_texture : enable
#extension GL_ARB_shading_language_420pack : enable


/*------------------------------------------------------------------------------
[DEFINITIONS & ON/OFF OPTIONS]
------------------------------------------------------------------------------*/
//--------------------------#[CHOOSE EFFECTS]#--------------------------------\\
//#[ANTIALIASING TECHNIQUES]   [1=ON|0=OFF]  # NOTE:
#define USE_FXAA                  1      //# [0 or 1] FXAA Fast Anti-aliasing

//#[LIGHTING & COLOUR]         [1=ON|0=OFF]  # NOTE: This one can enable all
#define GAMMA_CORRECTION            1      //# RGB Gamma Correction. Fixed expansion to variable compression gamma correction curve.
#define BLENDED_BLOOM               1      //# High Quality SP Bloom. Soft lighting with blending techniques, for a natural looking bloom.
#define SCENE_TONEMAPPING           0      //# HDR Scene Tonemapping. Layered component conversion, and applies scene tone mapping.
#define COLOR_CORRECTION            1      //# Component Color Correction. Colorspace conversion, with correction curves, and multiple palette types.
#define CROSS_PROCESSING            0      //# Filmic Cross Processing. Alters the tone of the scene, crossing the game's color set, with another.
#define PIXEL_VIBRANCE              1      //# Pixel Vibrance. Intelligently adjusts pixel vibrance depending on original color saturation.
#define COLOR_GRADING               0      //# Post-Complement Colour Grading. Alters individual colour components on a scene, to enhance selected

colour tones.
#define USE_CURVES            1    //# [0 or 1] Curves : Contrast adjustments using S-curves.


//#[MISC]                      [1=ON|0=OFF]  # NOTE: Enable one only
#define NTSC_TV_EMULATION           0      //# SimoneT's TV Colors Emulation Shader. Use to emulate the original PSX color space tone, and vibrancy.
/*------------------------------------------------------------------------------
[EFFECT CONFIG OPTIONS]
------------------------------------------------------------------------------*/

//##[GAMMA_CORRECTION]
#define Gamma 2.20                            //[1.5 to 4.0] Gamma correction. Decrease for lower gamma(darker). Increase for higher gamma(brighter). (Default:

2.2)

//##[BLENDED_BLOOM]
#define BloomType BlendScreen                   //[BlendGlow, BlendAddGlow, BlendAddLight, BlendScreen, BlendLuma, BlendOverlay] The type of blended

bloom. Light<->Dark.
#define BloomStrength 0.200                   //[0.000 to 1.000] Overall strength of the bloom. You may want to readjust for each blend type.
#define BlendStrength 1.000                   //[0.000 to 1.000] Strength of the blending. This is a modifier based on bloom. 1.0 equates to 100% strength.
#define BloomDefocus 2.000                    //[1.000 to 4.000] The initial bloom defocus value. Increases the softness of light, bright objects, etc.
#define BloomWidth 3.200                      //[1.000 to 8.000] Width of the bloom. Adjusts the width of the spread and soft glow. Scales with BloomStrength.
#define BloomReds 0.040                       //[0.000 to 1.000] Red channel correction of the bloom. Raising will increase the bloom of reds.
#define BloomGreens 0.030                     //[0.000 to 1.000] Green channel correction of the bloom. Raising will increase the bloom of greens.
#define BloomBlues 0.020                      //[0.000 to 1.000] Blue channel correction of the bloom. Raising will increase the bloom of blues.

//##[SCENE_TONEMAPPING]
#define TonemapType 2                         //[0|1|2|3] The base tone mapping operator. 0 is LDR, 1 is HDR(original), 2 & 3 are Filmic HDR(slight grading).
#define TonemapMask 1                         //[0 or 1] Enables an ALU tone masking curve. Produces a nice cinematic look. Suits some games more than

others.
#define MaskStrength 0.10                     //[0.000 to 1.000] Strength of the tone masking. Higher for a stronger effect. This is a dependency of

TonemapMask.
#define ToneAmount 0.360                      //[0.050 to 1.000] Tonemap strength (tone correction). Higher for stronger tone mapping, lower for lighter.
#define BlackLevels 0.060                     //[0.000 to 1.000] Black level balance (shadow correction). Increase to deepen blacks, lower to lighten them.
#define Exposure 1.000                        //[0.100 to 2.000] White correction (brightness). Higher values for more scene exposure, lower for less.
#define Luminance 1.000                       //[0.100 to 2.000] Luminance average (luminance correction). Higher values will lower scene luminance average.
#define WhitePoint 1.075                      //[0.100 to 2.000] Whitepoint average (wp lum correction). Higher values will lower the maximum scene white point.

//##[COLOR_CORRECTION]
#define CorrectionPalette 1                   //[1|2|3|4|5] The colorspace palette type. 1: RGB, 2: YXY, 3: XYZ, 4: HSV, 5: YUV. Each one will produce a different

combination of shades & hues.
#define ChannelR 1.40                         //[0.00 to 8.00] R(1), Y(2), X(3), H(4), Y(5) component channel varies with the colorspace used. Higher values

increase correction strength.
#define ChannelG 1.60                         //[0.00 to 8.00] G(1), X(2), Y(3), S(4), U(5) component channel varies with the colorspace used. Higher values

increase correction strength.
#define ChannelB 1.80                         //[0.00 to 8.00] B(1), Y(2), Z(3), V(4), V(5) component channel varies with the colorspace used. Higher values

increase correction strength.
#define PaletteStrength 2.00                  //[0.00 to 4.00] The interpolated strength ratio between the base color, and the corrected color. Raise to increase

saturation.

//##[PIXEL_VIBRANCE]
#define Vibrance 0.15                          //[-1.00 to 1.00] Overall vibrance strength. Locally adjusts the vibrance of pixels depending on their original

saturation.
#define RedVibrance 1.00                       //[-8.00 to 8.00] Red channel coefficient of the vibrance strength. Adjusting the vibrance of the red channel

independently.
#define GreenVibrance 1.00                     //[-8.00 to 8.00] Green channel coefficient of the vibrance strength. Adjusting the vibrance of the green channel

independently.
#define BlueVibrance 1.00                      //[-8.00 to 8.00] Blue channel coefficient of the vibrance strength. Adjusting the vibrance of the blue channel

independently.

//##[CROSS_PROCESSING]
#define FilmicProcess 1                         //[1|2|3] The color conversion type for the cross process. 1: cool, 2: warm, 3: dusk. You can achieve different

results with each.
#define RedShift 0.65                           //[0.10 to 1.00] Red color component shift of the filmic processing. Alters the red balance of the shift.
#define GreenShift 0.50                         //[0.10 to 1.00] Green color component shift of the filmic processing. Alters the green balance of the shift.
#define BlueShift 0.50                          //[0.10 to 1.00] Blue color component shift of the filmic processing. Alters the blue balance of the shift.
#define ShiftRatio 0.50                         //[0.10 to 2.00] The blending ratio for the base color and the color shift. Higher for a stronger effect.

//##[COLOR_GRADING]
#define RedGrading 1.20                         //[0.00 to 3.00] Red colour grading coefficient. Adjust to influence the red channel coefficients of the grading, and

highlight tones.
#define GreenGrading 1.10                       //[0.00 to 3.00] Green colour grading coefficient. Adjust to influence the Green channel coefficients of the

grading, and highlight tones.
#define BlueGrading 1.10                        //[0.00 to 3.00] Blue colour grading coefficient. Adjust to influence the Blue channel coefficients of the grading,

and highlight tones.
#define GradingStrength 0.35                    //[0.00 to 1.00] The overall max strength of the colour grading effect. Raise to increase, lower to decrease the

amount.
#define Correlation 1.00                        //[0.10 to 1.00] Correlation between the base colour, and the grading influence. Lower = more of the scene is

graded, Higher = less of the scene is graded.

//##[USE_CURVES]
#define Curves_mode        2             //[0|1|2] Choose what to apply contrast to. 0 = Luma, 1 = Chroma, 2 = both Luma and

Chroma. Default is 0 (Luma)
#define Curves_contrast 0.20         //[-1.00 to 1.00] The amount of contrast you want

//##[Advanced curve settings]
#define Curves_formula      3             //[1|2|3|4|5|6|7|8|9|10] The contrast s-curve you want to use.
                                      //1 = Sine, 2 = Abs split, 3 = Smoothstep, 4 = Exp formula, 5 = Simplified Catmull-Rom (0,0,1,1), 6 =

Perlins Smootherstep
                                      //7 = Abs add, 8 = Techicolor Cinestyle, 9 = Parabola, 10 = Half-circles.
                                      //Note that Technicolor Cinestyle is practically identical to Sine, but runs slower. In fact I think the difference

might only be due to rounding errors.
                                      //I prefer 2 myself, but 3 is a nice alternative with a little more effect (but harsher on the highlight and

shadows) and it's the fastest formula


//[END OF USER OPTIONS]

/*------------------------------------------------------------------------------
[GLOBALS|FUNCTIONS]
------------------------------------------------------------------------------*/

//Global variables
#define saturate(x) clamp(x, 0.0, 1.0)
#define lerp mix
#define frac fract
#define fmod mod
#define mul(x, y) (y * x)
#define float4x3 mat4x3
#define float3x3 mat3
#define float4x4 mat4
#define lumCoeff vec3(0.212656, 0.715158, 0.072186)
#define PI 3.1415972

//OGL Uniforms
uniform sampler2D OGLTexture;
uniform sampler2D OGLTexture0;

//varying
uniform vec2 texcoord;

float Epsilon = 1e-10;

#define texture_width   1024.0
#define texture_height  1024.0

#define texel_size_x  (1.0 / texture_width)
#define texel_size_y  (1.0 / texture_height)

#define OGLSize     vec2(texture_width, texture_height)
#define OGLInvSize  vec2(texel_size_x, texel_size_y)

//Average Relative Luminance (HSP Color Model)
float AvgLuminance(vec3 color)
{
return sqrt(dot(color * color, lumCoeff));
}

//Smoothstep alt
float smootherstep(float a, float b, float x)
{
x = saturate((x - a) / (b - a));
return x*x*x*(x*(x * 6 - 15) + 10);
}

//Conversion matrices
vec3 RGBtoXYZ(vec3 RGB)
{
const mat3 RGBtoXYZ = mat3(
0.6068909, 0.1735011, 0.2003480,
0.2989164, 0.5865990, 0.1144845,
0.0000000, 0.0660957, 1.1162243);

return RGBtoXYZ*RGB;
}

vec3 XYZtoRGB(vec3 XYZ)
{
const mat3 XYZtoRGB = mat3(
1.9099961, -0.5324542, -0.2882091,
-0.9846663, 1.9991710, -0.0283082,
0.0583056, -0.1183781, 0.8975535);

return XYZtoRGB*XYZ;
}

vec3 XYZtoSRGB(vec3 XYZ)
{
const mat3 XYZtoSRGB = mat3(
3.2404542, -1.5371385, -0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434, -0.2040259, 1.0572252);

return XYZtoSRGB*XYZ;
}

vec3 RGBtoYUV(vec3 RGB)
{
const mat3 RGBtoYUV = mat3(
0.2126, 0.7152, 0.0722,
-0.09991, -0.33609, 0.436,
0.615, -0.55861, -0.05639);

return RGBtoYUV*RGB;
}

vec3 YUVtoRGB(vec3 YUV)
{
const mat3 YUVtoRGB = mat3(
1.000, 0.000, 1.28033,
1.000, -0.21482, -0.38059,
1.000, 2.12798, 0.000);

return YUVtoRGB*YUV;
}

vec3 XYZtoYxy(vec3 XYZ)
{
float w = (XYZ.r + XYZ.g + XYZ.b);
vec3 Yxy;

Yxy.r = XYZ.g;
Yxy.g = XYZ.r / w;
Yxy.b = XYZ.g / w;

return Yxy;
}

vec3 YxytoXYZ(vec3 Yxy)
{
vec3 XYZ;
XYZ.g = Yxy.r;
XYZ.r = Yxy.r * Yxy.g / Yxy.b;
XYZ.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;

return XYZ;
}

/*------------------------------------------------------------------------------
[FXAA CODE SECTION]
Code from http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/
Credit to original Author
------------------------------------------------------------------------------*/
#if USE_FXAA == 1
float xbrthreshold = 0.020;
vec2 rcpFrame = OGLInvSize;
vec3 FXAA(sampler2D OGLTexture, vec2 texcoord)
{
float FXAA_SPAN_MAX = 8.0;                     //[4.0 t0 8.0]             
float FXAA_REDUCE_MUL = (1.0 / FXAA_SPAN_MAX); //[Default]
float FXAA_REDUCE_MIN = (1.0 / 128.0);         //[Default]
float FXAA_SUBPIX_SHIFT = (1.0 / 4.0);         //[Default]

vec4 posPos = vec4(texcoord.xy, texcoord.xy - (rcpFrame * (0.5 + FXAA_SUBPIX_SHIFT)));

/*---------------------------------------------------------*/
vec3 rgbNW = texture2D(OGLTexture, posPos.zw, 0.0).rgb;
vec3 rgbNE = texture2D(OGLTexture, posPos.zw + vec2(1., 0.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbSW = texture2D(OGLTexture, posPos.zw + vec2(0., 1.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbSE = texture2D(OGLTexture, posPos.zw + vec2(1., 1.)*rcpFrame.xy, 0.0).rgb;
vec3 rgbM = texture2D(OGLTexture, texcoord.xy, 0.0).rgb;
/*---------------------------------------------------------*/
//vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = AvgLuminance(rgbNW);
float lumaNE = AvgLuminance(rgbNE);
float lumaSW = AvgLuminance(rgbSW);
float lumaSE = AvgLuminance(rgbSE);
float lumaM = AvgLuminance(rgbM);
/*---------------------------------------------------------*/
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));

float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
/*---------------------------------------------------------*/
vec2 dir;

dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));

dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
/*---------------------------------------------------------*/
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);

float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);

dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) *

rcpFrame.xy;
/*--------------------------------------------------------*/

vec3 rgbA = (1.0 / 2.0) * (texture2D(OGLTexture, texcoord.xy + dir * (1.0 / 3.0 - 0.5)).rgb + texture2D(OGLTexture, texcoord.xy + dir * (2.0 / 3.0 -

0.5)).rgb);
vec3 rgbB = rgbA * (1.0 / 2.0) + (1.0 / 4.0) * (texture2D(OGLTexture, texcoord.xy + dir * (0.0 / 3.0 - 0.5)).rgb + texture2D(OGLTexture,

texcoord.xy + dir * (3.0 / 3.0 - 0.5)).rgb);

float lumaB = AvgLuminance(rgbB);

return ((lumaB < lumaMin) || (lumaB > lumaMax)) ? rgbA.rgb : rgbB.rgb;
}

//Hyllian's xBR Level 2 shader
//Copyright(C) 2011 / 2014 Hyllian / Jararaca - [email protected]
//Credit to Hyllian
float x_Width = texture_width;
float y_Height = texture_height;

float x_coef = texel_size_x;
float y_coef = texel_size_y;

float coef = 2.0;
vec3 rgbw = vec3(14.352, 28.176, 5.472);

float x = 0.5 * (1.0 / x_Width);
float y = 0.5 * (1.0 / y_Height);

//vec2 dx = vec2(x, 0.0);
//vec2 dy = vec2(0.0, y);
vec2 dx = vec2(0.0009765625, 0.0);//vec2(x, 0.0);//
vec2 dy = vec2(0.0, 0.001953125);//vec2(0.0, y);//
vec2 x2 = vec2(0.001953125, 0.0);//vec2(y, 0);//
vec2 y2 = vec2(0.0, 0.00390625);//vec2( 0.0 , y*2.0 );//
vec4 xy = vec4(0.0009765625, 0.001953125, -0.0009765625, -0.001953125);//vec4( x, y,-x,-y);//
vec4 zw = vec4(0.001953125, 0.001953125, -0.001953125, -0.00390625);//vec4( y , y,-y ,-(y*2.0));//
vec4 wz = vec4(0.0009765625, 0.00390625, -0.0009765625, -0.00390625);  //vec4( x, y*2.0 ,-x,-(y*2.0));//

vec4 df(vec4 A, vec4 B)
{
return abs(A - B);
}

vec4 weighted_distance(vec4 a, vec4 b, vec4 c, vec4 d, vec4 e, vec4 f, vec4 g, vec4 h)
{
return (df(a, b) + df(a, c) + df(d, e) + df(d, f) + 4.0*df(g, h));
}


vec3 xBR(sampler2D OGLTexture, vec2 texcoord)
{
vec4 edr, edr_left, edr_up; bvec4 px; // px = pixel, edr = edge detection rule
vec4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
bvec4 nc; // new_color
vec4 fx, fx_left, fx_up; // inequations of straight lines.

vec2 fp = fract(texcoord.xy*vec2(x_Width, y_Height));
vec2 vTex = texcoord.xy - fp*vec2(0.0009765625*x_coef, 0.001953125*y_coef);//vec2(x, y);

vec3 A = texture2D(OGLTexture, vTex + xy.zw).rgb;
vec3 B = texture2D(OGLTexture, vTex - dy).rgb;
vec3 C = texture2D(OGLTexture, vTex + xy.xw).rgb;
vec3 D = texture2D(OGLTexture, vTex - dx).rgb;
vec3 E = texture2D(OGLTexture, vTex).rgb;
vec3 F = texture2D(OGLTexture, vTex + dx).rgb;
vec3 G = texture2D(OGLTexture, vTex + xy.zy).rgb;
vec3 H = texture2D(OGLTexture, vTex + dy).rgb;
vec3 I = texture2D(OGLTexture, vTex + xy.xy).rgb;
vec3 A1 = texture2D(OGLTexture, vTex + wz.zw).rgb;
vec3 C1 = texture2D(OGLTexture, vTex + wz.xw).rgb;
vec3 A0 = texture2D(OGLTexture, vTex + zw.zw).rgb;
vec3 G0 = texture2D(OGLTexture, vTex + zw.zy).rgb;
vec3 C4 = texture2D(OGLTexture, vTex + zw.xw).rgb;
vec3 I4 = texture2D(OGLTexture, vTex + zw.xy).rgb;
vec3 G5 = texture2D(OGLTexture, vTex + wz.zy).rgb;
vec3 I5 = texture2D(OGLTexture, vTex + wz.xy).rgb;
vec3 B1 = texture2D(OGLTexture, vTex - y2).rgb;
vec3 D0 = texture2D(OGLTexture, vTex - x2).rgb;
vec3 H5 = texture2D(OGLTexture, vTex + y2).rgb;
vec3 F4 = texture2D(OGLTexture, vTex + x2).rgb;

vec4 b = vec4(dot(B, rgbw), dot(D, rgbw), dot(H, rgbw), dot(F, rgbw));
vec4 c = vec4(dot(C, rgbw), dot(A, rgbw), dot(G, rgbw), dot(I, rgbw));
vec4 d = b.yzwx;
vec4 e = vec4(dot(E, rgbw));
vec4 f = b.wxyz;
vec4 g = c.zwxy;
vec4 h = b.zwxy;
vec4 i = c.wxyz;
vec4 i4 = vec4(dot(I4, rgbw), dot(C1, rgbw), dot(A0, rgbw), dot(G5, rgbw));
vec4 i5 = vec4(dot(I5, rgbw), dot(C4, rgbw), dot(A1, rgbw), dot(G0, rgbw));
vec4 h5 = vec4(dot(H5, rgbw), dot(F4, rgbw), dot(B1, rgbw), dot(D0, rgbw));
vec4 f4 = h5.yzwx;

vec4 Ao = vec4(1.0, -1.0, -1.0, 1.0);
vec4 Bo = vec4(1.0, 1.0, -1.0, -1.0);
vec4 Co = vec4(1.5, 0.5, -0.5, 0.5);
vec4 Ax = vec4(1.0, -1.0, -1.0, 1.0);
vec4 Bx = vec4(0.5, 2.0, -0.5, -2.0);
vec4 Cx = vec4(1.0, 1.0, -0.5, 0.0);
vec4 Ay = vec4(1.0, -1.0, -1.0, 1.0);
vec4 By = vec4(2.0, 0.5, -2.0, -0.5);
vec4 Cy = vec4(2.0, 0.0, -1.0, 0.5);
vec4 Ci = vec4(0.25, 0.25, 0.25, 0.25);

// These inequations define the line below which interpolation occurs.
fx = vec4(greaterThan(Ao*fp.y + Bo*fp.x, Co));
fx_left = vec4(greaterThan(Ax*fp.y + Bx*fp.x, Cx));
fx_up = vec4(greaterThan(Ay*fp.y + By*fp.x, Cy));

interp_restriction_lv1 = vec4(notEqual(e, f))*vec4(notEqual(e, h));
interp_restriction_lv2_left = vec4(notEqual(e, g))*vec4(notEqual(d, g));
interp_restriction_lv2_up = vec4(notEqual(e, c))*vec4(notEqual(b, c));

edr = vec4(lessThan(weighted_distance(e, c, g, i, h5, f4, h, f), weighted_distance(h, d, i5, f, i4, b, e, i)))*interp_restriction_lv1;
edr_left = vec4(lessThanEqual(coef*df(f, g), df(h, c)))*interp_restriction_lv2_left;
edr_up = vec4(greaterThanEqual(df(f, g), coef*df(h, c)))*interp_restriction_lv2_up;

nc = bvec4(edr*(max(max(fx, edr_left*fx_left), edr_up*fx_up)));

px = lessThanEqual(df(e, f), df(e, h));

vec3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;

return res;
}

float diff2D(vec2 coord)
{
vec3 dt = vec3(1.0, 1.0, 1.0);

vec3 c00 = texture2D(OGLTexture, coord + 0.25*(-dx - dy)).xyz;
vec3 c20 = texture2D(OGLTexture, coord + 0.25*(dx - dy)).xyz;
vec3 c02 = texture2D(OGLTexture, coord + 0.25*(-dx + dy)).xyz;
vec3 c22 = texture2D(OGLTexture, coord + 0.25*(dx + dy)).xyz;

vec3 mn = min(min(c00, c20), min(c02, c22));
vec3 mx = max(max(c00, c20), max(c02, c22));

return dot(mx - mn, dt);
}

vec4 FXAAPass(vec4 color, vec2 texcoord)
{
vec2 fp = fract(texcoord * OGLSize);
vec2 vTex = texcoord - fp * OGLInvSize + 0.5 * OGLInvSize;
vec2 locator = sign(fp - vec2(0.5000000001, 0.5000000001));

float maxdiff = max(max(diff2D(vTex + locator*dx), diff2D(vTex + locator*dy)), diff2D(vTex));

if (maxdiff <= xbrthreshold) { color.rgb = xBR(OGLTexture, texcoord); }
else { color.rgb = FXAA(OGLTexture, texcoord); }

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[GAMMA CORRECTION CODE SECTION]
------------------------------------------------------------------------------*/

vec3 EncodeGamma(vec3 color, float gamma)
{
color = saturate(color);
color.r = (color.r <= 0.0404482362771082) ? color.r / 12.92 : pow((color.r + 0.055) / 1.055, gamma);
color.g = (color.g <= 0.0404482362771082) ? color.g / 12.92 : pow((color.g + 0.055) / 1.055, gamma);
color.b = (color.b <= 0.0404482362771082) ? color.b / 12.92 : pow((color.b + 0.055) / 1.055, gamma);

return color;
}

vec3 DecodeGamma(vec3 color, float gamma)
{
color = saturate(color);
color.r = (color.r <= 0.00313066844250063) ? color.r * 12.92 : 1.055 * pow(color.r, 1.0 / gamma) - 0.055;
color.g = (color.g <= 0.00313066844250063) ? color.g * 12.92 : 1.055 * pow(color.g, 1.0 / gamma) - 0.055;
color.b = (color.b <= 0.00313066844250063) ? color.b * 12.92 : 1.055 * pow(color.b, 1.0 / gamma) - 0.055;

return color;
}

#if GAMMA_CORRECTION == 1
vec4 GammaPass(vec4 color, vec2 texcoord)
{
const float GammaConst = 2.233333;
color.rgb = EncodeGamma(color.rgb, GammaConst);
color.rgb = DecodeGamma(color.rgb, float(Gamma));
color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[PIXEL VIBRANCE CODE SECTION]
------------------------------------------------------------------------------*/

#if PIXEL_VIBRANCE == 1
vec4 VibrancePass(vec4 color, vec2 texcoord)
{
float vib = Vibrance;

float lum = AvgLuminance(color.rgb);
vec3 luma = vec3(lum, lum, lum);

float colorMax = max(color.r, max(color.g, color.b));
float colorMin = min(color.r, min(color.g, color.b));

float colorSaturation = colorMax - colorMin;
vec3 colorCoeff = vec3(RedVibrance * vib, GreenVibrance * vib, BlueVibrance * vib);

color.rgb = lerp(luma, color.rgb, (1.0 + (colorCoeff * (1.0 - (sign(colorCoeff) * colorSaturation)))));
color.a = AvgLuminance(color.rgb);

return saturate(color); //Debug: return colorSaturation.xxxx;
}
#endif

/*------------------------------------------------------------------------------
[BLENDED BLOOM CODE SECTION]
------------------------------------------------------------------------------*/

#if BLENDED_BLOOM == 1
vec3 BlendAddLight(vec3 bloom, vec3 blend)
{
return saturate(bloom + blend);
}

vec3 BlendScreen(vec3 bloom, vec3 blend)
{
return (bloom + blend) - (bloom * blend);
}

vec3 BlendGlow(vec3 bloom, vec3 blend)
{
float glow = AvgLuminance(bloom);
return lerp((bloom + blend) - (bloom * blend), (blend + blend) - (blend * blend), glow);
}

vec3 BlendAddGlow(vec3 bloom, vec3 blend)
{
float addglow = smootherstep(0.0, 1.0, AvgLuminance(bloom));
return lerp(saturate(bloom + blend), (blend + blend) - (blend * blend), addglow);
}

vec3 BlendLuma(vec3 bloom, vec3 blend)
{
float lumavg = smootherstep(0.0, 1.0, AvgLuminance(bloom + blend));
return lerp((bloom * blend), (1.0 - ((1.0 - bloom) * (1.0 - blend))), lumavg);
}

vec3 BlendOverlay(vec3 bloom, vec3 blend)
{
vec3 overlay = step(0.5, bloom);
return lerp((bloom * blend * 2.0), (1.0 - (2.0 *(1.0 - bloom) * (1.0 - blend))), overlay);
}

vec3 BloomCorrection(vec3 color)
{
vec3 bloom = color;

bloom.r = 2.0 / 3.0 * (1.0 - (bloom.r * bloom.r));
bloom.g = 2.0 / 3.0 * (1.0 - (bloom.g * bloom.g));
bloom.b = 2.0 / 3.0 * (1.0 - (bloom.b * bloom.b));

bloom.r = saturate(color.r + float(BloomReds) * bloom.r);
bloom.g = saturate(color.g + float(BloomGreens) * bloom.g);
bloom.b = saturate(color.b + float(BloomBlues) * bloom.b);
color = bloom;
return color;
}

vec4 DefocusFilter(sampler2D OGLTexture, vec2 texcoord, vec2 defocus)
{
defocus = clamp(defocus, 1.0, 1.5);
vec2 texel = vec2(texel_size_x, texel_size_y) * defocus;

vec4 sampleA = texture2D(OGLTexture, texcoord + vec2(0.5, 0.5) * texel);
vec4 sampleB = texture2D(OGLTexture, texcoord + vec2(-0.5, 0.5) * texel);
vec4 sampleC = texture2D(OGLTexture, texcoord + vec2(0.5, -0.5) * texel);
vec4 sampleD = texture2D(OGLTexture, texcoord + vec2(-0.5, -0.5) * texel);

float fx = frac(texcoord.x * texture_width);
float fy = frac(texcoord.y * texture_height);

vec4 interpolateA = lerp(sampleA, sampleB, fx);
vec4 interpolateB = lerp(sampleC, sampleD, fx);
return lerp(interpolateA, interpolateB, fy);
}

vec4 BloomPass(vec4 color, vec2 texcoord)
{
float anflare = 4.0;
float width = BloomWidth;

vec2 defocus = vec2(BloomDefocus, BloomDefocus);
vec4 bloom = DefocusFilter(OGLTexture, texcoord, defocus);

vec2 dx = vec2(texel_size_x * width, 0.0);
vec2 dy = vec2(0.0, texel_size_y * width);

vec2 mdx = vec2(dx.x * defocus.x, 0.0);
vec2 mdy = vec2(0.0, dy.y * defocus.y);

vec4 blend = bloom * 0.22520613262190495;

blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord - mdx + mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - dx + mdy);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord + mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + dx + mdy);
blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord + mdx + mdy);

blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - mdx + dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord - dx + dy);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord + dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord + dx + dy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + mdx + dy);

blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord - mdx);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord - dx);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord + dx);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord + mdx);

blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - mdx - dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord - dx - dy);
blend += 0.100529757860782610 * texture2D(OGLTexture, texcoord - dy);
blend += 0.044875475183061630 * texture2D(OGLTexture, texcoord + dx - dy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + mdx - dy);

blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord - mdx - mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord - dx - mdy);
blend += 0.024146616900339800 * texture2D(OGLTexture, texcoord - mdy);
blend += 0.010778807494659370 * texture2D(OGLTexture, texcoord + dx - mdy);
blend += 0.002589001911021066 * texture2D(OGLTexture, texcoord + mdx - mdy);
blend = lerp(color, blend, float(BlendStrength));

bloom.xyz = BloomType(bloom.xyz, blend.xyz);
bloom.xyz = BloomCorrection(bloom.xyz);

color.w = AvgLuminance(color.xyz);
bloom.w = AvgLuminance(bloom.xyz);
bloom.w *= anflare;

color = lerp(color, bloom, float(BloomStrength));

return color;
}
#endif

/*------------------------------------------------------------------------------
[SCENE TONE MAPPING CODE SECTION]
------------------------------------------------------------------------------*/

#if SCENE_TONEMAPPING == 1

vec3 ScaleLuminance(vec3 x)
{
float W = 1.02; // WhitePoint Scale
float L = 0.16; // Luminance Scale
float C = 1.02; // Compression Scale

float N = clamp(0.82 + ToneAmount, 1.0, 2.0);
float K = (N - L * C) / C;

vec3 tone = L * C + (1.0 - L * C) * (1.0 + K * (x - L) / ((W - L) * (W - L))) * (x - L) / (x - L + K);

vec3 color;
color.r = (x.r > L) ? tone.r : C * x.r;
color.g = (x.g > L) ? tone.g : C * x.g;
color.b = (x.b > L) ? tone.b : C * x.b;

return color;
}

vec3 TmMask(vec3 color)
{
vec3 tone = color;

float highTone = 6.2;
float greyTone = 0.4;
float midTone = 1.62;
float lowTone = 0.06;

tone.r = (tone.r * (highTone * tone.r + greyTone)) / (tone.r * (highTone * tone.r + midTone) + lowTone);
tone.g = (tone.g * (highTone * tone.g + greyTone)) / (tone.g * (highTone * tone.g + midTone) + lowTone);
tone.b = (tone.b * (highTone * tone.b + greyTone)) / (tone.b * (highTone * tone.b + midTone) + lowTone);

const float gamma = 2.42;
tone = EncodeGamma(tone, gamma);

color = lerp(color, tone, float(MaskStrength));

return color;
}

vec3 TmCurve(vec3 color)
{
vec3 T = color;

float tnamn = ToneAmount;
float blevel = length(T);
float bmask = pow(blevel, 0.02);

float A = 0.100; float B = 0.300;
float C = 0.100; float D = tnamn;
float E = 0.020; float F = 0.300;

float W = 1.000;

T.r = ((T.r*(A*T.r + C*B) + D*E) / (T.r*(A*T.r + B) + D*F)) - E / F;
T.g = ((T.g*(A*T.g + C*B) + D*E) / (T.g*(A*T.g + B) + D*F)) - E / F;
T.b = ((T.b*(A*T.b + C*B) + D*E) / (T.b*(A*T.b + B) + D*F)) - E / F;

float denom = ((W*(A*W + C*B) + D*E) / (W*(A*W + B) + D*F)) - E / F;

vec3 black = vec3(bmask, bmask, bmask);
vec3 white = vec3(denom, denom, denom);

T = T / white;
T = T * black;

color = saturate(T);

return color;
}

vec4 TonemapPass(vec4 color, vec2 texcoord)
{
float L = Luminance;

vec3 tonemap = color.rgb;
vec3 luma = vec3(L, L, L);

float blackLevel = length(tonemap);
tonemap = ScaleLuminance(tonemap);

float luminanceAverage = AvgLuminance(luma);

if (TonemapMask == 1) { tonemap = TmMask(tonemap); }
if (TonemapType == 1) { tonemap = TmCurve(tonemap); }

// RGB -> XYZ conversion
vec3 XYZ = RGBtoXYZ(tonemap);

// XYZ -> Yxy conversion
vec3 Yxy;

Yxy.r = XYZ.g;                                  // copy luminance Y
Yxy.g = XYZ.r / (XYZ.r + XYZ.g + XYZ.b);        // x = X / (X + Y + Z)
Yxy.b = XYZ.g / (XYZ.r + XYZ.g + XYZ.b);        // y = Y / (X + Y + Z)

// (Wt) Tone mapped scaling of the initial wp before input modifiers
float Wt = saturate(Yxy.r / AvgLuminance(XYZ));

if (TonemapType == 2) { Yxy.r = TmCurve(Yxy).r; }

// (Lp) Map average luminance to the middlegrey zone by scaling pixel luminance
float Lp = Yxy.r * float(Exposure) / (luminanceAverage + Epsilon);

// (Wp) White point calculated, based on the toned white, and input modifier
float Wp = dot(abs(Wt), float(WhitePoint));

// (Ld) Scale all luminance within a displayable range of 0 to 1
Yxy.r = (Lp * (1.0 + Lp / (Wp * Wp))) / (1.0 + Lp);

// Yxy -> XYZ conversion
XYZ.r = Yxy.r * Yxy.g / Yxy.b;                  // X = Y * x / y
XYZ.g = Yxy.r;                                  // copy luminance Y
XYZ.b = Yxy.r * (1.0 - Yxy.g - Yxy.b) / Yxy.b;  // Z = Y * (1-x-y) / y

if (TonemapType == 3) { XYZ = TmCurve(XYZ); }

// XYZ -> RGB conversion
tonemap = XYZtoRGB(XYZ);

float shadowmask = pow(saturate(blackLevel), float(BlackLevels));
tonemap = tonemap * vec3(shadowmask, shadowmask, shadowmask);

color.rgb = tonemap;

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[COLOR CORRECTION CODE SECTION]
------------------------------------------------------------------------------*/

// Converting pure hue to RGB
vec3 HUEtoRGB(float H)
{
float R = abs(H * 6.0 - 3.0) - 1.0;
float G = 2.0 - abs(H * 6.0 - 2.0);
float B = 2.0 - abs(H * 6.0 - 4.0);

return saturate(vec3(R, G, B));
}

// Converting RGB to hue/chroma/value
vec3 RGBtoHCV(vec3 RGB)
{
vec4 BG = vec4(RGB.bg, -1.0, 2.0 / 3.0);
vec4 GB = vec4(RGB.gb, 0.0, -1.0 / 3.0);

vec4 P = (RGB.g < RGB.b) ? BG : GB;

vec4 XY = vec4(P.xyw, RGB.r);
vec4 YZ = vec4(RGB.r, P.yzx);

vec4 Q = (RGB.r < P.x) ? XY : YZ;

float C = Q.x - min(Q.w, Q.y);
float H = abs((Q.w - Q.y) / (6.0 * C + Epsilon) + Q.z);

return vec3(H, C, Q.x);
}

// Converting RGB to HSV
vec3 RGBtoHSV(vec3 RGB)
{
vec3 HCV = RGBtoHCV(RGB);
float S = HCV.y / (HCV.z + Epsilon);

return vec3(HCV.x, S, HCV.z);
}

// Converting HSV to RGB
vec3 HSVtoRGB(vec3 HSV)
{
vec3 RGB = HUEtoRGB(HSV.x);
return ((RGB - 1.0) * HSV.y + 1.0) * HSV.z;
}

#if COLOR_CORRECTION == 1
// Pre correction color mask
vec3 PreCorrection(vec3 color)
{
vec3 RGB = color;

RGB.r = 2.0 / 3.0 * (1.0 - (RGB.r * RGB.r));
RGB.g = 2.0 / 3.0 * (1.0 - (RGB.g * RGB.g));
RGB.b = 2.0 / 3.0 * (1.0 - (RGB.b * RGB.b));

RGB.r = saturate(color.r + (float(ChannelR) / 200.0) * RGB.r);
RGB.g = saturate(color.g + (float(ChannelG) / 200.0) * RGB.g);
RGB.b = saturate(color.b + (float(ChannelB) / 200.0) * RGB.b);

color = saturate(RGB);

return color;
}

vec3 ColorCorrection(vec3 color)
{
float X = 1.0 / (1.0 + exp(float(ChannelR) / 2.0));
float Y = 1.0 / (1.0 + exp(float(ChannelG) / 2.0));
float Z = 1.0 / (1.0 + exp(float(ChannelB) / 2.0));

color.r = (1.0 / (1.0 + exp(float(-ChannelR) * (color.r - 0.5))) - X) / (1.0 - 2.0 * X);
color.g = (1.0 / (1.0 + exp(float(-ChannelG) * (color.g - 0.5))) - Y) / (1.0 - 2.0 * Y);
color.b = (1.0 / (1.0 + exp(float(-ChannelB) * (color.b - 0.5))) - Z) / (1.0 - 2.0 * Z);

return saturate(color);
}

vec4 CorrectionPass(vec4 color, vec2 texcoord)
{
vec3 colorspace = PreCorrection(color.rgb);

#if CorrectionPalette == 1
colorspace = ColorCorrection(colorspace);

#elif CorrectionPalette == 2
vec3 XYZ = RGBtoXYZ(colorspace);
vec3 Yxy = XYZtoYxy(XYZ);

Yxy = ColorCorrection(Yxy);
XYZ = YxytoXYZ(Yxy);
colorspace = XYZtoRGB(XYZ);

#elif CorrectionPalette == 3
vec3 XYZ = RGBtoXYZ(colorspace);
vec3 Yxy = XYZtoYxy(XYZ);
XYZ = YxytoXYZ(Yxy);
XYZ = ColorCorrection(XYZ);
colorspace = XYZtoRGB(XYZ);

#elif CorrectionPalette == 4
vec3 hsv = RGBtoHSV(colorspace);
hsv = ColorCorrection(hsv);
colorspace = HSVtoRGB(hsv);

#elif CorrectionPalette == 5
vec3 yuv = RGBtoYUV(colorspace);
yuv = ColorCorrection(yuv);
colorspace = YUVtoRGB(yuv);
#endif

color.rgb = lerp(color.rgb, colorspace, float(PaletteStrength));

color.a = AvgLuminance(color.rgb);

return color;
}
#endif

/*------------------------------------------------------------------------------
[S-CURVE CONTRAST CODE SECTION]
------------------------------------------------------------------------------*/

#if USE_CURVES == 1

vec4 CurvesPass(vec4 color, vec2 texcoord)
{
float Curves_contrast_blend = Curves_contrast;


/*-----------------------------------------------------------.
/               Separation of Luma and Chroma                 /
'-----------------------------------------------------------*/

// -- Calculate Luma and Chroma if needed --
#if Curves_mode != 2

//calculate luma (grey)
float luma = dot(lumCoeff, color.rgb);

//calculate chroma
vec3 chroma = color.rgb - luma;
#endif

// -- Which value to put through the contrast formula? --
// I name it x because makes it easier to copy-paste to Graphtoy or Wolfram Alpha or another graphing program
#if Curves_mode == 2
vec3 x = color.rgb; //if the curve should be applied to both Luma and Chroma
#elif Curves_mode == 1
vec3 x = chroma; //if the curve should be applied to Chroma
x = x * 0.5 + 0.5; //adjust range of Chroma from -1 -> 1 to 0 -> 1
#else // Curves_mode == 0
float x = luma; //if the curve should be applied to Luma
#endif

    // Contrast formulas
// -- Curve 1 --
#if Curves_formula == 1
x = sin(PI * 0.5 * x); // Sin - 721 amd fps, +vign 536 nv
x *= x;

//x = 0.5 - 0.5*cos(PI*x);
//x = 0.5 * -sin(PI * -x + (PI*0.5)) + 0.5;
#endif

// -- Curve 2 --
#if Curves_formula == 2
x = x - 0.5;
x = (x / (0.5 + abs(x))) + 0.5;

//x = ( (x - 0.5) / (0.5 + abs(x-0.5)) ) + 0.5;
#endif

// -- Curve 3 --
#if Curves_formula == 3
//x = smoothstep(0.0,1.0,x); //smoothstep
x = x*x*(3.0 - 2.0*x); //faster smoothstep alternative - 776 amd fps, +vign 536 nv
//x = x - 2.0 * (x - 1.0) * x* (x- 0.5);  //2.0 is contrast. Range is 0.0 to 2.0
#endif

// -- Curve 4 --
#if Curves_formula == 4
x = (1.0524 * exp(6.0 * x) - 1.05248) / (20.0855 + exp(6.0 * x)); //exp formula
#endif

// -- Curve 5 --
#if Curves_formula == 5
//x = 0.5 * (x + 3.0 * x * x - 2.0 * x * x * x); //a simplified catmull-rom (0,0,1,1) - btw smoothstep can also be expressed as a simplified catmull-

rom using (1,0,1,0)
//x = (0.5 * x) + (1.5 -x) * x*x; //estrin form - faster version
x = x * (x * (1.5 - x) + 0.5); //horner form - fastest version

Curves_contrast_blend = Curves_contrast * 2.0; //I multiply by two to give it a strength closer to the other curves.
#endif

// -- Curve 6 --
#if Curves_formula == 6
x = x*x*x*(x*(x*6.0 - 15.0) + 10.0); //Perlins smootherstep
#endif

// -- Curve 7 --
#if Curves_formula == 7
//x = ((x-0.5) / ((0.5/(4.0/3.0)) + abs((x-0.5)*1.25))) + 0.5;
x = x - 0.5;
x = x / ((abs(x)*1.25) + 0.375) + 0.5;
//x = ( (x-0.5) / ((abs(x-0.5)*1.25) + (0.5/(4.0/3.0))) ) + 0.5;
#endif

// -- Curve 8 --
#if Curves_formula == 8
x = (x * (x * (x * (x * (x * (x * (1.6 * x - 7.2) + 10.8) - 4.2) - 3.6) + 2.7) - 1.8) + 2.7) * x * x; //Techicolor Cinestyle - almost identical to curve 1
#endif

// -- Curve 9 --
#if Curves_formula == 9
x = -0.5 * (x*2.0 - 1.0) * (abs(x*2.0 - 1.0) - 2.0) + 0.5; //parabola
#endif

// -- Curve 10 --
#if Curves_formula == 10 //Half-circles

#if Curves_mode == 0
float xstep = step(x, 0.5);
float xstep_shift = (xstep - 0.5);
float shifted_x = x + xstep_shift;
#else
vec3 xstep = step(x, 0.5);
vec3 xstep_shift = (xstep - 0.5);
vec3 shifted_x = x + xstep_shift;

#endif

x = abs(xstep - sqrt(-shifted_x * shifted_x + shifted_x)) - xstep_shift;

//x = abs(step(x,0.5)-sqrt(-(x+step(x,0.5)-0.5)*(x+step(x,0.5)-0.5)+(x+step(x,0.5)-0.5)))-(step(x,0.5)-0.5); //single line version of the above

//x = 0.5 + (sign(x-0.5)) * sqrt(0.25-(x-trunc(x*2))*(x-trunc(x*2))); //worse

/* // if/else - even worse
if (x-0.5)
x = 0.5-sqrt(0.25-x*x);
else
x = 0.5+sqrt(0.25-(x-1)*(x-1));
*/

//x = (abs(step(0.5,x)-clamp( 1-sqrt(1-abs(step(0.5,x)- frac(x*2%1)) * abs(step(0.5,x)- frac(x*2%1))),0 ,1))+ step(0.5,x) )*0.5; //worst so far

//TODO: Check if I could use an abs split instead of step. It might be more efficient

Curves_contrast_blend = Curves_contrast * 0.5; //I divide by two to give it a strength closer to the other curves.
#endif

// -- Curve 11 --
#if Curves_formula == 11 //Cubic catmull
float a = 1.00; //control point 1
float b = 0.00; //start point
float c = 1.00; //endpoint
float d = 0.20; //control point 2
x = 0.5 * ((-a + 3 * b - 3 * c + d)*x*x*x + (2 * a - 5 * b + 4 * c - d)*x*x + (-a + c)*x + 2 * b); //A customizable cubic catmull-rom spline
#endif

// -- Curve 12 --
#if Curves_formula == 12 //Cubic Bezier spline
float a = 0.00; //start point
float b = 0.00; //control point 1
float c = 1.00; //control point 2
float d = 1.00; //endpoint

float r = (1 - x);
float r2 = r*r;
float r3 = r2 * r;
float x2 = x*x;
float x3 = x2*x;
//x = dot(float4(a,b,c,d),float4(r3,3*r2*x,3*r*x2,x3));

//x = a * r*r*r + r * (3 * b * r * x + 3 * c * x*x) + d * x*x*x;
//x = a*(1-x)*(1-x)*(1-x) +(1-x) * (3*b * (1-x) * x + 3 * c * x*x) + d * x*x*x;
x = a*(1 - x)*(1 - x)*(1 - x) + 3 * b*(1 - x)*(1 - x)*x + 3 * c*(1 - x)*x*x + d*x*x*x;
#endif

// -- Curve 13 --
#if Curves_formula == 13 //Cubic Bezier spline - alternative implementation.
vec3 a = vec3(0.00, 0.00, 0.00); //start point
vec3 b = vec3(0.25, 0.15, 0.85); //control point 1
vec3 c = vec3(0.75, 0.85, 0.15); //control point 2
vec3 d = vec3(1.00, 1.00, 1.00); //endpoint

vec3 ab = lerp(a, b, x);           // point between a and b
vec3 bc = lerp(b, c, x);           // point between b and c
vec3 cd = lerp(c, d, x);           // point between c and d
vec3 abbc = lerp(ab, bc, x);       // point between ab and bc
vec3 bccd = lerp(bc, cd, x);       // point between bc and cd
vec3 dest = lerp(abbc, bccd, x);   // point on the bezier-curve
x = dest;
#endif

// -- Curve 14 --
#if Curves_formula == 14
x = 1.0 / (1.0 + exp(-(x * 10.0 - 5.0))); //alternative exp formula
#endif

   //Joining of Luma and Chroma                 
#if Curves_mode == 2 //Both Luma and Chroma
vec3 col = x;  //if the curve should be applied to both Luma and Chroma
color.rgb = lerp(color.rgb, col, Curves_contrast_blend); //Blend by Curves_contrast

#elif Curves_mode == 1 //Only Chroma
x = x * 2.0 - 1.0; //adjust the Chroma range back to -1 -> 1
vec3 col = luma + x; //Luma + Chroma
color.rgb = lerp(color.rgb, col, Curves_contrast_blend); //Blend by Curves_contrast

#else // Curves_mode == 0 //Only Luma
x = lerp(luma, x, Curves_contrast_blend); //Blend by Curves_contrast
color.rgb = x + chroma; //Luma + Chroma
#endif
//Return the result
color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif

/*------------------------------------------------------------------------------
[CROSS PROCESSING CODE SECTION]
------------------------------------------------------------------------------*/
#if CROSS_PROCESSING == 1

vec3 CrossShift(vec3 color)
{
vec3 cross;

vec2 CrossMatrix[3] = vec2[](
vec2(0.960, 0.040 * color.x),
vec2(0.980, 0.020 * color.y),
vec2(0.970, 0.030 * color.z));

cross.x = float(RedShift) * CrossMatrix[0].x + CrossMatrix[0].y;
cross.y = float(GreenShift) * CrossMatrix[1].x + CrossMatrix[1].y;
cross.z = float(BlueShift) * CrossMatrix[2].x + CrossMatrix[2].y;

float lum = AvgLuminance(color);
vec3 black = vec3(0.0, 0.0, 0.0);
vec3 white = vec3(1.0, 1.0, 1.0);

cross = lerp(black, cross, saturate(lum * 2.0));
cross = lerp(cross, white, saturate(lum - 0.5) * 2.0);
color = lerp(color, cross, saturate(lum * float(ShiftRatio)));

return color;
}

vec4 CrossPass(vec4 color, vec2 texcoord)
{
#if FilmicProcess == 1
color.rgb = CrossShift(color.rgb);

#elif FilmicProcess == 2
vec3 XYZ = RGBtoXYZ(color.rgb);
vec3 Yxy = XYZtoYxy(XYZ);

Yxy = CrossShift(Yxy);
XYZ = YxytoXYZ(Yxy);

color.rgb = XYZtoRGB(XYZ);

#elif FilmicProcess == 3
vec3 XYZ = RGBtoXYZ(color.rgb);
vec3 Yxy = XYZtoYxy(XYZ);

XYZ = YxytoXYZ(Yxy);
XYZ = CrossShift(XYZ);

color.rgb = XYZtoRGB(XYZ);
#endif

color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif

/*------------------------------------------------------------------------------
[COLOR GRADING CODE SECTION]
------------------------------------------------------------------------------*/

#if COLOR_GRADING == 1
float RGBCVtoHUE(vec3 RGB, float C, float V)
{
vec3 Delta = (V - RGB) / C;

Delta.rgb -= Delta.brg;
Delta.rgb += vec3(2.0, 4.0, 6.0);
Delta.brg = step(V, RGB) * Delta.brg;

float H;
H = max(Delta.r, max(Delta.g, Delta.b));
return frac(H / 6);
}

vec3 HSVComplement(vec3 HSV)
{
vec3 complement = HSV;
complement.x -= 0.5;

if (complement.x < 0.0) {
complement.x += 1.0;
}
return(complement);
}

float HueLerp(float h1, float h2, float v)
{
float d = abs(h1 - h2);

if (d <= 0.5)
{
return lerp(h1, h2, v);
}
else if (h1 < h2)
{
return frac(lerp((h1 + 1.0), h2, v));
}
else
{
return frac(lerp(h1, (h2 + 1.0), v));
}
}

vec4 ColorGradingPass(vec4 color, vec2 texcoord)
{
vec3 guide = vec3(RedGrading, GreenGrading, BlueGrading);

float amount = GradingStrength;
float correlation = Correlation;
float concentration = 2.00;

vec3 colorHSV = RGBtoHSV(color.rgb);
vec3 huePoleA = RGBtoHSV(guide);
vec3 huePoleB = HSVComplement(huePoleA);

float dist1 = abs(colorHSV.x - huePoleA.x);
if (dist1 > 0.5) dist1 = 1.0 - dist1;

float dist2 = abs(colorHSV.x - huePoleB.x);
if (dist2 > 0.5) dist2 = 1.0 - dist2;

float descent = smoothstep(0.0, correlation, colorHSV.y);

vec3 HSVColor = colorHSV;

    if (dist1 < dist2) {

float c = descent * amount * (1.0 - pow((dist1 * 2.0), 1.0 / concentration));

HSVColor.x = HueLerp(colorHSV.x, huePoleA.x, c);
HSVColor.y = lerp(colorHSV.y, huePoleA.y, c);
}
else
{
float c = descent * amount * (1.0 - pow((dist2 * 2.0), 1.0 / concentration));

HSVColor.x = HueLerp(colorHSV.x, huePoleB.x, c);
HSVColor.y = lerp(colorHSV.y, huePoleB.y, c);
}

color.rgb = HSVtoRGB(HSVColor);

color.a = AvgLuminance(color.rgb);

return saturate(color);
}
#endif




/*------------------------------------------------------------------------------
[TV COLORS EMU CODE SECTION]
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
SimoneT NTSC TV colors emulation 1.0 Shader
Copyright (C) 2016 SimoneT - [email protected]
Credit to SimoneT.
------------------------------------------------------------------------------*/

#if NTSC_TV_EMULATION == 1

// conversion from NTSC RGB Reference White D65 ( color space used by NA/Japan TV's ) to XYZ
vec3 NTSC(vec3 c)
{
vec3 v = vec3(pow(c.r, 2.2), pow(c.g, 2.2), pow(c.b, 2.2)); //Inverse Companding
return v*mat3(
0.6068909, 0.1735011, 0.2003480,
0.2989164, 0.5865990, 0.1144845,
0.0000000, 0.0660957, 1.1162243);
}

// conversion from XYZ to sRGB Reference White D65 ( color space used by windows )
vec3 sRGB(vec3 c)
{
vec3 v = c*mat3(
3.2404542, -1.5371385, -0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434, -0.2040259, 1.0572252);

//Companding
v.r = (v.r > 0.0031308) ? ((1.055 * pow(v.r, (1.0 / 2.4))) - 0.055) : 12.92 * v.r;
v.g = (v.g > 0.0031308) ? ((1.055 * pow(v.g, (1.0 / 2.4))) - 0.055) : 12.92 * v.g;
v.b = (v.b > 0.0031308) ? ((1.055 * pow(v.b, (1.0 / 2.4))) - 0.055) : 12.92 * v.b;
return v;
}

// NTSC RGB to sRGB
vec3 NTSCtoSRGB(vec3 c)
{
return sRGB(NTSC(c));
}

// Ported from SimoneT TV colors emulation 1.0 Shader
vec4 TvColorsPass(vec4 color, vec2 texcoord)
{
color.rgb = NTSCtoSRGB(color.rgb);

return color;
}
#endif





/*------------------------------------------------------------------------------
[MAIN() & COMBINE PASS CODE SECTION]
------------------------------------------------------------------------------*/

void main()
{
vec2 texcoord = gl_TexCoord[0].xy;
vec4 color = texture2D(OGLTexture0, texcoord);

#if USE_FXAA == 1
color = FXAAPass(color, texcoord);
#endif

#if GAMMA_CORRECTION == 1
color = GammaPass(color, texcoord);
#endif

#if PIXEL_VIBRANCE == 1
color = VibrancePass(color, texcoord);
#endif

#if BLENDED_BLOOM == 1
color = BloomPass(color, texcoord);
#endif

#if SCENE_TONEMAPPING == 1
color = TonemapPass(color, texcoord);
#endif

#if USE_CURVES == 1
color = CurvesPass(color, texcoord);
#endif

#if COLOR_CORRECTION == 1
color = CorrectionPass(color, texcoord);
#endif

#if CROSS_PROCESSING == 1
color = CrossPass(color, texcoord);
#endif

#if COLOR_GRADING == 1
color = ColorGradingPass(color, texcoord);
#endif


#if NTSC_TV_EMULATION == 1
color = TvColorsPass(color, texcoord);
#endif


gl_FragColor = color;
}


How it looks

PSX
Truck Scene
http://pho.to/AhTsk/uh/original

Old PC

Truck Scene
http://pho.to/AhTsk/up/original

Costa del Sol
http://pho.to/AhTsk/x8/original

Kalm
http://pho.to/AhTsk/3g/original

New PC

Truck Scene
http://pho.to/AhTsk/g4/original

Costa del Sol
http://pho.to/AhTsk/os/original

Kalm
http://pho.to/AhTsk/cq/original



Note:  The above are the shader + modified light exe function.  PS... I have slightly altered the contrast in the above shader since these screenshots were taken, as I felt it was too great.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: nfitc1 on 2017-05-18 04:27:45
As Luksy has posted the PSX calculates and renders the colors differently.

I think it's more basic than that. I think it's the limitation of the composite video connection. Since it can't do better than 240i and most CRTs do their own blending (though not necessarily on purpose) it takes more color variation to make an obvious contrast. As such, the backgrounds were designed to be oddly blocky with random flecks of color sprinkled in to make a smooth appearance despite the source's jaggy appearance. The designers of the PSX's GPU knew this and probably force each pixels' color to slightly influence the ones next to it. So to compensate, set designers have to be creative to cause realistic gradients. The source would look dirty, but the interpretation looks smooth because it can't show each pixel in its true color.

I noticed this a few years back when I got a video adapter for the PS2 that was both composite and component in the same cord. The composite looked smoother because the resolution was lower and made my set do some interpolation. When I switched to component (which maxes at 480p) I immediately regretted my decision as all the color artifacts came shining through and less interpolation was done on the image.

Now we play games at 1080p and up so lots more time is spent on making 32-bit colored textures at 4K resolutions so more accurate gradients can be achieved.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Sega Chief on 2017-05-18 15:29:30
Either my Notepad isn't set up properly-

Edit: Never mind, it was Notepad. Copy-pasting the code into Notepad++ retains the proper formatting.

Edit2: It looks great; world map doesn't seem as dreary and as an added bonus the backgrounds don't seem as messed up now either; one thing though is that oranges come through a bit too strong.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-18 17:56:31
Is your monitor calibrated? If so, check vibrance option. And contrast
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Sega Chief on 2017-05-18 19:19:58
Is your monitor calibrated? If so, check vibrance option. And contrast


Good thing you mentioned, a while back I set the monitor up to display certain colours more vibrantly cause it looked very washed out on normal settings. That's probably what it was.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-18 19:55:39
Finally, if you really want the PSX experience, a Gaussian blur needs adding to the above shader.  I like 0.5, but 1.0 pixels in Adobe makes it look very close at the expense of less detail (like the PSX)

Observe:

http://pho.to/AhWQH/ma/original

The models, of course, are still too rendered to fit with the background.  That's why the filtering for 3d objects needs to be disabled in aali's driver (like Steam allows). I'll see if JWP knows how.

Also, PSX is in 4:3 AR. For some reason, 1280 * 960 does not seem to give the exact same result as Mednafen does. Checking.


edit

http://forum.fobby.net/index.php?t=msg&goto=3778&
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-18 20:13:21
Looks a bit like the ps4 images I've seen. BTW. there is a problem with try the new light setting. As it looks now only the body and the head gets the light from above, but arms and legs get the light from below.  :|
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Covarr on 2017-05-18 20:14:58
Finally, if you really want the PSX experience, a Gaussian blur needs adding to the above shader.
I mean, if you really want to be authentic to how the art looked in the '90s, you'd need a CRT shader and/or a NTSC (or PAL) signal shader. The emulation community loves that stuff. I'm not sure it's really worth the effort, though.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-18 20:19:48
True.  The gaussian + shader + disabled filtering of 3D will be very close though.

@Kal. Yup. I'm aware it ain't perfect shading and probably never will be.  I think the entire thing would need recalculating, but I'll keep on looking. They've decided to shade this way.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-05-18 21:15:12
Tbh the blurriness in that last image is just butt-ugly. I just booted up my PS2 and did a comparison, and the PS2 has a much sharper image. It is, of course, slightly blurred when compared against a completely unfiltered image, but only very slightly. It is so slight, in fact, that I'd say it's more or less perfect, as it doesn't smoothen out any details, but it smoothens out a little of the pixellation. If you're curious, I used a Component cable and a modern display, so it's not a CRT or composite signal thing either.

I did take a couple of screenshots (http://i218.photobucket.com/albums/cc143/Shadow_Saix/WP_20170519_00_01_31_Pro.jpg) for you to compare as well, but I don't think they'll be much useful since I don't have a capture card, and had to take them with my phone camera. So ignore the stupid blue tint, that doesn't belong there.

Either way, a postprocessing effect that destroys any and all detail is certainly not the way to go. If anything, that would be a major downgrade.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-18 21:22:14
That is more or less exactly what mednafen gives out.  You have to compare it like for like.  A PC is never going to give you the PSX look, as Covarr said. And we can't really emulate it.  But Mednafen is about as close as you're likely to get for a PSX game output onto a screen (minus the scan lines you can artificially add).  Output from a real PS with cables has already done things that no shader is probably capable of.

The gaussian + shader looks almost identical for me when compared to Mednafen (I prefer 0.5 pixel Gaussian or no Gaussian at all - but that's because I think the PSX is inferior to the PC when it comes to the blurriness and all the dithering).

To me your screen shot looks just as bad in other ways (dithering / scan line / jagged).  Can you get me one in Kalm in the same place I took the Mednafen shot?  I can put them all along side then too.

Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-05-18 21:39:38

To me your screen shot looks just as bad in other ways (dithering / scan line / jagged).  Can you get me one in Kalm in the same place I took the Mednafen shot?  I can put them all along side then too.


Yeah the jaggedness and lines going here and there was definitely my bad, the display was configured like bollocks so it stretched the image one way and shrunk it the other way. Dithering, however, is unavoidable, simply because it is a PS1 game. Still, the fact that the dithering is visible through even a shitty screenshot, is a testament to how much more accurate the Component signal is next to that old PAL/NTSC crap. :P

I can get a Kalm screenshot too, but it'll probably take a couple hours because I need to fiddle around with save files and get them on the Memcard.

Update: Well, here it is. This time around, I decided to use the screen (HDTV) I always use for pretty much everything since the other one turned out to be a big hunk of $#!!.

Now, this picture (http://i218.photobucket.com/albums/cc143/Shadow_Saix/WP_20170519_01_31_55_Pro.jpg) will only tell you so much, but it confirmed my gut feeling. The pixellation is very much there, but then again so is that dithering, because, well, HDTV. Also, using an external camera to make screencaps for this sort of purpose is bad since each screen has adjustable sharpness and brightness and all that (although mine are set to default.) It also adds that blue tint and the picture is much brighter than the image itself was.

So, just for reference, I wanted to see what another emulator produces. With a color depth of 32 bits, there is obviously no dithering involved, and no external camera involved. Which results in this. (http://i218.photobucket.com/albums/cc143/Shadow_Saix/ff7-029951.png)

I may have been wrong the first time. Neither PS2 nor ePSXe look like they make an effort to blur the image in any way, unless instructed otherwise. The blurring is not part of the game, it's part of the displays of that era. Mednafen might be simply trying to replicate that, because it's often considered part of the nostalgic experience. I know the GPU plugin I use with ePSXe has an option for fullscreen smoothing, which produces an almost identical result, but if it's disabled, it doesn't blur anything.

What do you make of this?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-19 01:00:43
You may be right. Mednafen may be adding something... but I am not sure why it would when it's supposed to be direct.  Perhaps it does (it could be the bilinear filtering).   Either way, we can safely say that gaussian as an option would be ok.  Personally, I'd never use it.  I much  prefer the output from the tweaked shader I posted on its own. I think that beats the lot, tbh.

Do you think that needs any more work?  Any thoughts on it?

Edit.

Yeah, it's bilinear filtering with mednafen.  I thought I'd disabled it.  It looks awful without it, though.  I think we have a winner then.... it's the shader alone. No blur.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-05-19 01:40:07
Gaussian could work wonders if it's applied in a very, very small dose, but any more and it's just going to make the details vanish. Also, it should be configured to avoid blurring 3D geometry, because it does slightly negate what you gain from using a high internal resolution. It would make battles especially look as if you'd been drinking for 14 hours straight.

I haven't even tried out the shader yet, but if it breathes life into the colors, then why the hell not.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-19 20:37:05
fr_e field bug.

I think everyone is about ready to sign off on this problem. The Diamond Weapon shadow that traverses the screen in the PSX version seems to have been deliberately disabled in the PC version.  Placing it back, even by altering tiles, has failed (Ilducci and Spy__Dragon tried). It could well be that this particular effect cannot be made to work due to some sort of limitation with the PC field files. Importing a working field from PSX doesn't work either, because Makou Reactor cannot properly import field backgrounds.  Even if it could, it again may be that PC field format doesn't allow for this layer to work properly.

So, I've started thinking about other ways to add the effect back into the game. For me, the only good way would seem to be adding the shadow shape to a file and using that in-game (a hrc / p file, like the Great Glacier map).  Transparency could be added using the field model function. Of course, I'd need someone else to make this.  Do you think you could do it, Kaldarasha?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-19 21:24:18
At the time I read it I got the idea to use a model object to solve the problem.
I have an already textured plane from my drop shadow tests. I could use that and add a texture with the shape of Dimond to it.

Edit:
How's that?
(http://i.imgur.com/No4fYnZ.png)

Blending is on by default.

Edit2:
https://mega.nz/#!3d0QDZjC!mI3i1s_FwcXH2AFcZCr1OkvMbnXhtSq2CMcNrfo9__I
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-19 21:49:29
Since the shadow cast is supposed to be part of it from a distance, this is how it should look (note only black with outline is needed... since I can make it move right to left)

>>

https://www.youtube.com/watch?v=93JwjEcRyLU&t=08m56s

8:56

It's a very simple shape.  Straight on one end (since that end will never be seen),  and a curve shape on the other end.  Width 512 pixels.  Height 256.

Then I just make it move right to left... which simulates Weapon moving.

In fact, I could probably record the psx game and send you the exact shape.

Edit.  Actually, it has a shape on both sides, but on PSX version's release you never see the left side (maybe even because of bad script programming).

Here is the final shape:

Left
http://pho.to/AhazS/e3/original

Right
http://pho.to/AhazS/6y/original

So, that's what I need.  That shape. 512 pixels across. A rectangle, starting with the left side curve, ending with right side curve. 224 pixels high.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Sega Chief on 2017-05-20 02:16:57
You could maybe just fade the tint of the screen to be darker then fade it back to normal as a replacement effect if the shadow thing doesn't work out.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-20 02:27:59
That would be plan C...  but it would suck not to have a good shadow.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-20 06:34:31
I'll also be adding dialogue issues, but only if it's an original Japanese error.  For example, chocobos having belly buttons :P  Charlie Beer discovered one recently in his proof check of the Japanese...  Aerith isn't told that Tifa's bar is the Seventh Heaven, but later knows its name.  I've added exposition earlier to compensate.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Sega Chief on 2017-05-21 01:15:07
I'll also be adding dialogue issues, but only if it's an original Japanese error.  For example, chocobos having belly buttons :P

But do they have ears?  ;D
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-21 11:09:08
Myst6re has informed me that layer 3 of fr-e is special because it uses transparency. It doesn't seem to be right in the field file (PC) and even if it were, I'm betting the engine wouldn't display it right, unless aalis driver fixed it. I think were forced to use char.lgp with the shadow

And yes, they do have ears.  ;D
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-05-24 11:39:28
Seems that the layer is really broken. Even Palmer shows only a black layer. Also, compared to kuro_1 the shadow has a strange set of functions, maybe the game should render the shape in real time?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-24 11:45:35
The only way to fix this is by putting a shape into char/lgp and using it in field (using makou to add it).

A page or so back I added the shape needed.  If it's possible to create that then I'll have a go at fixing the field that way.  The layer method isn't going to work.  The current PC field has had the background layer disabled due to issues with the transparency effect - and I don't think the engine supports transparent layers in the PC port.

So we're stuck with a workaround.  Luckily the only field in the game that uses transparent layers is fr_e (rootmap does too, but is debug menu only).
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-05-24 14:34:27

I don't think the engine supports transparent layers in the PC port.


Doesn't it, though? I imported this field's full background (http://i218.photobucket.com/albums/cc143/Shadow_Saix/ff7%202017-05-24%2017-17-05-19.png) from the English PSX files, and the blue bubbles are as transparent as they should..

Then again, it may be a different thing altogether. There's the fact that in this field (startmap) the transparency is on Layer 1, which is the foreground. In fr_e it is Layer 3, which is commonly an animated layer, so I'm not sure if these two instances are even remotely related to each other.

In any case, importing the PSX layers for fr_e using Makou gave shitty results at best, so it's probably not worth it to even try fixing it. Using a flat square model with a transparent shape textured on it is the easiest way to do it, and will look much better, too. I fully agree with that idea.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-05-24 14:43:29
Makou has serious issues with Z order importing and fails on some backgrounds.  This one could be one of them - or it might be transparency related.  I agree that layer 3 may be the issue that wrecks the fr_e background in this case.  Perhaps that's where the port falls down.  But it's nice to know it works for rootmap.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-16 03:41:53
Party member placement is not updated correctly from PHS - and not at all from the Order screen.  I don't know if that's the case in PSX.

Cloud
Tifa
Barrett

Cloud has ID 0
Tifa has ID 2
Barrett has ID 1.

The vars (Bank 2 [9], Bank 2 [10] and Bank 2 [11]) should hold the following:

0
2
1

Which they will be if you use PHS and completely change the party.  But if you swap the characters about in the order screen, the vars will remain 0,2,1. So if you then have this order:

Cloud
Barrett
Tifa

The vars will still be 0,2,1.  At cutscenes, this means that the game will behave as though Tifa is party member 2 and not party member 3. The PHS menu also suffers with a problem.  If you completely change the party, the vars will be updated properly. But if you swap out only one member, the vars are not updated properly either. So the cutscenes will again display members out of place.

The vars Bank 2 [9], Bank 2 [10] and Bank 2 [11] are ALWAYS supposed to mirror 4F8, 4F9 and 4FA of the savemap (which are updated with Order option also).  At the moment, this is not happening.  I should be able to add this fix for R06.


edit.

Because Cloud can be moved in the order screen, it messes this up. So the order screen not changing vars may be deliberate.  Still, PHS is not updating properly when swapping out one char. That's definitely an issue.

edit 2.

Because the party leader isn't locked to the first slot, they've basically created some sort of crappy update procedure to make sure the party leader doesn't end up being placed in the vars reserved for member 2 and 3.  What they should have done is lock party leader to the first slot.

edit 3.

An easy fix is to simply make party member 2 always equal the member that is highest (ignoring party member 1, who is leader). That way, if order is

Tifa (2)
Cloud (0)
Barrett (1)


Tifa will be member 2 and Barrett will be member 3.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-16 10:07:17
Also, wtf is going on in trnad_53 Cloud Script 3?

Looks like not only left over code - but actual code still in use that displays the location in a dialogue box.  Something that somehow doesn't show up in actual play?  Anyone want to find out why while I'm busy?

Actually...  this map isn't being used at all. It's only ever seen via the debug menu.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-21 22:37:24
Field error [fixed] nvmin1_2:  Pointed out to me by Charlie Beer... who has a good eye.  He noticed that the brother and sister - who later end up wearing  black cloaks - are the wrong size in PC version.  I've checked Japanese field v PC - and he's absolutely right.  They should both be size 256.  One of them is 512.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-22 00:33:21
Having a nice chat with Charlie Beer

Quote
sidenote, do you have any idea what tifa is supposed to be doing in this map when she does that weird ass animation
https://youtu.be/29euU5fNqk8?t=369

Quote
Daniel Burke: let's see
No i dont
i dont think she is meant to stay there like a lemon at any rate
also sinin2_1 you will see a "memory" dialogue

Quote
Anonymous Dinosaur: she's lemoning so hard and it bugs the shit out of me

Quote
Daniel Burke: that is erroneous and v likely a left over message from the script programmer to himself
I'll have to look into it
i dont think she is meant to do that

Quote
Anonymous Dinosaur: she does that animation twice, then, and when she picks up the Premium Heart
its so weird

Quote
Daniel Burke: It's not the first time either that that happens in regards to left over script.  At Junon, the programmer left in "1 2 3 "  set with a var - to tell him the timing in game as we was struggling to work out why Cloud wasn't lining up right and so on.  I fixed it.
he*
in gme you literally see "And... 1" "and...2"  "and.... 3"  Poor Baskett had no fucking clue what it was

Quote
Anonymous Dinosaur: lmaooooo

Quote
Daniel Burke: also the "switch on" dialogue in the reactor is also a debug message
in the elevator

Quote
Anonymous Dinosaur: that makes so much sense

Quote
Daniel Burke: they forgot to take it the fuck out
usually debug messages are removed.  Like when Barrett comes running into seventh heaven.  The dialogue is hidden "THUD THUD THUD sound should come in here"

Quote
Anonymous Dinosaur: makes you realise how much less proofing these games had

Quote
Daniel Burke: well they were rushed and the testers obv thought that "switch on" was intended
lmao

Quote
Anonymous Dinosaur: ahahaha
oh well
it has now been solved years later

Quote
Daniel Burke: also fun note, the high mid low game at the gold saucer was meant to have better odds... but the programmer made a common mistake with probability.  He didn't factor in how it works in those cases and assumed that overall odds would be like 400-1
he made it 3709-1 to beat the game
as a consequence, no tester ever beat it and so if you ever do there is a bug leading to an invisible final opponent.
the game is meant to end after the superman
luksy and i fixed it

Quote
Anonymous Dinosaur: amazing

Quote
Daniel Burke: in fact when I noted this issue... a member of Qhimm made the EXACT SAME mistake
that the programmer did

Daniel Burke: http://forums.qhimm.com/index.php?topic=12667.msg176030#msg176030  this guy thinks i'm being sarcastic. I'm not.
Erzfreund calculates it properly using math further down

Quote
Anonymous Dinosaur: fucking hell

Quote
Daniel Burke: It's not as simple as it first appears eh ;) 
In any case... changing the rounds to 5 instead of 10 fixes the odds to around 300-1

Quote
so you can actually win the game now?

Quote
Daniel Burke: yeah.  Odds are good and also last opponent is correctly last opponent
If you played the fight game 100 times, then you'd beat the Girl ~66 times.
------------
Not true.. you might beat her 0, might beat her 100 ;)

<< thats the error in thinking
that because the odds of winning 10 rounds is 66% that means you will always win 66%.  That isnt how it works.  I mean, it's theoretically possible to win ALL 40 rounds without losing  a point
and to lose all 10 in a singl round

Quote
Anonymous Dinosaur: yeah thats like...... fundamentally how probability works

Quote
Daniel Burke: If you played the fight game 100 times, then you'd beat the Girl ~66 times.
This is only correct of course if you played a million times...  then it will be much closer to 66%
100 times.. forget it.

Quote
Anonymous Dinosaur: truly a beginners mistake

Quote
Daniel Burke: yes!  script programmer should have gotten off his fat arse and walked across to ken narita and asked him

Quote
Anonymous Dinosaur: and the programmer literally programmed that faulty logic into the game hahaha

Quote
Daniel Burke: hiroki was the script programmer from what I can see
yeah!
haha
when i was a kid i could never beat the 3rd opponent.  To beat 1 2 and 3 has odds if i recall of around 400-1
beating 4th too is 3709-1
So i knew something was amiss

Quote
Anonymous Dinosaur: same, i tried and tried and tired
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-06-22 07:22:52
The animation is correct. Zax Cloud and Sephiroth talk about things of which she has no understanding, so she gets bored and starts playing with the water. It might had looked better if she would kneel down but then she would probably out of the scene. This behavior is also interesting regarding the true Cloud in many ways. If this would be the real Cloud in that conversation, Tifa wouldn't do that but watch him carefully. It's also interesting that she does that in his told story while the Cloud we see doesn't pay much attention to her. This might be over interpretation, but it could be a hint that this is a memory from the true Cloud, who has followed the whole scene and has noticed it.

Edit:
I have currently played the snowboard minigame and realized that the balloon animation is broken on PC.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: nfitc1 on 2017-06-22 14:41:29
I always thought she does the anime face fault (http://tvtropes.org/pmwiki/pmwiki.php/Main/FaceFault), just not so animatedly. Cloud says "mysterious power" and Sephiroth just laughs and Tifa collapses because she thought it was a stupid thing to say too. The timing of this animation is either intentional or poorly executed.


As for http://forums.qhimm.com/index.php?topic=12667.msg176030#msg176030
I could revive that and might be able to give a better equation to the odds of the original script. If you want, that is.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-22 15:14:04
I fixed the odds by simply making the rounds first to 5 instead of 10. This slashes odds to around 300-1 to beat the entire game. I am not sure you have interpreted that scene right, kal. In the real cloud version, he is wearing his helmet and she doesn't fi d out its him until the very end in the reactor
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-06-22 15:50:51
I mean that the real Cloud had seen everything from the distance. It might that what we see, is something from his own memory. Though, I don't believe that this is the case, since Nomura said in an interview that Clouds' mystery past was invented at the very end of the project. This means that they probably didn't meant that this soldier should be Cloud in the first place. Well, who knows? I simply wouldn't remove it from that scene but changing it to another more fitting animation.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: August on 2017-06-22 23:33:31
As CB mentioned, Tifa also plays that animation when she picks up the Premium Heart (and we can see more clearly that she's almost touching the floor), except that the Mako fountain scene gives her outstretched arm a prolonged twirling motion. In the previous scene she's standing outside the fountain, close to the water's edge, and does not move during the next scene except to turn towards the fountain and bend down. I interpret this scene to be Tifa idly playing with the water at her feet, captivated by the fountain more than the Soldiers' conversation.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-23 00:07:18
I agree.  It does look a little bloody silly, though. Haha.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-23 00:20:59
@Kal

Charlie put me onto this.  Check sininb2.  Cid's feet are wrong because he is using Cloud's animations.  What is he supposed to be using for those?
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: August on 2017-06-23 00:30:23
I agree.  It does look a little bloody silly, though. Haha.
Yes - one might well ask why she has a "pickup" animation like that in the first place, while Cloud's is the more sensible kneeling variety. Let's just say that methinks someone at Square had a bit of fun animating Tifa. ;)
Title: .
Post by: [email protected] on 2017-06-25 11:05:36
.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-25 12:31:00
The mansion theme should be fixed with Anxious Heart.  I'm sure I've had this convo at least 5 times. Please check for me. We definitely discussed the other bugs. They are fixed.  :)
Title: .
Post by: [email protected] on 2017-06-25 17:15:44
.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-25 17:26:43
The entire audio module has been replaced in R06 and now also uses psx effects. So those issues you raised are all fixed too. They aren't listed there. Nearly all will be caused by the faulty module which has been replaced.  But I'll add the ones you noted.  The aero one may be a scene.bin battle problem if it isn't the audio module.
 
Please check Anxious Heart for me and make sure that the Mansion music is fixed. I'm sure I went through this question 2 years ago.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: August on 2017-06-26 00:46:02
Here's a funny one: if you access the menu while you are moving in the buggy, the menu sfx are all higher pitched. It appears the buggy simply has the one engine noise that is pitched up when accelerating, but it affects all sfx across the board.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-26 00:49:32
I didn't know it changed pitch - that's something I am so far not emulating - but when it gets added, it shouldn't cause this issue.  It uses a completely different channel.  I bet this didn't happen in PSX.
Title: .
Post by: [email protected] on 2017-06-26 10:34:04
.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: nfitc1 on 2017-06-26 12:19:05
It definitely happens on the original PC version. I remember noticing this a long time ago. I did it just for fun most of the time.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-27 01:02:19
I'll add these to the database when I get time.  Right now... got bigger fish to fry by fixing them all!
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-06-27 02:33:29
Aeroga (and Supernova) both use effect 00163, which, as Cicciolo pointed out, is wrong in PC original. This is an error in audio.dat.  163 is accidentally the same as 162. This means there will be a totally wrong effect in Supernova too lol and other places.  But since I worked entirely off the PSX version, this effect has been fixed.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Kaldarasha on 2017-06-27 10:24:15
Phew, the bug finding never stops. On PC Cloud use a wrong animation at the end of the G-Bike minigame.
PSX
https://youtu.be/a3R8-qwg81E?t=127

PC
https://youtu.be/mhHrFhAZSFA?t=170

From what I can see on YouTube the wrong animation is never used on psx, so I will simply change jgaa.a to igaa.a and igaa.a to jgaa.a just in case it is used somewhere.

Regarding Cid I assume the best way to fix it is to update the model loader with corresponding animations of him. I'll see if I can make it ready for you.
Title: .
Post by: [email protected] on 2017-06-27 11:36:38
.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-06-27 20:36:30
On a side note, has anyone noticed a weird bug with Bizarro Sephiroth duplicating/triplicating his model during the boss battle? I'm not sure if i could replicate it though...

Well, I mean he is placed five times in the formation to give the illusion of five targets, but the four additional models are invisible by default. I guess some sort of script error could cause them to become visible. Typically something you'd see in mods developed by inexperienced modders, but I've literally never seen it myself, ever.
Title: .
Post by: [email protected] on 2017-06-27 21:23:05
.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: nfitc1 on 2017-06-27 22:19:52
I do vaguely remember this happening once on my PC copy way back when. I have no idea how to reproduce it, but it probably has to do with reviving parts. The idle animations are out of sync after some actions.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: August on 2017-06-30 23:58:23
The sfx for FMVs in Bugenhagen's laboratory don't play correctly. In boogdemo.avi only a few effects are played and in boogstar.avi they don't play at all. I checked the Database but this seems to have been overlooked. I've found some videos that show the same results as my playtesting.

psx: https://youtu.be/Sf82Mka39Eo?list=PLD305DAD36259178E&t=252

pc: https://youtu.be/yiq9b2X7RgY?list=PLvv1mA3UKy9PD2JcrlP98HMgqH9KP5H_u&t=531
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-01 15:58:05
The effect problem has been noted before by Sega Chief, but we didn't reach any conclusion.  This *should* be fixed with my module replacement, because it again supports multiple effects from field and all calls from field are heeded.  The only way this won't be fixed at the moment is if the field code itself is broken, which I doubt.  Thanks for clarifying it.

The bug report has been filed as fixed.

As for Bizarro...  I am going to file it as a bug.  There likely is 3 models loaded into battle due to the party being able to attack Bizarro from left right and front. I dunno if this is a PC issue alone.  Sega Chief may be able to find a bug in the AI. Or it could be a porting issue.

@Kal.  I will check G-bike and add it to the Bug Database.

@August, I have added the fade issue to the database.  I am not sure whether I already fixed it in R06.
Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-02 04:46:25
I'm redoing my sound approach. Instead of taking over akao main function - I'm just gonna do what I should from the start and take over the functions it eventually uses.  That way, I don't need to continually cover bases twice. Of course, this wouldn't need to be done if all the programmers used akao wrapper, but they didn't.  All my main functions are done.  I just need to work out exactly which functions are being called and take over them.  Disable any that are to do with starting /ending threads and so on,  since those aren't going to be needed.

Title: Re: [FF7PC] The Bug Database - post bug reports here
Post by: Ansem on 2017-07-03 20:06:40
I couldn't find this in the database, so just to make sure; has the Soldier First and Second classes' multi-slash attack been fixed? It was always broken in the vanilla game, since the enemies' animation scripts for that attack are incomplete.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-05 02:25:30
That's one for Kal and Sega Chief.

in other news.... Akao field wrapper is incorrect with PC version.  Maybe also PSX.  It only allows one byte instead of at least two for all transition Time parameters.  So when the snowboard game (for example), sets the clapping sfx to fade out (at the end of a winning time) using the wrapper, instead of 12C (300) / 60 = 5 second fade out, you will get 2C (44) / 60 = 0.73 seconds. 

This is a huge oversight by the porting team or original team. It's also easily fixed.

I very much doubt this is a mistake in the original game.  Something tells me they'd have realized that all their fade outs were being reduced to a maximum of 255 / 60 = 4.25 seconds. And I'm sure that clapping sfx did indeed fade correctly in psx.

Quote
213.SetEffect [Channel 4, Balance 64, 00441 [SB - Clapping, looped].ogg]
213.SetLoop [LoopStart 200618]
213.SetVolume [Channel 4, Volume 127]
--------------------------------------------------------------------------
214.SetVolumeTransition [Channel 4, TargetVolume 0, Time 5000]

That's better, no?  5000 because I convert to ms for use in bass.dll.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Sega Chief on 2017-07-05 13:35:08
I couldn't find this in the database, so just to make sure; has the Soldier First and Second classes' multi-slash attack been fixed? It was always broken in the vanilla game, since the enemies' animation scripts for that attack are incomplete.

The animations themselves function, they just look a bit choppy. Soldier 1st uses the first step of 4x-cut instead of the normal 03 slash animation for his physical attack which is why he ends up standing very close to the player party after the attack; like Hojo's combo, only the fourth attack 'returns' the actor to their starting position.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Ansem on 2017-07-05 17:00:37
The animations themselves function, they just look a bit choppy. Soldier 1st uses the first step of 4x-cut instead of the normal 03 slash animation for his physical attack which is why he ends up standing very close to the player party after the attack; like Hojo's combo, only the fourth attack 'returns' the actor to their starting position.

I took a gander at the AB file. 03 is definitely meant for the normal attack, and it does function as intended. 4xCut uses script 06, which uses different anims for delivering the attack, but it ceases all actions after the first slash because there is an EE right after the animation. EE returns the actor to Idle state, so the attack is cut short and he doesn't return to original spot either  (The EE is there after the other slashes as well.)

This is an easy fix tbh. Just need to clean up the garbage that's stopping the script from executing completely, and add an E5 right before the last EE so the enemy returns to his correct position.

Edit: Actually, the E5 is already there where it belongs. Only some cleanup is required.

Edit2: And it is done (https://drive.google.com/open?id=0B9fTgwq2DUJQLS1FakxMRmJBV2c). Took me 5 minutes to do it, lol. Do test it out though, because I can't at the moment.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-05 21:16:09
Nice.  You get a credit in The Big Bad Bug Database.  Oh, what an honour!

Edit.

Was this present on PSX?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-07 05:43:21
Comet 2 sfx are being chopped off early because of the command to stop at 5A44D6  and 5A44E5. Nopping these will fix the issue, but I am uncertain if doing that leaves resources.  NFITC1 or someone may know more about that.  These multiple effects do seem to use threads for the audio (I think they use the effect ID as a parameter for the thread ID.  There is also a second parameter, usually of 0F  - but I have no idea what that does).

I didn't notice any memory leaks though.

It would be nice to see how the PSX version worked internally for these... perhaps they even had a fade out.   It won't matter with version of the audio module.                 
         
Quake 3 may suffer with a similar issue in that the graphic effect is terminated early. I will check.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-07 10:36:24
I didn't realize Music Pan and Music Pan Transitions were actually ever used. This will be reinstated with The Audio Replacement. Looking at the field code in Makou, it seems it uses 2 byte values this time, rather than one.  So Left is 0, centre is 0x4000, and right is 0x7FFF. Effect balance is 0, 0x40, 7F.  Unless Akao2 causes some sort of mess... but I doubt it.

Also seems that there has been a miscommunication somewhere with the sound programmer / design team / field programmers... because although akao2 should allow for 2 byte time values, as I said previously this isn't the case with the hard code, which has accidentally left only one byte being used. I am still not sure if this is the case in PSX, but I'll be testing soon. Some of the field programmers have kept to a one byte maximum value for time intervals in field (indicating they've been told that's the limit)... but not in cos_btm2 for example... where you'll find a music transition of 500. If the akao wrapper is broken in PSX, this fade will be totally broken too.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: nfitc1 on 2017-07-07 15:24:45
As for Bizarro...  I am going to file it as a bug.  There likely is 3 models loaded into battle due to the party being able to attack Bizarro from left right and front. I dunno if this is a PC issue alone.  Sega Chief may be able to find a bug in the AI. Or it could be a porting issue.

The three different sides are different formations. The game will decide to angle Bizarro based on the formation it's loaded in. The question is can this be reproduced in the angled formations? I have never switched parties during that battle so I don't even know how the mechanics work.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Ansem on 2017-07-07 15:59:58
Was this present on PSX?

The Soldier animation bug? Yes.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-08 06:15:49
I've just tested the PSX version.  Music panning functions are disabled there too. So although field script does exist for music panning including transitions, they can never be executed in PSX or PC. And that's probably a good thing looking at the field script... there's a few entries there that look to me to make no sense at all.  I guess that's also why the values are 0, 0x4000, 0x7fff... because they never had to change them to conform to the correct one byte standard (in fact there are a few correct one byte pans in the script too!).

I will allow the functions to be used with my dll, but they'll need to be enabled with an opinion in the ini.

Akao 0xDA IS used in PSX though. It resets the music tempo to 0. I think it's rather redundant, because normal tempo setting can reset tempo to 0. 0xE4 doesn't seem to be used at all from what I can see, despite it being called a few times (mainly after minigames).

Tempo max value is 0x7F (not 0x40 as I previously reported.  The snowboard minigame does stop at 0x40, but the coal train part of the game will speed music up to the maximum).
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Kaldarasha on 2017-07-27 08:08:57
So I have just finished my rework on Cid and by the time I tested the new model I found a very minor bug in Mideel, many of the NPC have no colusion and you can literaly run through them.

I will now see what I can do regarding the shadow of diamant. However I have a few concerns, while Dan has defined the size he needs I have no way to exactly create them since it's a 3d object which can have any demision while using a texture with the exact size he asks for. Another issue I see is regarding the scene itself. Diamond is moving away from the party in the  FMV before and after, while in the specific scene the shadow is moving to the right (to the left from the player's view) which is actually not correct. This means the shadow has to move down if we follow the movement of Diamont. That's why I made a full shape shadow to test a few possibilities.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-07-27 15:39:20
That may not be exactly true.  The orientation of a shadow cast from that elevation could probably move left to right (also depends on light source).  I am not sure, but I don't think we need to alter the scene.  The original worked fine and no-one questioned it.  Is it possible to create that shadow with the dimension and shape I mentioned?
Title: .
Post by: [email protected] on 2017-08-01 19:12:49
.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Kaldarasha on 2017-08-14 19:44:14
Have we ever addressed the issue with mtcrl_3?
(https://steamuserimages-a.akamaihd.net/ugc/866234423409009805/3CA442D689AB07149A60DF6CE6DEB6D536074FC4/)

I had encountered once myself but it is very rare, so I mostly forget about that. Maybe a side effect of the faster loading time?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-08-14 19:45:29
Yeah, I fixed it.  It's caused by poor scripting (the models should be hidden in the init section and aren't being - they're being hidden after a delay).  Probably doesn't "show up" on PSX due to load differences, fade differences.  But it's there too.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Sega Chief on 2017-08-15 02:45:51
Yeah, I fixed it.  It's caused by poor scripting (the models should be hidden in the init section and aren't being - they're being hidden after a delay).  Probably doesn't "show up" on PSX due to load differences, fade differences.  But it's there too.

So this can be prevented if the delay in Init to hide a model is removed?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-08-15 03:34:38
There is no delay in an init.  The init section is there precisely to set up models to be shown / hidden - or other things that must happen at field load.  The init section is executed as fast as your cpu will allow - which is virtually instant UNLESS you place an instruction that has a natural delay there (like Wait).  If you use a loop in init, the field will simply not load, as the game will not be able to progress past init.

What they did in the above field (iirc) is to place the model hide/show data outside of init (like Main) - and using script call instructions - which added a delay long enough that the PC screen will fade in before the model instructions were reached.  This is also a big problem in numerous other areas on the PSX as well as PC, where the script programmer made a mess of how script calls work, leading to a delay in models being shown or hidden before / after fades.

The issue is made worse by the fact the execution limit per group is set default to 8 instructions a frame maximum. So if your "hide model" instruction is in main and on byte 24 (25th byte), then it will take 4 frames to reach that instruction under the best case scenario. If you had a wait 10 there... then it would take 14 frames. If you had a "move model to X" there, then it won't be reached for 14 frames + the time it takes model to move to X. And so on.

That's why init should literally be used for initialize instructions only. The setting of positions and initial vars / math.  Not anything that the engine has a natural delay for.  And definitely not script calls - which will probably be ignored by the engine anyway... not sure.

See here

http://forums.qhimm.com/index.php?topic=15956.msg250079#msg250079
Title: .
Post by: [email protected] on 2017-08-16 23:48:54
.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-08-16 23:52:10
Yeah, all sfx related issues are likely fixed because I have replaced the audio functions entirely.
Title: .
Post by: [email protected] on 2017-08-17 13:46:50
.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-08-17 13:52:14
Yeah im a bit behind adding it and Im waiting to test it with my own dll but am far too busy atm.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-09-03 14:23:22
I am going to have to somehow merge my databases...  at the moment I am duplicating too much crap.  I am updating the database with latest bug issues sent to me here and in PM.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-09-10 11:25:56
Shikun spotted a plot hole.  I've looked into it and fixed it by removing the the exposition.

Major plot hole: Only one NPC mentions the Undersea Mako Reactor before Cait does aboard the Highwind (after Midhir).  Other NPCs start to talk about it after Midhir. This is a problem because Cid immediately knows that the last Huge Materia is at the Undersea reactor after the Corel/Fort Condor mission.

Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-09-10 16:17:55
Junon March.  Don't talk to the captain.  I forgot to close the dialogue box.  So you are stuck there forever if you do haha.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: nfitc1 on 2017-09-11 04:19:21
Shikun spotted a plot hole.  I've looked into it and fixed it by removing the the exposition.

Major plot hole: Only one NPC mentions the Undersea Mako Reactor before Cait does aboard the Highwind (after Midhir).  Other NPCs start to talk about it after Midhir. This is a problem because Cid immediately knows that the last Huge Materia is at the Undersea reactor after the Corel/Fort Condor mission.

While a poor excuse narratively, you can explain it away that the group gained the knowledge of it during that week in Junon we don't see because if Tifa's coma. It would make sense that since they were there a week while supposedly being Shinra's guests that they would learn of the reactor. It does beg the question of how they learned the huge materia was there as that was supposed to be a secret IIRC.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-09-11 04:30:34
We're with Cid all the way up to that point (he's team leader), and the exposition comes just out of nowhere. It wouldn't be so bad if someone had mentioned it directly a few times, but I think the writers of the scene assumed this would be taken care of.  And it never was.  So then no one went back and amended.  Then you have Cait later on with his revelation that the last one is at the undersea reactor.  And then you think "yeah.. so? I know."
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-09-20 09:47:41
OK, apparently there is a bug in FF7 where the characters in cutscenes don't show up because of some issue with the party - perhaps PHS/New party field opcode breaking something.  So far, I haven't been able to replicate.

Any ideas?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-01 23:55:16
https://gyazo.com/6381e2596f89182922f6d57b65c00e27

Spy__Dragon added Kal's shadow for Diamond Weapon, but it looks to me like FF7 engine can't handle the large size of the texture.  There must be a limit.  So we'll need to separate the model into segments to make this work.  But it does look promising.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Kaldarasha on 2017-10-04 12:15:35
I don't think it is the model. Texture-wise we can go as high as we want. 4k is pretty possible, even 8k might work. I guess Melenia's Cloud has a 2k texture. Though, it's hard to tell where the problem is, without seeing it in motion. It could be that the orientation is wrong and the model does clip with the ground or it clips with the cam. It's a pretty close view after all. From what I can see I would say the model isn't plain and not near enough to the camera and does clip with the ground as well as with Cloud.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-04 12:31:28
Yeah but I am talking about the dimensions.   Not the file size.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Ansem on 2017-10-04 12:51:04
Yeah but I am talking about the dimensions.   Not the file size.

That's what 4k and 8k and such stand for. Approximate pixel count across the horizontal axis. I, for one, hate those terms because they're really not what texture resolutions should be called.

Out of curiosity, Kal, how many polygons are in that shadow model?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-04 12:51:46
It also doesn't tell you the dimensions... limits could be across either axis. A pixel count tells you nothing about dimension.

Quote
Melenia's Cloud has a 2k texture

The Cloud model isn't a rectangle shape that has a vert and hor dimension anywhere near this shadow.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-10 19:39:15
Anyone else ever realize that after 2 or so jumps at the Support under Junon, the dolphin actually places you exactly on the spot you need to be to get onto the beam?  I always thought it was strange, but now I think it's actually a remnant from the programmer testing it.  Probably forgot to make sure it wouldn't do that.  Or maybe it was on purpose to make it easier.

In any case, with Weapon mod, I will remedy it.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Ansem on 2017-10-10 19:50:02
By the way, it just occurred to me, but have you done anything regarding Cid's Hyper Jump sometimes crashing the game? I'm not entirely sure if it's PC-exclusive, but I don't remember encountering that on PSX ever. I couldn't find this in the database, so I think it best to bring it up now rather than late, just in case.

Oddly enough, the crash almost definitely has to do something with the Death status, because the crashes stopped once I removed the status from the attack.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-10 20:00:36
I heard about that... Probably from you. I haven't seen it happen, though.  It probably is entirely PC issue.  When I did 60fps mod, I also noticed I had to fix Tifa's limit from crashing. I will look into it.  Does it always happen?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Ansem on 2017-10-10 20:13:14
It's not 100% consistent. Very likely to happen against bosses though, based on what I gathered from searching some of the old posts here. Apparently, the first fight with Ultima Weapon is the most common reported time, but I'm going to assume that's just because people coincidentally tend to have Cid's Limit Level at 2 at the point in the story, (unless they had been grinding it before) so the issue just happens to surface there more often.
Title: .
Post by: [email protected] on 2017-10-10 21:55:35
.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-10-10 23:01:34
So there we are.  It crashes only when the limit is used on an enemy that is immune to death.  The only fixes in Steam etc are the ones that this community made and which Aali added to his dll "driver". So this one has never been fixed, like hundreds of others.

It shouldn't be hard for me to see what accesses the status flag and then work from there reversing it.  I'll look into it tonight.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Matski on 2017-11-24 18:08:34
Not sure if this issue is a bug or just an inconsistency. It occurs in all versions of the game.

When Sephiroth teleports around during the Reunion, it normally has a flash visual + sound effect attached to it: Youtube Video Example (https://youtu.be/HdMFyuw42Tk?list=PLDgypNs3MY2TrF00OMNcK2BCHc9CovwPI&t=1261)

But when Sephiroth disappears in the particular incident shown here, there is never any accompanying special effect/sound effect: Youtube Video Example (https://youtu.be/HdMFyuw42Tk?list=PLDgypNs3MY2TrF00OMNcK2BCHc9CovwPI&t=1425)

It just looks like he glitches out of the game. Do you think it's worth fixing, if it can be fixed?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-11-25 09:54:36
yeah I'm definitely inclined to believe that's a script oversight.
 I'll fix it . Thanks.  Although one is where he is arriving , one leaving.  It may be better to fade out the Sephiroth model that's leaving, unless that flash effect happens elsewhere as he is leaving?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: Matski on 2017-11-25 15:14:21
This clip (https://youtu.be/HdMFyuw42Tk?list=PLDgypNs3MY2TrF00OMNcK2BCHc9CovwPI&t=1540) shows Sephiroth disappearing later in the scene, while using the visual and sound effects.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-12-01 01:25:22
Yeah it's definitely a script error I'll fix it. Thanks a lot.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: DLPB_ on 2017-12-09 16:41:55
This can continue to serve as the main bug post, but the main document is going to soon be The Reunion Database.  I am in the process of merging everything and updating it all there.  I fix as much as I can anyway for The Reunion.
Title: .
Post by: [email protected] on 2017-12-11 12:44:14
.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2017-12-12 14:08:32
Getting there.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2017-12-14 02:39:29
There is some work to do, and there will be duplicates, but the merge is more or less complete. I'll run back through this thread soon to see if I missed any reports. Bed time.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2017-12-14 20:40:42
Ansem, your Hyper Jump bug has been added to the database, finally.  I will look into fixing it ASAP.  Other additions to database will now be made.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2018-01-05 04:31:28
I am sure there was a bug regarding text in battle.  Either a recovery or death text that wouldn't display right.

Anyone any ideas?
Title: Re: [FF7PC] Post bug reports here
Post by: Kaldarasha on 2018-03-30 02:46:03
It seems that the script in Bone Village has a logic error. When you successfully finish the condor minigame of the main story, but don't pick up the Phoenix materia, you can also get the materia on disc three in Bone Village, while you can still pick up the materia in Fort Condor. I guess the game should check if the minigame is won or not, instead of checking if the materia is in the inventory.
See here:
http://steamcommunity.com/sharedfiles/filedetails/?id=442678385
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2018-03-30 13:10:56
this is already fixed. it should be on the reunion database with any other script errors. if it isnt ill add to document.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2018-03-30 14:37:00
https://docs.google.com/spreadsheets/d/1DUjmyW94zcYoX7gIW5yAT4giTPeNmCR4TCaHAiXOLlU

It was already there.  Entry 44, Field Script Errors. Please make sure that it isn't here before posting ;) :P
Title: Re: [FF7PC] Post bug reports here
Post by: Kaldarasha on 2018-03-30 16:01:16
I'll do it next time.
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2018-04-15 15:12:12
Quote
alright so this is 100% repeatable. It only occurs if you are pressing the ok button when getting off the ladder when you enter the field from the bottom. if you climb up to where you can walk and get back on the ladder it will not occur.
a few things i noticed was that the triangle you stand on when getting off is directly above the ladder but cloud automatically takes a step towards the walkway. So if you press ok while doing it he tries to go back down the ladder but cant because hes stil trying to take the step, which he cant do because hes facing the wrong direction now.
As to why it only happens on first dismount when entering scene i dont kno
I also had this bug occur without NT active, still using your exe though. its a vanilla bug id geuss

Uprisen has found a bug in rktbas2.  From what I can see, because you can enter from below, the circle press is still allowed, which will start a script that should not be able to be run.  I am going to run through a few fixes and see if the problem goes away. It should be as simple as checking the starting triangle before OK is allowed to call the script.
Title: Re: [FF7PC] Post bug reports here
Post by: UpRisen on 2018-04-15 18:11:20
 field uttmpin2 theres a "hidden" rotating door at the bottom of the screen and you can soft lock it by spamming "ok" when going through it.

shpin_3 is another bugged field.  There is a body next to the ladder and if you position correctly you can interact with both at the same time. This will lets you move with the txt bubble up, you can then start the trigger with sephi, end the first conversation which will restore your movement and you can attempt to leave the field during sephi talking, this can lead to a soft lock.
Title: Re: [FF7PC] Post bug reports here
Post by: Timber on 2019-12-30 05:31:08
Accidentally posted in wrong thread so posting here too:

- In Shinra HQ after meeting Rufus, you control Aeris and if you enter the elevator and then exit, when exiting the glass elevator, the light that shines from the open door turns off too early (before you leave the elevator). Entering the elevator works fine though.

- Same scenario as above, there are 2 elevators, Player can enter the left elevator, in which case the elevator boss battle is on the wrong side and doesn't make sense. Player shouldnt even be able to enter this elevator as in theory there's a massive robot in there.

- When you first get to Shinra HQ and take the direct approach through the front door, you can optionally go to the Accessories shop on the second floor, and a small cutscene will play when you talk to the clerk - (Barrett talks about how they aren't going to rob the store, they are here to rescue someone). If you do not see this cutscene the first time, then later after the Rufus fight, while controlling Aeris, you can talk to the clerk and the same cutscene starts where Barrett is talking about how they are here to rescue someone, even though Aeris is right in front of him.
Title: Re: [FF7PC] Post bug reports here
Post by: skyhawk on 2020-03-01 22:49:34
Minor field script error, I think:

While in Junon for the first time, dressed up as a Shinra goon:

In the Barracks off Junon (Left):
There is a soldier who says
"Oi. You're still on duty!", "Then again, I'm hardly qualified to grill people.", followed by
"Whatever you do, don't turn into a slouch like me."

The hitbox for the dialog is very off. I can use the (heater?) in the next room over, or the couch on the other side of the room, and still get this line of dialog.
Title: Re: [FF7PC] Post bug reports here
Post by: skyhawk on 2020-03-02 00:58:54
I've found an issue with the Bomb enemies from the Corel area. My copy of ff7 does not function with The Reunion disabled, so I can't test vanilla, but I think this does happen there.

When a Bomb detonates, it turns the entire battle arena black. This condition persists until the end of the battle, which I somehow doubt was the intended behavior.

Video example (https://drive.google.com/file/d/1yMBlrfNwyAnwM-6o3AQqdYttLQa6MBvJ/view?usp=sharing)
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-03-23 09:05:46
this is a weird bug that appears in blin63_1: in the "doors minigame" if you continue to select "Better not" (or no in original game) when asked to open a door sometimes the same question text will popup again and again without having pressed action button on the door. I really can't understand how this bug is triggered (for a test i've pressed better again more than 20/40 times)

Tested with new translation on and off: it appears in both cases
Title: Re: [FF7PC] Post bug reports here
Post by: Kuraudo. on 2020-04-04 21:16:32
Hello,

The icon of the Masamune in the inventory it's a gun. In Steam version and PSX.

Just to report.

Cheers,
Title: Re: [FF7PC] Post bug reports here
Post by: Kuraudo. on 2020-04-05 18:11:57
Heya,

If you go up in this particular field, the icon will move on top of the dialogue box. (junonr4/end parade)

https://imgur.com/IubRrjD
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-04-05 18:36:41
the shadow on the highwind i noticed does the inverse of what it is supposed to do based on altitude

when you move up (towards the source of light) the highwind shadow should get larger (and blurrier due to larger penumbra), and when you move down the shadow should come into focus and become smaller

but the shadow instead gets smaller as you go up and larger as you go down

I'd imagine its the same in psx version but i dont remember, i only notice now because of the graphical mods, you notice a lot more stuff when you can actually make out what they are!
Title: Re: [FF7PC] Post bug reports here
Post by: Kuraudo. on 2020-04-07 07:38:34
No, still appearing with last R06d.
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-04-07 07:49:31
If this is fixed in Reunion's Beacause (New Translation), don't report to me.  Is it ?

R06d and New translation on
(https://i.ibb.co/417w2fd/Immagine.png) (https://ibb.co/TWkD1TL)
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-04-07 11:36:08
cannot replicate.  Need save and how are you getting icon to end up there?

when the commander says march and you need to go in formation you can enable the hand over the cloud head (only in this moment, never tried when you are in formation). When the screen fades to black cloud can still move freely and if you go to the position of the assistant director box you can see the hand... a disable character movement in this moment should fix the problem
Screen with only black fade removed
(https://i.ibb.co/n3dfxjP/Immagine.png) (https://ibb.co/28VPGdZ)

save 3, file 6 https://www.mediafire.com/file/cg95biu2e4kddip/save02.ff7/file (just exit the door on the left to start the parade)
Title: Re: [FF7PC] Post bug reports here
Post by: Kuraudo. on 2020-04-11 08:41:02
This is the original as well. Not a bug but a possible field improvement:

(https://cdn.discordapp.com/attachments/688832597194965080/698181312414089317/IMG_20200410_164105_compress54.jpg)
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-04-11 17:43:18
obviously you guys know this, but the vanilla model has no sword on the back

using the model with the sword makes it look a lot worse than it really is
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-04-11 18:03:15
obviously you guys know this, but the vanilla model has no sword on the back

using the model with the sword makes it look a lot worse than it really is

right, with model overhaul this scene is absurd... but with this animation the developers should have used bhff.hrc (cloud model with sword)
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-04-12 21:08:52
https://drive.google.com/file/d/0B0czBXR0PqOMaG4xZ1EtYnRSMmk2QXpRS1dlWWVzdw/view

save05, file 11 (it comes up in the game as save6 since there is a save00, i'm sure you woulda figured that out/already knew)


i just came across an issue of needing saves myself
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-04-17 12:21:30
This is the original as well. Not a bug but a possible field improvement:

(https://cdn.discordapp.com/attachments/688832597194965080/698181312414089317/IMG_20200410_164105_compress54.jpg)

list of field with this problem (maybe it's not complete; the sword animation sometimes is BIBF and sometimes ETAA)
gaiin 6
junin 3
datiao 6   
subin 1a   
subin 1b   
subin 2b   
tunnel 6   
canon 2   
md8brdg2

I don't know why in other filed this is not appening (for example in semkin_5 the programmers made the correct animation with sword)

I've made a fix for all this field in my italian project for R06d http://forums.qhimm.com/index.php?topic=19551.0 in update 1.4 if you want to check (i'm not a professional in editing field but all possible crash/freeze should have been fixed)

As for test save file i've used this monster pack: http://forums.qhimm.com/index.php?topic=9625.msg173277#msg173277
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-04-18 17:31:06
i am about 98% sure there is some sort of glitch with the odds of appearance by the man who sells GP near the gold saucer save point

in the ps1 version the odds were 1 in 100, it was really rare when he would show up, and to make him appear you really had to go in the gate and come back out about 100 times

in pc version when i ride the ropeway he is there already about half the time

perhaps its not a bug and they wanted to make him not so rare anymore, but i still feel like they wouldn't have made THAT much of a difference if it weren't a bug

i wouldnt care either way if this was fixed or not, just find it interesting
Title: Re: [FF7PC] Post bug reports here
Post by: DLPB_ on 2020-04-19 12:30:06
F10 freezes FF7.  Gonna have to sort that.
Title: Re: [FF7PC] Post bug reports here
Post by: usb on 2020-04-20 15:43:15
@usb - Semkin 5 was corrected by me.  Check original flevel and The Reunion Database.

now make sense, didn't checked original flevel
Title: Re: [FF7PC] Post bug reports here
Post by: GrayFoxN312 on 2020-04-22 00:20:54
While playing with The Reunion R06e, the game crashes after battle randomly on the overworld in the transition between the battle victory fade out to the results screen. I am playing on Steam.

A window didn't pop up saying that it crashed though, but I had no input in the quit function that was implemented (you have to deliberately hold down the two buttons).

For examination I'm inserting a drive link with the app.log, my save file, and Reunion log because that's all that was updated, there's no updated crash.dmp:

https://drive.google.com/open?id=1oyrCDsu5dAnDh-Ziwg8gLkOfKjNCh59N
Title: Re: [FF7PC] Post bug reports here
Post by: GrayFoxN312 on 2020-04-23 01:24:06
Yeah the whole window vanished, up and quit by itself, after the battle ended.
Title: Re: [FF7PC] Post bug reports here
Post by: GrayFoxN312 on 2020-04-23 01:28:25
I also acknowledge that I was using Reunion, sorry for the mix up, if I have a bug next time I'll post in the Reunion thread proper.
Title: Re: [FF7PC] Post bug reports here
Post by: GrayFoxN312 on 2020-04-23 02:08:08
ah yes!!! apologies... glanced over it. okay, yeah. If I have a problem again, definitely. I booted it up today and haven't had an issue. see you, if I see you, in The Reunion forum :)
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-04-29 03:30:52
if your party has any dead characters, the game will let you use a megalixir even when all alive characters have full hp/mp
Title: Re: [FF7PC] Post bug reports here
Post by: Kuraudo. on 2020-04-29 14:04:05
Hello,

Report: Barret while closing eyes appear to have blonde eyebrow in this scene (https://imgur.com/a/FfkhbeV) (mtcrl_3)
Title: Re: [FF7PC] Post bug reports here
Post by: orichalcon on 2020-05-01 03:37:34
This is normal.  Even in battle you can choose to use megalixir on healthy party.  You choose to do it.

in battle its different, you could get hit before you actually use it, but in the field its definitely unintended behavior

if the game blocks you from using an elixir on all 3 characters, it should block you from using a megalixir as well

also you can still use a megalixir on a party of 3 dead characters in the field, its like 2 bugs in 1


and i havent confirmed this or anything, but i'd be willing to bet my car that ff8 and ff10 blocks use in this scenario (i'm not THAT confident... just my car is a P.O.S.)
Title: Re: [FF7PC] Post bug reports here [use The Reunion thread instead]
Post by: obesebear on 2020-05-02 01:46:28
do you want it merged?
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: justphamin on 2020-07-16 22:35:48
Anyone else ever realize that after 2 or so jumps at the Support under Junon, the dolphin actually places you exactly on the spot you need to be to get onto the beam?  I always thought it was strange, but now I think it's actually a remnant from the programmer testing it.  Probably forgot to make sure it wouldn't do that.  Or maybe it was on purpose to make it easier.

In any case, with Weapon mod, I will remedy it.

Is it still the same sweet spot? I'm having the hardest time trying to get it. I can't find it for the life of me.
Title: Re: [FF7PC] Post bug reports here [use The Reunion thread instead]
Post by: obesebear on 2020-07-17 22:49:08
Is it still the same sweet spot? I'm having the hardest time trying to get it. I can't find it for the life of me.
When the "minigame" starts, you just immediately jump.  Then when you land you jump again.
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: orichalcon on 2020-07-17 23:41:19
Is it still the same sweet spot? I'm having the hardest time trying to get it. I can't find it for the life of me.

you need to set weapon mode to 0 in options.ini, its not complete yet and others have also reported the dolphin jump is insanely hard to impossible
Title: Re: [FF7PC] The Big Bad Bug Database - post bug reports here
Post by: justphamin on 2020-07-18 01:03:18
you need to set weapon mode to 0 in options.ini, its not complete yet and others have also reported the dolphin jump is insanely hard to impossible

You're a life saver. I stopped playing for about a month and was about to give up because I was so frustrated with it. Thank you!!! I'll try it out later