NVIDIAGameWorks / rtx-remix

Combined repo for the RTX-Remix runtime
https://www.nvidia.com/en-us/geforce/rtx-remix/
MIT License
1.35k stars 68 forks source link

Allow AperturePBR_Portal material-shader to properly function on replacement meshes. #236

Open Kamilkampfwagen-II opened 1 year ago

Kamilkampfwagen-II commented 1 year ago

In order to get AperturePBR_Portal material shader working, a pair of texture hashes needed to be configured: rtx.rayPortalModelTextureHashes = textureHash1, textureHash2 The code block enforcing this requirement here.

However replacement materials don't have such runtime hashes thus this limitation prevents portals to be used on replacement meshes.

Mark's statement on this:

That code could be changed to check the overrideMaterialData's type, and check if it already has a portal_index property.

Link to that Discord message

MarkEHenderson commented 1 year ago

I looked into this a bit further.

We currently depend on a 2nd texture that Portal feeds into the original portal draw calls, which serves as a mask to show which parts of the original draw call should forward a portal (basically just a circle, but I believe with some changes when the portal is opening / closing).

If the draw call being replaced is not one of Portal's original portal draw calls, this would mask texture would need to be part of the replacement material, and would be static.

Right now replacement materials will just uses the albedo texture for both texture1 and texture 2 when it loads a portal material. In the shader, it just checks if the red value of a pixel is > 0.5f. So if the texture you're setting as emissive_mask_texture has a red value about 0.5, that pixel will be considered to be a portal, and as far as I can tell it should function as a portal.

You might try replacing the spritesheet currently set on the materials with a simple texture consisting of a transparent black background (pixel values 0,0,0,0) with a solid white circle in the center (pixel values 1,1,1,1). Make sure to also remove the sprite_sheet properties when you do that.

When you want to make it look a bit nicer, you can change the black part to be whatever, as long as the red channel stays under 0.5 (or 128 if you're dealing with 0-255 range).

Kamilkampfwagen-II commented 1 year ago

I created the mask texture. (0,0,0,0) frame and (255,255,255,255) circle at the center. Set it as emissive mask texture of the portal material. Portal indexes are double checked. Every other material property is at its default. mask

Although this steps had an impact on the result, portals are still glitchy and non functional.

https://github.com/NVIDIAGameWorks/rtx-remix/assets/84380947/222db146-f5c4-4617-8b7c-df09a5006a63

This is how the portal material implemented: https://gist.github.com/Kamilkampfwagen-II/a3b9096952c4955210e770218d3572c6

The replacement mesh containing two portals: https://gist.github.com/Kamilkampfwagen-II/44bf1e1349fbb2108d6240462b1d6912

NV-DM commented 9 months ago

REMIX-915 for tracking.