浏览代码

* Disabled occlusion culling for WaterDepth capture camera. (To workaround issue on Quest)

* Changed samplers for water depth and scene depth to workaround Quest issue. (Quest uses point sampler pre the change)
* Added inverseZ handling to waterDepth map.
* Comment out unused code in WaterLighting.hlsl
/boatattack-xr-add-xr-support
thomas-zeng 4 年前
当前提交
040d9d7a
共有 4 个文件被更改,包括 16 次插入10 次删除
  1. 2
      Packages/com.verasl.water-system/Scripts/Water.cs
  2. 8
      Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl
  3. 4
      Packages/com.verasl.water-system/Shaders/WaterInput.hlsl
  4. 12
      Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl

2
Packages/com.verasl.water-system/Scripts/Water.cs


additionalCamData.renderShadows = false;
additionalCamData.requiresColorOption = CameraOverrideOption.Off;
additionalCamData.requiresDepthOption = CameraOverrideOption.Off;
additionalCamData.allowXRRendering = false;
var t = _depthCam.transform;
var depthExtra = 4.0f;

_depthCam.allowHDR = false;
_depthCam.allowMSAA = false;
_depthCam.cullingMask = (1 << 10);
_depthCam.useOcclusionCulling = false; // XRTODO: Workaround Quest issue. When occlusion culling is enabled on Quest, we see part of terrain is over culled.
//Generate RT
if (!_depthTex)
_depthTex = new RenderTexture(1024, 1024, 24, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear);

8
Packages/com.verasl.water-system/Shaders/WaterCommon.hlsl


float2 AdjustedDepth(half2 uvs, half4 additionalData)
{
float rawD = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_ScreenTextures_linear_clamp, uvs).r;
float rawD = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture_linear_clamp, uvs).r;
float d = LinearEyeDepth(rawD, _ZBufferParams);
return float2(d * additionalData.x - additionalData.y, (rawD * -_ProjectionParams.x) + (1-UNITY_REVERSED_Z));
}

return (1 - SAMPLE_TEXTURE2D_LOD(_WaterDepthMap, sampler_WaterDepthMap_linear_clamp, posWS.xz * 0.002 + 0.5, 1).r) * (_MaxDepth + _VeraslWater_DepthCamParams.x) - _VeraslWater_DepthCamParams.x;
#if UNITY_REVERSED_Z
return (1 - SAMPLE_TEXTURE2D_LOD(_WaterDepthMap, sampler_ScreenTextures_linear_clamp, posWS.xz * 0.002 + 0.5, 1).r) * (_MaxDepth + _VeraslWater_DepthCamParams.x) - _VeraslWater_DepthCamParams.x;
#else
return (SAMPLE_TEXTURE2D_LOD(_WaterDepthMap, sampler_ScreenTextures_linear_clamp, posWS.xz * 0.002 + 0.5, 1).r) * (_MaxDepth + _VeraslWater_DepthCamParams.x) - _VeraslWater_DepthCamParams.x;
#endif
}
float3 WaterDepth(float3 posWS, half4 additionalData, half2 screenUVs)// x = seafloor depth, y = water depth

4
Packages/com.verasl.water-system/Shaders/WaterInput.hlsl


SAMPLER(sampler_CubemapTexture);
#endif
TEXTURE2D_X(_WaterFXMap);
TEXTURE2D_X(_CameraDepthTexture);
TEXTURE2D_X(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture_linear_clamp);
TEXTURE2D(_WaterDepthMap); SAMPLER(sampler_WaterDepthMap_linear_clamp);
TEXTURE2D(_WaterDepthMap);
// Surface textures
TEXTURE2D(_AbsorptionScatteringRamp); SAMPLER(sampler_AbsorptionScatteringRamp);

12
Packages/com.verasl.water-system/Shaders/WaterLighting.hlsl


reflection = GlossyEnvironmentReflection(reflectVector, 0, 1);
#elif _REFLECTION_PLANARREFLECTION
// get the perspective projection
float2 p11_22 = float2(unity_CameraInvProjection._11, unity_CameraInvProjection._22) * 10;
// conver the uvs into view space by "undoing" projection
float3 viewDir = -(float3((screenUV * 2 - 1) / p11_22, -1));
//// get the perspective projection
//float2 p11_22 = float2(unity_CameraInvProjection._11, unity_CameraInvProjection._22) * 10;
//// conver the uvs into view space by "undoing" projection
//float3 viewDir = -(float3((screenUV * 2 - 1) / p11_22, -1));
half3 viewNormal = mul(normalWS, (float3x3)GetWorldToViewMatrix()).xyz;
half3 reflectVector = reflect(-viewDir, viewNormal);
//half3 viewNormal = mul(normalWS, (float3x3)GetWorldToViewMatrix()).xyz;
//half3 reflectVector = reflect(-viewDir, viewNormal);
half2 reflectionUV = screenUV + normalWS.zx * half2(0.02, 0.15);
reflection += SAMPLE_TEXTURE2D_LOD(_PlanarReflectionTexture, sampler_ScreenTextures_linear_clamp, reflectionUV, 6 * roughness).rgb;//planar reflection

正在加载...
取消
保存