浏览代码

More bugfixes for volume texture sampling

/main
Evgenii Golubev 6 年前
当前提交
a5b000b4
共有 3 个文件被更改,包括 25 次插入18 次删除
  1. 3
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl
  2. 33
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  3. 7
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs

3
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Common.hlsl


return ComputeTextureLOD(uv);
}
// LOD clamp is optional and happens outside the function.
return max(0.0, 0.5 * log2(d * (scale * scale)));
return 0.5 * log2(d * (scale * scale));
}

33
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute


float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float3 _VolumeMaskDimensions; //x = 1/totalTextures , y = 1/textureSize, z = textureSize
float4 _VolumeMaskDimensions; //x = 1/numTextures , y = width, z = depth = width * numTextures, w = maxLod
CBUFFER_END
//--------------------------------------------------------------------------------------------------

{
float offset = volumeData.textureIndex * _VolumeMaskDimensions.x;
// Scale and bias the UVWs and then take fractional part, will be in [0,1] range.
voxelCenterUVW = frac(voxelCenterUVW * volumeData.textureTiling + volumeData.textureScroll);
//scale and bias the UVWs and then take fractional part, will be in [0,1] range
voxelCenterUVW = frac(voxelCenterUVW * volumeData.textureTiling + volumeData.textureScroll);
float rcpNumTextures = _VolumeMaskDimensions.x;
float textureWidth = _VolumeMaskDimensions.y;
float textureDepth = _VolumeMaskDimensions.z;
float maxLod = _VolumeMaskDimensions.w;
voxelCenterUVW.z = voxelCenterUVW.z * _VolumeMaskDimensions.x;
voxelCenterUVW.z += offset;
float offset = volumeData.textureIndex * rcpNumTextures;
voxelCenterUVW.z = voxelCenterUVW.z * rcpNumTextures + offset;
float lod = ComputeTextureLOD(duvw_dx, duvw_dy, duvw_dz, _VolumeMaskDimensions.z);
float lod = ComputeTextureLOD(duvw_dx, duvw_dy, duvw_dz, textureWidth);
lod = clamp(lod, 0, maxLod);
// Secondly, for trilinear filering, which of the two LoDs should you choose to compute the distance to the edge?
// If you use floor(lod), the lower LoD may cause the leak across the edge from the neighbour texture.
// If you use ceil(lod), the upper LoD effectively loses a texel at the border, which may break tilable textures.
// Secondly, for trilinear filtering, which of the two LoDs should you choose to compute the distance to the edge?
// If you use floor(lod), the lower LoD may cause a leak across the edge from the neighbor texture.
// If you use ceil(lod), the upper LoD effectively loses a texel at the border, which may break tileable textures.
int textureSize = (int)_VolumeMaskDimensions.z;
int mipSize = textureSize >> (int)ceil(lod);
float clampBorder = 0.5f * rcp(mipSize);
voxelCenterUVW.z = clamp(voxelCenterUVW.z, offset + clampBorder, offset + _VolumeMaskDimensions.x - clampBorder);
// We support texture filtering across the wrap in Z in neither case.
int textureSize = (int)textureDepth;
int mipSize = textureSize >> (int)ceil(lod);
float halfTexelSize = 0.5f * rcp(mipSize);
voxelCenterUVW.z = clamp(voxelCenterUVW.z, offset + halfTexelSize, offset + rcpNumTextures - halfTexelSize);
return SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_trilinear_clamp_sampler, voxelCenterUVW, lod).a;
}

7
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


Matrix4x4 transform = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(vFoV, resolution, hdCamera.viewMatrix, false);
Texture3D volumeAtlas = DensityVolumeManager.manager.volumeAtlas.volumeAtlas;
Vector3 volumeAtlasDimensions = new Vector3(0.0f, 0.0f, 0.0f);
Vector4 volumeAtlasDimensions = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
volumeAtlasDimensions.y = 1.0f / volumeAtlas.width;
volumeAtlasDimensions.z = volumeAtlas.width;
volumeAtlasDimensions.y = volumeAtlas.width;
volumeAtlasDimensions.z = volumeAtlas.depth;
volumeAtlasDimensions.w = Mathf.Log(volumeAtlas.width, 2); // Max LoD
}
else
{

正在加载...
取消
保存