Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (91,804 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

The Hero

San Andreas PS2 reflections on PC

Recommended Posts

The Hero

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/topic/741021-recreating-ps2-atmosphere-ive-found-logic-coders-needed/?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.com/mods/show.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/topic/742005-san-andreas-ps2-reflections-on-pc/?p=1066538718

Edited by THE HERO

Share this post


Link to post
Share on other sites
-KING-

Good luck

Share this post


Link to post
Share on other sites
Snoops27

I can't offer anything but good luck!

Share this post


Link to post
Share on other sites
Inadequate

Good luck on this and hope the coders achieve something.

Share this post


Link to post
Share on other sites
The Hero

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.

Edited by THE HERO

Share this post


Link to post
Share on other sites
SilverRST

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.

Share this post


Link to post
Share on other sites
The Hero

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 :(

Edited by THE HERO

Share this post


Link to post
Share on other sites
SkyHunted

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

Share this post


Link to post
Share on other sites
The Hero

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.

Edited by THE HERO

Share this post


Link to post
Share on other sites
Inadequate

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

Share this post


Link to post
Share on other sites
The Hero

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).

Share this post


Link to post
Share on other sites
Inadequate

Anybody have tested it?

Share this post


Link to post
Share on other sites
The Hero

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

Share this post


Link to post
Share on other sites
nyolc8

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

Share this post


Link to post
Share on other sites
Inadequate

 

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.

Edited by inadequate

Share this post


Link to post
Share on other sites
Gramps

Now now kiddies, no name calling is required.

 

Obvious vu1dump is obvious.

Share this post


Link to post
Share on other sites
Snowshoe

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.

Share this post


Link to post
Share on other sites
Inadequate

Any progress on this, boys?

Share this post


Link to post
Share on other sites
The Hero

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/topic/303855-alphatest-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.

Share this post


Link to post
Share on other sites
DK22Pac

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.

Share this post


Link to post
Share on other sites
pawel86ck

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

Share this post


Link to post
Share on other sites
Savidge

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.

Share this post


Link to post
Share on other sites
pawel86ck
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)

Share this post


Link to post
Share on other sites
MrMateczko

Edit the enbseries.ini and disable all the unneeded stuff. Set EnableBloom and other stuff to 0.

Share this post


Link to post
Share on other sites
The Hero

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.

Edited by THE HERO

Share this post


Link to post
Share on other sites
The Hero

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);

Edited by THE HERO

Share this post


Link to post
Share on other sites
Snoops27

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

Share this post


Link to post
Share on other sites
Inadequate

Nice updates man.

Share this post


Link to post
Share on other sites
The Hero

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/gta/ps2_refl/ps2reflection.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.

Edited by THE HERO

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.