Quantcast

Jump to content

» «
Photo

San Andreas PS2 reflections on PC

  • This topic is locked This topic is locked
129 replies to this topic
The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#1

Posted 13 October 2014 - 06:30 AM Edited by THE HERO, 22 November 2014 - 09:24 PM.

In the thread about the PS2 post processing the topic shifted towards the PS2 reflections and I said It would be a good idea to make a new thread for this, this is it.

I posted some stuff I found it here: http://gtaforums.com...d/?p=1066309640

but I'm giving my current knowledge here as well:

 

The PS2 reflections consist of three passes, the diffuse pass, the environment pass and the specular pass (this one's missing on the PC which has specular lighting instead).

 

What we have is Dexx's plugin (with source) which does a pretty good job generally but is not accurate enough: http://www.gtagarage...ow.php?id=17540

 

The problems are these:

- The environment map no longer moves with the vehicle

- The maps are "too bright"

- The texture coordinate generation for the specular pass is incorrect (uses D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR, the PS2 does something different).

 

The first bug can probably be fixed by someone acquainted with the executable.

The other two problems can only be fixed until we know what the PS2 does, this is what I found out:

 

(Note: all I'm writing now I found out by looking into the calls and state of pcsx2 frames captured with PIX)

 

The same geometry is rendered three times (once for each pass) on the PS2 and blended together. In practice, the blend is just dst = dst + src for both reflection passes.

The texture is modulated with the vertex colors. These are 1.7 fixed point numbers (so 0.0-1.0 is 0-128) before being sent to pcsx2's vertex shader (which just converts them to floats) and are multiplied again by 1.9921875 (= 255/128) to convert them to the normal 0-255 range. So if you're debugging with PIX, remember to multiply the color values of the mesh by ~2.

The vertex colors of both passes differ from one another and are dependent on time and weather. This means they are very likely to come from the timecyc.

 

The environment map is rendered with the somehow transformed second UV set (how is the transformation done?, I'd very much like to know) just as on PC without the mod.

The specular map is rendered with generated texture coordinates. How these are calculated I don't know yet, one would have to look at the VU1 program that processes vehicles for that probably (this will get ugly).

 

So we'll have to find out what the colors for the reflection passes are, i.e. where they come from.

And secondly we need to find out the correct tex coord generation.

 

It would be very cool if someone knowledgeable could make a hook that renders the vehicles with a shader so one can experiment more easily (and we'll need a shader in the end anyway since I don't think we can generate texture coordinates otherwise). I'll ask Dexx about this, I think he already did something like that.

 

That's all for now, I really hope we can do this :)

 

 

 

EDIT: See here for the first release:

http://gtaforums.com...c/?p=1066538718

  • Frank.s, Xyn, Ermac and 10 others like this

-KING-
  • -KING-

    Player Hater

  • BUSTED!
  • Joined: 08 Oct 2014
  • United-States

#2

Posted 13 October 2014 - 10:38 AM

Good luck


Snoops27
  • Snoops27

    Hustler

  • Members
  • Joined: 10 Aug 2013
  • United-Kingdom

#3

Posted 13 October 2014 - 10:51 AM

I can't offer anything but good luck!


Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#4

Posted 13 October 2014 - 04:54 PM

Good luck on this and hope the coders achieve something.

  • Snoops27 and Neddo like this

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#5

Posted 13 October 2014 - 08:08 PM Edited by THE HERO, 13 October 2014 - 08:13 PM.

Damn it, I'm such an idiot. I complete forgot about the intensity values in the DFF chunks for reflection and specular material. These are still somehow modified (depending on timecyc probably) but it's a lot more clear now where they come from, they're still too bright I think.

  • mirh and Snoops27 like this

SilverRST
  • SilverRST

    Boss

  • Members
  • Joined: 25 Mar 2013
  • None

#6

Posted 13 October 2014 - 08:32 PM

Damn it, I'm such an idiot. I complete forgot about the intensity values in the DFF chunks for reflection and specular material. These are still somehow modified (depending on timecyc probably) but it's a lot more clear now where they come from, they're still too bright I think.

We as 3D modelers can adjust the power of the reflections in the DFF when exporting it.

The paramters we use for Zmodeler is [env:9] The max is 50.

I'm not sure if this helps but maybe there is something called [env:xx] in the EXE files or DFF from the PS2.


The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#7

Posted 14 October 2014 - 02:37 PM Edited by THE HERO, 14 October 2014 - 08:19 PM.

Haha, no. That's just how Zmodeler does it.

Anyway, I found out that the specular and environment intensities are not effected by timecyc values. But as they're time dependent this must be hardcoded.

 

Edit: dumped the VU1 state with my modified pcsx2 before it renders the first part of the third split of the Tampa's hood and disassembled the instructions. Now the fun begins :(

  • mirh, SilverRST and Snoops27 like this

SkyHunted
  • SkyHunted

    i wished for a rain , not a sandstorm.

  • Members
  • Joined: 29 Jun 2014
  • None
  • April Fools Winner 2015

#8

Posted 15 October 2014 - 02:23 AM

@THE HERO is that getting you any closer to making a PS2 ref on PC ?

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#9

Posted 15 October 2014 - 06:00 AM Edited by THE HERO, 15 October 2014 - 06:00 AM.

It will, hopefully. The VU1 is the vector unit of the PS2 that processes the geometry (and probably generates the reflection texture coordinates) and sends it to the rasterizer. It's sort of the vertex shader of the PS2. So now I have to go through the program it runs and see what it does. It should have the code for generating the texture coordinates. This will not be easy however. This way I can only find out how the tex coords are generates of course. Someone else would have to implement that on PC then.

  • mirh and Snoops27 like this

Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#10

Posted 15 October 2014 - 06:05 AM

Aw yesss, all the luck in this.  :^:

  • Snoops27 likes this

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#11

Posted 15 October 2014 - 06:37 AM

If anyone is interested in this or what it looks like (although I seriously doubt that), i uploaded the files here: http://aap.papnet.eu/gta/vu1dump.zip

As I said, this is the VU1 before it draws the tampa's hood. vu1mem is the memory, vu1micromem is the instruction memory, vu1micro.dis it's disassembled form, vu1state is a (binary) dump of the registers and vu1state.txt a textual version of that (generated with the python script).

  • mirh and Snoops27 like this

Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#12

Posted 15 October 2014 - 05:57 PM

Anybody have tested it?


The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#13

Posted 15 October 2014 - 06:27 PM

What do you want to test? This is the PS2 code which renders a vehicle.


nyolc8
  • nyolc8

    -

  • Members
  • Joined: 12 Oct 2009
  • Hungary

#14

Posted 15 October 2014 - 07:03 PM

What do you want to test? This is the PS2 code which renders a vehicle.

obviously, the guy have no idea what are you talking about in this topic :D

  • Gramps likes this

Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#15

Posted 15 October 2014 - 09:11 PM Edited by inadequate, 15 October 2014 - 09:14 PM.

 

What do you want to test? This is the PS2 code which renders a vehicle.

obviously, the guy have no idea what are you talking about in this topic :D

 

 

lol sorry Mr. MasterCodingExpert nyolc8, for a moment I thought it was a script.

  • Snoops27 likes this

Gramps
  • Gramps

    ★★★★★

  • GTA Mods Staff
  • Joined: 23 May 2008
  • New-Zealand
  • Helpfulness Award
    Contribution Award [Mods]

#16

Posted 16 October 2014 - 01:11 AM

Now now kiddies, no name calling is required.

Obvious vu1dump is obvious.
  • lpgunit and Savidge like this

Snowshoe
  • Snowshoe

    Special Snowflake

  • Members
  • Joined: 04 Jun 2009
  • United-States

#17

Posted 20 October 2014 - 05:50 PM

Good luck on this. While I don't think there's anything particularly wrong with the PC sheen on cars, it's certainly more generic than whatever the PS2 did.


DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#18

Posted 20 October 2014 - 10:21 PM

THE HERO, have you any knowledges about VIF codes and DMA packets used on PS2?
I made some research months ago, but didn't finish it since there was some controversial moments...
http://gtamodding.ru/wiki/Native_Data_PLG_(Секция_RW)#Playstation_2
Maybe you know anything about it?
  • Gramps, mirh, Snoops27 and 1 other like this

Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#19

Posted 22 October 2014 - 08:34 PM

Any progress on this, boys?

  • Snoops27 likes this

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#20

Posted 27 October 2014 - 09:05 PM

THE HERO, have you any knowledges about VIF codes and DMA packets used on PS2?
I made some research months ago, but didn't finish it since there was some controversial moments...
http://gtamodding.ru/wiki/Native_Data_PLG_(Секция_RW)#Playstation_2
Maybe you know anything about it?

 

The PS2 pre-instanced geometry data is more or less an open book to me at this point. I don't read Russian so I can't read what it says on the page, but it looks good. If you want I could document all I know about the PS2 format on gtamodding.

The TXD format has some secrets left though (but I bet you can find these out as well).

 

As for my research, I've been reading a bit of the disassembled VU1 code and already found some interesting stuff (nothing new exactly, but it's nice to read the code that actually does the magic) but I haven't yet gotten to the part where the reflections are rendered. Now that the semester started I sadly no longer have the time I had a few weeks ago, but I'm quite optimistic I'll be able to figure out how the PS2 renders vehicles, but it can take a while.

 

Now we still don't have anybody to implement all the changes, maybe this can be of help: http://gtaforums.com...phatest-sa-gfx/

We need a vertex and pixel shader to override the rendering of vehicles. We need to access the three textures, some material properties and so on. If that's working and I find out what the PS2 does the actual writing of the shaders should be a piece of cake.

  • Gramps, mirh, Snoops27 and 1 other like this

DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#21

Posted 05 November 2014 - 01:04 PM

The PS2 pre-instanced geometry data is more or less an open book to me at this point. I don't read Russian so I can't read what it says on the page, but it looks good. If you want I could document all I know about the PS2 format on gtamodding.

Yes, I wish.

pawel86ck
  • pawel86ck

    Player Hater

  • Members
  • Joined: 07 Sep 2009
  • Poland

#22

Posted 15 November 2014 - 12:15 AM

Guy's, right now I'm using ENB for car reflections, but there's any way to turn off bloom, and ENB color filters ? I just want car and maybe water reflections 


Savidge
  • Savidge

    lemon madman

  • Members
  • Joined: 29 Dec 2013
  • England

#23

Posted 15 November 2014 - 12:32 AM

Guy's, right now I'm using ENB for car reflections, but there's any way to turn off bloom, and ENB color filters ? I just want car and maybe water reflections 

Wrong place to ask, buddy.

  • Snoops27 likes this

pawel86ck
  • pawel86ck

    Player Hater

  • Members
  • Joined: 07 Sep 2009
  • Poland

#24

Posted 15 November 2014 - 12:37 PM

Wrong place to ask, buddy.

I want something similar to ps2 car reflection, and for now there's no alternative besides ENB (old car reflection mod for SA doesnt work anymore on new game exe)


MrMateczko
  • MrMateczko

    The Laziest Person on Earth™

  • Members
  • Joined: 10 Dec 2011
  • Poland
  • Helpfulness Award [Chain Game]

#25

Posted 15 November 2014 - 12:53 PM

Edit the enbseries.ini and disable all the unneeded stuff. Set EnableBloom and other stuff to 0.
  • pawel86ck likes this

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#26

Posted 15 November 2014 - 01:03 PM Edited by THE HERO, 15 November 2014 - 01:30 PM.

Got a little update. I'm reading through the code that renders the environment and specular pass and kinda figured out what color values are used. As I said there is a magic value that's time dependent (not timecyc dependent). Each pass has a base color/intensity so to speak (192 for the env pass, 96 for the spec pass) which is multiplied with the magic value (0.58 in my case) and the intensity value from the DFF chunk (although I think that at least the env intensity is somehow modified before being uploaded to the VU1, have to investigate that) to yield the final color with which the texture is modulated. I havent' actually checked if I can confirm that with PIX, the alpha values are especially weird. For the env pass a value of 0.33 is used but then converted to an integer (so 0) while the spec pass uses the alpha of the diffuse pass.

If someone made a shader for the vehicles we could try and see how it works.

I still have no idea where the magic value comes from or how the texture coordinates are generated/transformed.

 

EDIT: checked with PIX. The color values are multiplied by 255/128 (~2) in pcsx2 after multiplication with the texture (not only alpha, also the colors, PS2 is weird) and the alphas are indeed correct but not used anyway.

  • Gramps, Blackbird88, mirh and 5 others like this

The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#27

Posted 19 November 2014 - 07:17 PM Edited by THE HERO, 20 November 2014 - 01:06 PM.

Another update, found out how the environment map texture coordinates are calculated!!

This is the code from my OpenGL shader I use for testing:

        v = u_lightdir;   // in eye space
        vec3 u = vec3(v.x+1, v.y+1, v.z)*0.5;
        vec3 n = mat3(mvmat)*in_normal*vec3(-1, 1, -1);
        vec3 st = u - n*dot(n, v);
        v_texcoord2.st = st.xy;

 

then further down (use black to clamp, otherwise the color from above):

        if(st.z < 0){
                v_speccolor = vec4(96, 96, 96, 0)/255.0*specMult*0.58;
                v_speccolor.a = v_color.a;
                v_speccolor *= 255/128;
        }else
                v_speccolor = vec4(0.0, 0.0, 0.0, 1.0);
 

I'm not quite sure about the light direction and the multiplication by vec3(-1, 1, -1) yet (this was needed because the PS2 uses different matrices). Not quite sure why the matrices are different.

Now I'll look into the colors again. I think I haven't gotten them quite right yet, they seem so dark in my tests.

 

EDIT: Now I'm no longer quite sure what u_lightdir really is. The light direction in another part of the code is some other value.

 

EDIT: Maybe u_lightdir is a special reflection vector. I got the world-space vector by multiplying with approximately the right inverse view matrix (0.48246654, -0.51606954, -0.70774151) but this needs x and z negated as well. Next I'll check if this vector is time-dependent (I reckon not).

So the code above is now: V = u_lightdir*vec3(-1, 1, -1);

  • Androll, George Costanza, mirh and 3 others like this

Snoops27
  • Snoops27

    Hustler

  • Members
  • Joined: 10 Aug 2013
  • United-Kingdom

#28

Posted 19 November 2014 - 07:19 PM

Thanks for not giving up like most modders would, you're doing great!

  • Alt, SilverRST, Neddo and 2 others like this

Inadequate
  • Inadequate

    Midnight Emulator

  • Members
  • Joined: 11 Apr 2012
  • None

#29

Posted 19 November 2014 - 10:07 PM

Nice updates man.


The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Best Conversion 2017 Contribution [Liberty City Stories: PC]
    Best Total Overhaul 2017 Contribution [GTA: Underground]
    Most Helpful Modding 2016 [Honorable Mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#30

Posted 20 November 2014 - 08:30 PM Edited by THE HERO, 21 November 2014 - 08:07 AM.

I thought I'd publish my test program so you can see for yourself what I've done, the code's on github (https://github.com/aap/gtaprogs) but I've compiled a windows binary: http://aap.papnet.eu...2reflection.rar

First write your SA path into the configuration file (saps2-win.json or sapc-win.json, depending on the platform) and run misctest.exe from cmd like this: misctest conf\saps2-win.json (or click on the run.bat file, which uses the saps2-win.json file, edit if you want). Make sure you use double backslashes and terminate the path with one.

 

As for the code, I haven't yet found out how the diffuse color is done exactly, but that isn't too bad as the PC already does it. The reflection vector (which also seems to be the light vector....hm....) is indeed time independent and always (0.5, -0.5, -sqrt(0.5)) in world space. Haven't looked at the environment texture generation yet, but the PC version does it without Dexx's mod, so if we could just use that code that would suffice.

The only thing that's really left no is the unknown magic number used for the vertex colors in the env and spec pass.

I really hope someone tries to implement that.

 

EDIT: just got one step closer to finding out the diffuse pass lighting calculation.

 

EDIT: Found out how the diffuse pass is done (more or less, still two magic colors I took out of the PS2) and updated the program (link above). I also fixed a stupid bug that caused the reflection passes to be too dark (255/128 is an integer division and yields 1, duh...). I think it looks almost identical to my reference screen, but see for yourself:

tampa.pngtampaps2.png

 

The only think really missing still is the magic time dependent multiplier for the reflections.

  • Androll, Gramps, George Costanza and 11 others like this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users