elishacloud / Silent-Hill-2-Enhancements

A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC. It also includes scripts to build or modify SH2 audio files (SFX, BGM and Dialog).
http://www.enhanced.townofsilenthill.com/SH2/
zlib License
539 stars 41 forks source link

Help Needed: Specialized Room Adjustments #63

Closed Polymega closed 2 years ago

Polymega commented 5 years ago

@Bigmanjapan

Continuing from email conversation here are details about other rooms/areas that could use some love. Some of these have been discussed in the past but will be posted here just to make them easier to find/discuss, if needed:

Hotel Room 312 Chair Shadow (rr91.map)

The chair James sits on while watching the VHS tape doesn't cast a shadow while the cutscene plays. However, both before and after the cutscene the chair has a shadow once more:

image

Here you can also see a video of the chair regaining its shadow once the cutscene ends: https://youtu.be/JH109aNOpCA

This is a problem because, without the chair's shadow during the cutscene, we see only James' shadow and during certain parts of the cutscene chunks of his shadow are masked out:

image

image

I studied the parts of James' shadow that are bugged/masked out and it seems to actually make an abstract outline of where the chair's shadow should actually be.

And here is a PCSX2 (PS2) screenshot showing that the chair should have its shadow during this part:

image

If you watch the video link from above, we can see that James' can cast his shadow on the chair while the chair itself casts its own shadow (after the cutscene ends).

Since we know it's possible for the chair to cast its own shadow and the chair can also receive James' shadow, is there then anyway to restore the shadow to this chair during the cutscene?

Polymega commented 5 years ago

FIXED! Prison hallway hole lights (ps53.map)

This one was mentioned before but adding here for posterity: The tube lights in this prison hallway hole room aren't "lit" and instead affected by James' flashlight. When his light is off they're pitch black and when his light is on they're dulled:

image

Whereas they should always be lit (with no other lighting influencing them) as seen here on the PCSX2 (PS2) version:

image

Is there a way to restore these lights so that they're always lit?

Polymega commented 5 years ago

The Dormant Mannequin (Woodside Rm 205)

Main thread here

This room is a complete mess and the PC version of this game is trying to do everything it can to ruin the surprise.

However, thanks to you Bigmanjapan, we now know how to darken the dynamic objects in this room before acquiring the light and we can now also fix the pool of blood when both a) quick loading into the room before getting the flashlight and b) if the Mannequin dies on the carpet afterwards.

The last two things to fix? 1) Removing the shine from the mannequin before getting the light (to make the surprise more... surprising) and 2) preventing the mannequin from "flipping" when coming to life if the player quick loads into the room before getting the light.

Now, both of these things aren't necessary to have fixed (the most important bug to fix was darkening the dynamic objects) but, between the two remaining fixes, I'd say removing the shine on the mannequin before acquiring the flashlight is more important between the two.

Why? Because the chances of someone quick saving then quick loading in this particular room before acquiring the light are probably slim. If someone were to enter this room and see a beacon of light off to the side they're very likely to acquire that before doing anything else in this room ("Ooooh! Shiny!")

Because of that, I'd wager many people won't ever experience the mannequin incorrectly flipping from quick loading back into this room. However, removing the shine on the mannequin would be much more beneficial to hide the surprise that awaits them...

If I may ask: Between the two remaining fixes for this room, can removing the shine be the priority and its fixed shared even if the other issue can't/hasn't been found yet?

Bullsquiddy commented 5 years ago

Probably unhelpful to point out, but the shadows during that cutscene in the PC version also appear to be darker. Is that an extension of it lacking soft shadows?

Polymega commented 5 years ago

Is that an extension of it lacking soft shadows?

I'd say that's correct. If/when we find the right person(s) to implement soft shadows I was planning on asking about if the values of the shadows could also be brightened some; as adjusting that would be the time to do so (with someone editing the shadows).

Polymega commented 5 years ago

FIXED! ap18.cam

Bigmanjapan, while in the closet, can the camera be moved to the right to hide the void? With Cheat Engine, changing sh2pc.exe+1B810F8 (float) [Camera Z] to -101390 fixes it.

Ignore; this was an issue with Nvidia cards hiding chunks of the wall when the camera is too close.

004

Bigmanjapan commented 5 years ago

@Polymega

This is how that camera angle looks in my build:

default

Are you sure it's not something you've done or some other code of Ehanced Edition interfering? I don't update the build I use for research that often, so my build could lack the code the accidentaly breaks this camera angle. Try using a default build with 16:9 AR hack only to see how the camera angle behaves.

This camera angle is not actually stored in ap18.cam file, it's stored directly in sh2pc.exe.

Some addresses that control this camera angle:

sh2pc.exe+4E0FA8 (008E0FA8) float — tilt with elliptical trajectory sh2pc.exe+4E0FAC (008E0FAC) float — panning with elliptical trajectory sh2pc.exe+4E0FB8 (008E0FB8) float — tilt sh2pc.exe+4E0FAC (008E0FBC) float — panning sh2pc.exe+4E0FD4 (008E0FD4) float — roll

It seems that there is no X / Y / Z coodrinates for this camera angle, it's anchor point is calculated via several addresses that have elliptical trajectories instead of straight X / Y / Z lines. I've seen such design in Fatal Frame games long time ago. The whole store in the sh2pc.exe thing is probably due to the fact that this camera angle needs to be disabled after the key is picked up and once James steps out of the closet after picking up the key.

Changes to this camera angle could be made via hex injection directly to sh2pc.exe. The addresses offsets are the same minus 00400000 module: 0x4E0FA8, 0x4E0FAC etc There is always a possibility that some other camera angle polls values from these addresses but I highly doubt that.

Interesting that if I save while standing in the closet, then reload, the game will output black screen. One needs to step out of the closet and walk back in to initiate the angle. This suspiciously reminds me of the camera transfer glitch I was getting while running Maria's scenario: https://youtu.be/oZYm5bDslto

Doesn't happen on PCSX2 if I try to use debug save function in the closet and then reload it. Once Cxbx-Reloaded is developed more it will be interesting to see if the bug is present in Xbox builds.

Polymega commented 5 years ago

Are you sure it's not something you've done or some other code of Ehanced Edition interfering?

This is interesting. On my laptop my camera angle in here looks like yours. Let me go home tonight and re-test this area on my main computer again. Maybe I had remnants of a custom camera adjustment here or something...

Ignore; this was an issue with Nvidia cards hiding chunks of the wall when the camera is too close.

Interesting that if I save while standing in the closet, then reload, the game will output black screen.

Oh wow. From 15 years of playing the PC game I've never quick saved in there to have this happen.

A possible fix would be IF in room ID AND a certain camera angle is active THEN disable quick save feature. But this is under the presumption that we know how to easily disable quick save for a certain area.

However...... I personally think this bug is so circumstantial it wouldn't be worth worrying much about. It could be placed lower on the wishlist of things to fix.

Bigmanjapan commented 5 years ago

Better solution would be to figure out why this camera angle only initializes when James steps into the trigger area and not when James is spawned directly on it.

At first I thought that on PC version trigger for that angle is made via a line while on PS2 it's an actual rectangular area. Not the case. PC version's trigger area is also a rectangular one but actually needs stepping into to get activated for some reason.

Polymega commented 5 years ago

lol! @Bigmanjapan it's another damn Nvidia bug. When I used my Nvidia PC with WineD3D the closet camera looks like yours. When I used my Nvidia PC without WineD3D it shows the void. My laptop (using Intel graphics) also looks fine.

Since there's no easy way to fix this camera let's just ignore this one. It's not that big of a deal when there are other things more important to fix. lol this game hates Nvidia cards...

Ooooh! Actually I bet this is chunks of the wall disappearing due to the already-known Nvidia bug. Okay, yeah, this will eventually be fixed then and the camera angle has been correct the whole time there.

Polymega commented 5 years ago

FIXED! ap88.map

@Bigmanjapan there's a few flat poly planes/textures that should be brightened in this room. It looks either the address that controls its brightness isn't set right or the address to adjust the brightness isn't there to begin with for the PC version:

PC:

image

PCSX2:

image

Here's what it looks like from the other side: image

Bigmanjapan commented 5 years ago

ap88.map there's a few flat poly planes/textures that should be brightened in this room.

For some reason surface color of that element is controlled via cover-up fog addresses (which is used to create corners shadows indoors):

sh2pc.exe+542C20 (00942C20) byte — Cover-up fog R sh2pc.exe+542C21 (00942C21) byte — Cover-up fog G sh2pc.exe+542C22 (00942C22) byte — Cover-up fog B sh2pc.exe+542C30 (00942C30) float — Cover-up fog front line sh2pc.exe+542C34 (00942C34) float — Cover-up fog back line sh2pc.exe+542C3C (00942C3C) float — Cover-up fog intensity

The issue here is that when you bright it up, shadows in the corners becomes brighter too. You can crank shadows down via intensity address but that would mess with the original room design.

Also similar thing happens with prison hallway hole lights (ps53.map). When James flashlight is off, black colour on the lights is also rendered by fog addresses for some reason. It only renders proper texture on the lights when James flashlight is on. I think the prison lights and Blue Creek windows issues might have the same root.

default

default

Xbox builds have these issues too.

Polymega commented 5 years ago

Thanks for looking into this, Bigmanjapan.

If the addresses/functions are missing to make these particular materials/shaders fully illuminated perhaps we may ask @FrozenFish24 to see if he could perform magic on the vertex/pixel shader calls for these particular pieces of geometry? Similar to how the WineD3D wall issues became fixed?

I have no earthly clue if such a thing is even possible or wise to do so... but:

Here's a link to Intel Frame Analyzer screen grabs for both ap88.map and ps53.map: http://www.igotaletter.com/temp/sh2pc/sh2pc_intel_frame_grabs.zip

There are two versions of each screen grab: One with the flashlight on, and the other with the flashlight off.

For ap88.map here is the geometry in question:

image

For ps53.map here is the geometry in question:

image

As you all know by now, I am no programmer. But I was able to incorrectly brighten these geometry pieces by altering the pixel shader code. For the halogen lights in ps53.map:

image

I changed def c3, 0, 0, 0, 0 to def c3, 1, 1, 1, 1

I know that doesn't help any but it shows that maybe there's something there that can be done?

Polymega commented 5 years ago

Got it working in the Frame Analyzer! Okay, here's what I did:

I captured another scene where the halogen lights worked. In this case, the butterfly room in Woodside Apartments:

image

I then copied the vertex shader code from this geometry and pasted it directly as-is to the halogen light geometry in the prison:

image

and the windows for the apartment staircase:

image

This worked--at least through the Intel Graphics Frame Analyzer--for both versions of each scene: When James flashlight was both on and off.

Here is the code:

    vs_1_1
    dcl_position v0
    dcl_texcoord v7
    mov r11, c0
    mov r1, c0
    mov oD1, c0
    mov oD0, c0
    mov oT2, c0
    mov oT1, c0
    mov oT0, c0
    dp4 r1.x, v0, c0
    dp4 r1.y, v0, c1
    dp4 r1.z, v0, c2
    dp4 r1.w, v0, c3
    max r11.w, r1.w, c14.w
    rcp r11, r11.w
    mad oFog, c23.y, r11.x, c23.x
    mov oPos, r1
    mov oT0.xy, v7
    mov oD0, c14.w
    mov oD1.xyz, c14.x
    mov oT1, c14.x
    mov oT2, c14.x

So the final question would be to @FrozenFish24 and @elishacloud : Could anything be done with this information to fix these two spots?

elishacloud commented 5 years ago

@Polymega, It is relatively easy to replace one shader with another one. Can you show me what the shader looked like before and after you updated it?

Polymega commented 5 years ago

Yes sir:


Quick Save save file for Prison hallway: sh2pcsave1c.zip

Halogen lights before (they're pitch black like this when you turn off his light and lambert shaded when his light is on): https://user-images.githubusercontent.com/27395260/48106024-bc80b480-e207-11e8-8532-20540aea4093.png

Halogen lights how they should be after fix: https://user-images.githubusercontent.com/27395260/48106056-dae6b000-e207-11e8-805f-a12447809ea5.png

Halogen lights original vertex shader code:

    vs_1_1
    dcl_position v0
    dcl_color v5
    dcl_texcoord v7
    mov r11, c0
    mov r1, c0
    mov oD1, c0
    mov oD0, c0
    mov oT2, c0
    mov oT1, c0
    mov oT0, c0
    dp4 r1.x, v0, c0
    dp4 r1.y, v0, c1
    dp4 r1.z, v0, c2
    dp4 r1.w, v0, c3
    max r11.w, r1.w, c14.w
    rcp r11, r11.w
    mad oFog, c23.y, r11.x, c23.x
    mov oT0.xy, v7
    mov oD0, v5
    mov oD1, c14.x
    mov oT1, c14.x
    mov oT2, c14.x
    mov oPos, r1

Quick Save save file for Apartment Staircase: sh2pcsave1c.zip

Windows before: https://user-images.githubusercontent.com/27395260/49322822-114edc80-f4e1-11e8-8c47-2201441b7645.png

Windows how they should be after fix: https://user-images.githubusercontent.com/27395260/49322825-1dd33500-f4e1-11e8-8ca4-30c81426b9cd.png

Windows original vertex shader code:

    vs_1_1
    dcl_position v0
    dcl_color v5
    dcl_texcoord v7
    mov r11, c0
    mov r1, c0
    mov oD1, c0
    mov oD0, c0
    mov oT2, c0
    mov oT1, c0
    mov oT0, c0
    dp4 r1.x, v0, c0
    dp4 r1.y, v0, c1
    dp4 r1.z, v0, c2
    dp4 r1.w, v0, c3
    max r11.w, r1.w, c14.w
    rcp r11, r11.w
    mad oFog, c23.y, r11.x, c23.x
    mov oT0.xy, v7
    mov oD0, v5
    mov oD1, c14.x
    mov oT1, c14.x
    mov oT2, c14.x
    mov oPos, r1

I'm pretty much clueless with Direct3D, shaders, etc. but it's worth noting that we only want to update the shaders for these specific pieces of geometry for these particular rooms only.

Polymega commented 5 years ago

For both of these particular rooms, these geometry pieces seem to be the only ones that use their vertex shader codes within the whole room. So if they're overwritten just for when you're in these rooms, it shouldn't negatively affect anything else within the area.

sh2pc.exe+1BB7DAC (01FB7DAC) byte — room index ID Prison hallway ID: 00000064 (hex) Apartment staircase ID: 00000021 (hex)

Perhaps the shader can be updated for the overall game but I wouldn't know what else that would affect without play testing the whole game.

The updated shader code can be found at the bottom of this post: https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/63#issuecomment-444334831

Bigmanjapan commented 5 years ago

@Polymega

Nice.

Also what's up with the dead Lying Figure being rotated 90 degrees after the Blue Creek bossfight? I've seen it being positioned both parallel and perpendicular to the stairs on PC version.

Polymega commented 5 years ago

That's a result of quick loading back into the room, similar to the apartment flashlight room. Although this creature never comes back to life so nothing to really worry over.

elishacloud commented 5 years ago

I believe the problem is only with one line in the vertex shader:

    vs_1_1
    dcl_position v0
    dcl_color v5
    dcl_texcoord v7
    mov r11, c0
    mov r1, c0
    mov oD1, c0
    mov oD0, c0
    mov oT2, c0
    mov oT1, c0
    mov oT0, c0
    dp4 r1.x, v0, c0
    dp4 r1.y, v0, c1
    dp4 r1.z, v0, c2
    dp4 r1.w, v0, c3
    max r11.w, r1.w, c14.w
    rcp r11, r11.w
    mad oFog, c23.y, r11.x, c23.x
    mov oT0.xy, v7
    mov oD0, v5        ;<--- This line is bad
    mov oD1, c14.x
    mov oT1, c14.x
    mov oT2, c14.x
    mov oPos, r1

Instead of mov oD0, v5 it should be mov oD0, c14.w.

Try with this patch: d3d8.zip

Polymega commented 5 years ago

I'm envious of your know-how. This works great whenever James' flashlight is on. However, it goes back to "blacking" out the geometry whenever you turn off his flashlight (L key to toggle, by default).

Any chance to make this override any and all functions/calls to this vertex shader so that the geometry is always fully illuminated, regardless of whether or not James' flashlight is on/off?

elishacloud commented 5 years ago

Apparently there is a different vertex shader used when the flashlight is off. I had to make some additional changes to that shader also.

Here is the vertex shader used when the flashlight is off:

    vs_1_1
    dcl_position v0
    dcl_color v5
    dcl_texcoord v7
    mov r11, c0
    mov r1, c0
    mov oD1, c0
    mov oD0, c0
    mov oT2, c0
    mov oT1, c0
    mov oT0, c0
    dp4 r1.x, v0, c0
    dp4 r1.y, v0, c1
    dp4 r1.z, v0, c2
    dp4 r1.w, v0, c3
    max r11.w, r1.w, c14.w
    rcp r11, r11.w
    mad oFog, c23.y, r11.x, c23.x
    mov oFog, c14.x        ;<--- This line needs to be removed
    mov oPos, r1
    mov oT0.xy, v7
    mov oD0, v5            ;<--- This line is bad (see above)
    mov oD1.xyz, c14.x
    mov oT1, c14.x
    mov oT2, c14.x

Try this one: d3d8.zip

Note: I updated the actual vertex shader. This could affect other rooms since I don't know what other rooms use this shader.

Polymega commented 5 years ago

Beautifully done! Just testing the areas in question everything is working and looking great. Thank you very much for looking into this, Elisha!

Note: I updated the actual vertex shader. This could affect other rooms since I don't know what other rooms use this shader.

Okay, let me play test the game soon, playing through both campaigns to completion once with the flashlight always on and another where it's always off. I'll report back with my findings then.

Polymega commented 5 years ago

FIXED! ap64.cam Adjustment

Hi @Bigmanjapan ,

Can the camera be adjusted to hide this while in the wallet toilet bathroom?

image

Polymega commented 5 years ago

@Bigmanjapan @FrozenFish24

I may have found something about the Hotel chair shadow glitch while I was researching another shadow area.

But first: Let's talk about the shadow for the grandfather clock in Woodside Apartment:

When your flashlight casts a shadow on the clock it leaves a glitched "outline" of the clock's shadow around it, just like what the Hotel chair seems to be doing:

image

So I took an Intel Frame capture of this room and saw something peculiar:

image

The Frame Capture software unfortunately does not capture real-time shadows. So this shadow isn't a dynamic shadow...

But wait! I've seen this before: It's a fake shadow used throughout the game for various assets. It's typically a flat poly plane with a semi-transparent PNG texture that simulates a shadow:

image image

So what does this mean? That fake poly shadow plane is a dynamic object. Because when you move the clock, that shadow (that poly plane) moves with it. And what do we know about SH2 PC? Currently, dynamic objects can't have shadows cast upon them.

So if/when we can figure out how to have dynamic objects receive shadows cast upon them, the grandfather clock's shadow should at least be fixed.


However... I'm not so sure that's the issue with the Hotel chair:

I'm not sure how many areas are like this, but for this room it looks like simple geometry is casted out and that is what determines where/how the shadows will be drawn:

https://youtu.be/OptmHNdQBFs

image

Be sure to watch the YouTube video above. I'm not sure what this is? There's no shader calls to them? But whatever this is it seems to be what's both casting the current shadow we see and probably also bugging out the chair shadow in the process?

But both before and after the cutscene the chair (which has a correct shadow during these points) has a more "clean" piece of geometry to tell it how to cast its shadow: https://youtu.be/xzWlali5qGk

image

You can even see part of these poly planes if you angle James the right way:

image

But during the cutscene I found no instance of such a "clean" piece of geometry to tell the game where/how to cast its shadow.

I could just be speaking nonsense right now but I wonder if the disappearance of that one group of "clean" geometry that defines the chair's shadow being missing during the cutscene is what's causing the issue of its shadow not appearing at all?

Keith94 commented 5 years ago

I was curious, since the camera adjustment fixes are intended for 16:9 resolutions, I assume they won't be effective for even wider aspect ratios, i.e. 21:9, 32:9, 48:9 etc.? Is there a way to toggle the camera fixes off in those cases?

Polymega commented 5 years ago

That's correct; if you go ultra wide you're still probably going to see clipping through walls even with the 16:9 .cam fixes. To disable them you can remove any/all .cam files from the \sh2e\bg\ folders.

Keith94 commented 5 years ago

Thanks!

Bigmanjapan commented 5 years ago

@Polymega

ap64.zip

FrozenFish24 commented 5 years ago

@Polymega I was looking into soft shadows recently and I worked out that you can get the dynamic shadows to show up in the frame analyzer by removing all the game's textures. Here's a modified sh2e dll that stubs out m_IDirect3DDevice8::SetTexture which might prove useful to you: sh2e-no_textures.zip

From my limited understanding, the dynamic shadows are created using some combination of shadow volumes (as you surmised), a full screen quad and the stencil buffer. Layered over the static shadows. Perhaps it may be possible to transplant the clean chair shadow volume into the cutscene.

screenshot

Polymega commented 5 years ago

Thank you for the latest .cam adjustment, Bigmanjapan!

This is great, FrozenFish24! Without a doubt this will be useful down the line. Do you know if shaders (I'm guessing the vertex shaders?) are what determine whether or not a geometry receives any sort of shadow on it? Or is that handled elsewhere; something more specific programmed to the game engine?

FrozenFish24 commented 5 years ago

I had a mess around and it seems to be something to do with the stencil buffer. By default the door in the Abstract Daddy room won't receive dynamic shadows because it has the STENCILENABLE render state set to TRUE:

before

Set this to FALSE and it starts to receive shadow:

after

I'm not sure if this was just an oversight or done deliberately. I'll get it working in-game and see what happens.

Polymega commented 5 years ago

Set this to FALSE and it starts to receive shadow:

image

This month just keeps getting better! Man oh man, I'm hoping this adjustment leads to something truly great and special! Well done once again, FrozenFish24!

I'm not sure if this was just an oversight or done deliberately.

I'd be willing to bet deliberately so as to also run well on the crappiest of GPUs for 2003's time.

FrozenFish24 commented 5 years ago

Okay, can confirm it works in-game too. Now to come up with a better detection mechanism so that we're not stuck white-listing every object in the game :stuck_out_tongue:

door-shadow

Here's the code I used for the door btw:

HRESULT m_IDirect3DDevice8::DrawIndexedPrimitive(THIS_ D3DPRIMITIVETYPE Type, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
    if (Type == D3DPT_TRIANGLESTRIP && primCount == 200 && NumVertices == 109) {
        DWORD stencilEnable;
        GetRenderState(D3DRS_STENCILENABLE, &stencilEnable);
        SetRenderState(D3DRS_STENCILENABLE, FALSE);
        HRESULT hr = ProxyInterface->DrawIndexedPrimitive(Type, MinVertexIndex, NumVertices, startIndex, primCount);
        SetRenderState(D3DRS_STENCILENABLE, stencilEnable);
        return hr;
    }

    return ProxyInterface->DrawIndexedPrimitive(Type, MinVertexIndex, NumVertices, startIndex, primCount);
}
FrozenFish24 commented 5 years ago

After further testing it seems the geometry that receives shadows has D3DRS_STENCILPASS set to D3DSTENCILOP_KEEP, and geometry that doesn't has it set D3DSTENCILOP_ZERO. So here's a much cleaner solution that seems to work:

HRESULT m_IDirect3DDevice8::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
{
    if (State == D3DRS_STENCILPASS && Value == D3DSTENCILOP_ZERO)
        Value = D3DSTENCILOP_KEEP;

    return ProxyInterface->SetRenderState(State, Value);
}

This will need more testing but it seems to fix at least the Abstract Daddy door and the grandfather clock. Haven't spotted any new issues either after running through the apartments, so fingers crossed.

Here's the dll: sh2e-shadowfix.zip

Bigmanjapan commented 5 years ago

55

66

77

Polymega commented 5 years ago

Great!! I planned on spending most of my Saturday play testing SH2 PC for Elisha's vertex shader fix anyway so I'll be happy to help you give this a run through as well.

@FrozenFish24 please do send me a message sometime when you can.

FrozenFish24 commented 5 years ago

@Polymega Whoops completely slipped my mind, I'll shoot you one now.

Polymega commented 5 years ago

Just some info I came across before I forget about it:


For the Hotel Chair shadow it looks like it may use a form of two-sided stencil: https://docs.microsoft.com/en-us/windows/desktop/direct3d9/two-sided-stencil

I think perhaps the character models do the same?


For DX9, something called "Precomputed Radiance Transfer" (PRT) could possibly be used for soft shadows:

PRT requires either of the following, but not both:

  • highly-tessellated models and vs_1_1
  • ps_2_0

SH2 would fall under the first category of that. Although I don't know how high a highly-tessellated model would have to be?:

https://docs.microsoft.com/en-us/windows/desktop/direct3d9/precomputed-radiance-transfer


According to this Valve dev blog, DirectX 8.1 introduced soft shadows so theoretically you wouldn't need to use DX9 to achieve the effect? However, I couldn't find any info about this with DX8.1 so I'm not sure how accurate that statement is:

https://developer.valvesoftware.com/wiki/DirectX_Versions#DirectX_8.1


Probably fully useless for this game but it was published in 2005, close-ish to SH2 PC's release window so maybe some knowledge can be extracted from it: https://www.gamedev.net/articles/programming/graphics/soft-edged-shadows-r2193/

Polymega commented 5 years ago

@elishacloud I finished play testing the game and I believe everything is good to go with your vertex shader fix for the windows/halogen lights! Great work on this fix!

Reference here: https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/63#issuecomment-444701621 And here: https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/63#issuecomment-444727997


Great work again @FrozenFish24 discovering the potential to restore shadows upon dynamic objects! I'll give this a play test soon myself! Something to think about at a later time,--and maybe this is something Elisha would also know?--but would you also know how to tell a specific/individual piece of geometry to disable shadows completely for it?

In this case, it's the window for Heaven's Night:

PC

sh2pc 2018-12-07 19-56-25

PS2/PCSX2

image

From trying to pay attention throughout the whole game as I was playing it recently, this has been the only spot so far that I've noticed shouldn't have a shadow on it.


Lastly, @FrozenFish24 , do you reckon it might be possible to add geometry to a .map file (while using the texture files associated with whatever geometry group you're adding to it)? The file in question would be hp190.map

This would be something I'd do for fun, but even way back in the early 2000's, I always thought that since this fridge has power (it lights up once you open it) you should see a power cord somewhere. I'd love to make a simple power cord coming out of the fridge and snaking away/hiding away behind the furniture against the wall:

image

If you'd think that'd be possible, would you be able to provide me an OBJ of this mesh group?

image

If it can't be done no worries and there's no point in trying to force it to work otherwise. (It's not that big of a deal to add; just something fun to do on the side.)

FrozenFish24 commented 5 years ago

It is possible to blacklist specific geometry, would you be able to provide a save file for that area? I'd also noticed the TV screen in the apartments probably shouldn't receive a shadow when it's switched on either? Would be nice if there's some generic way we can detect this, I'll look into it.

It should technically be possible to add new geometry with a lot of manual tinkering. I'm willing to give it a go for curiosity's sake. Here's the obj although it might be easier if you use an in-game capture as the basis for your edits because the fridge isn't actually part of the map: hp190.zip

Polymega commented 5 years ago

@FrozenFish24 thanks again for all the info. To start: I did notice a glitch with the new stencil shadows for dynamic objects: https://youtu.be/7UonECv1ZT4:

This may have something to do with the Z depth?


Here is a Quick Save file of the Heaven's Night window: sh2pcsave1c.zip

I'd also noticed the TV screen in the apartments probably shouldn't receive a shadow when it's switched on either?

Great minds think alike. :) I noticed this a few hours after making my earlier response here. Yes, that also shouldn't have a shadow on it.


Here's geometry for a power cord for hp190.map: hp190_power_cord.zip

And here's what it should approximately look like in the environment:

image image image

For the texture file, I used the one that is used by this geometry:

image

I placed the power cord portion of the UV group in the black void and, for the extension cord, shrunk it down and placed it within a portion of the white/cream texture of the fabric.

The normals should be preserved within the .OBJ file but, just in case they're not, they should look something roughly like this:

image

Lastly, the model is upside-down as that is how the environments get exported out when I capture them. So here would be the top/bottom for it:

image

Thanks for looking into this! I'm curious to see what's to come from this experiment. Even though the cord only has 6 sides there's a lot of divisions within it to make smooth-ish curves so the poly count will be on the higher end. And please let me know if I can help in any other way.

FrozenFish24 commented 5 years ago

@Polymega Here's a potential fix for the shadow issue when James is behind other characters. His STENCILPASS render state was set to D3DSTENCILOP_REPLACE by default so I change it to KEEP as well. This also causes him to start self-shadowing but I'm not sure if it's PS2 accurate. I'm still searching for something more robust.

fix

Updated code:

HRESULT m_IDirect3DDevice8::SetRenderState(D3DRENDERSTATETYPE State, DWORD Value)
{
    if (State == D3DRS_STENCILPASS && (Value == D3DSTENCILOP_ZERO || Value == D3DSTENCILOP_REPLACE))
        Value = D3DSTENCILOP_KEEP;

    return ProxyInterface->SetRenderState(State, Value);
}

Binary: sh2e.zip

I'm making progress on inserting the power cable too, would you be able to re-upload your obj with one of the chairs or something in it's correct relative position to the cable? Just so I can get the size and placement exact. Cheers!

Polymega commented 5 years ago

This also causes him to start self-shadowing but I'm not sure if it's PS2 accurate.

That's PS2 accurate. :) I'm happy you were able to find a fix for that relatively painless!

would you be able to re-upload your obj with one of the chairs or something in it's correct relative position to the cable?

Yes sir, here you go: hp190_power_cord_002.zip

RedPyramidThingy commented 5 years ago

You guys are awesome. Each time I think you've found a problem that can't be solved you come back with a brilliant solution. Thanks so much for your hard work. I don't have the knowledge to contribute much but if you ever need more people to test things, I'd be glad to help.

Polymega commented 5 years ago

I'll go ahead and say it: I love this team. Elisha, Aero, Bigmanjapan, FrozenFish, Nisto, and more...

I'm personally so damn happy that incredibly-talented folks are out here helping to allow future generations to more easily and correctly experience this game on modern displays/hardware.

FrozenFish24 commented 5 years ago

@Polymega Here's a little teaser. Not sure if this will actually work in-game because I don't have a save file for the area, but my script dumps it correctly and SH Level Viewer opens it too. hp190.zip

Also the game is expecting a Triangle Strip describing the geometry but I've had no luck with NvTriStrip or PyFFI as both just produce a mess of polygons. So the new indices are stored very inefficiently for now (Just a tri list stitched together with degenerate faces). This probably shouldn't affect anything besides file size though. Figured it out, zip updated.

Polymega commented 5 years ago

Here is a Quick Save save file of this room: sh2pcsave1e.zip

Figured it out, zip updated.

This is super rad! Now the fridge, which lights up from having power, actually has power going to it. So bloody cool!!

image

There's one last challenge to this I didn't anticipate: How to apply a shader to the cord for both when his light is on and off. As otherwise the mesh stays fully black:

image

FrozenFish24 commented 5 years ago

cable It looks closer to how it should from underneath. I think I must have screwed up the normals at some point.

Polymega commented 5 years ago

Those damn bloody normals... trying to get the last laugh again. Actually, since the room was exported upside down from the SH Level Viewer (and I didn't want to flip it as I assumed that's how SH2 saves/reads the rooms?) and I worked/modeled the cord upside down that would explain why the normals would also probably be upside down. Apologies about that as I think that may be the case.

FrozenFish24 commented 5 years ago

Haha, nope it wasn't your fault. Turns out it wasn't the normals it was the strip's winding order being inverted (e.g. defining a triangle's vertices [0,1,2] vs [2,1,0]). Here's the fixed map: hp190.zip cable2