浏览代码

Revert "(wip) refraction box model"

This reverts commit e375685ce235e1bf2ae15920e635204e12f15cd5.
/Add-support-for-light-specular-color-tint
Frédéric Vauchelles 7 年前
当前提交
6a14200c
共有 6 个文件被更改,包括 7 次插入90 次删除
  1. 42
      ScriptableRenderPipeline/Core/ShaderLibrary/GeometricTools.hlsl
  2. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  3. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  4. 43
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  6. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader

42
ScriptableRenderPipeline/Core/ShaderLibrary/GeometricTools.hlsl


return min(min(rbminmax.x, rbminmax.y), rbminmax.z);
}
// This simplified version assume that we care about the result only when we are inside the box
// Assume dir is normalize
// return the hit normal
float BoxRayIntersectSimple(float3 start, float3 dir, float3 boxMin, float3 boxMax, out float3 n)
{
float3 invDir = 1.0 / dir;
// Find the ray intersection with box plane
float3 firstPlaneIntersect = (boxMin - start) * invDir;
float3 secondPlaneIntersect = (boxMax - start) * invDir;
float dist = firstPlaneIntersect.x;
n = float3(boxMin.x - boxMax.x, 0.0, 0.0);
if (firstPlaneIntersect.y < dist)
{
dist = firstPlaneIntersect.y;
n = float3(0.0, boxMin.y - boxMax.y, 0.0);
}
if (firstPlaneIntersect.z < dist)
{
dist = firstPlaneIntersect.z;
n = float3(0.0, 0.0, boxMin.z - boxMax.z);
}
if (secondPlaneIntersect.x < dist)
{
dist = secondPlaneIntersect.x;
n = float3(boxMax.x - boxMin.x, 0.0, 0.0);
}
if (secondPlaneIntersect.y < dist)
{
dist = secondPlaneIntersect.y;
n = float3(0.0, boxMax.y - boxMin.y, 0.0);
}
if (secondPlaneIntersect.z < dist)
{
dist = secondPlaneIntersect.z;
n = float3(0.0, 0.0, boxMax.z - boxMin.z);
}
return dist;
}
// Assume Sphere is at the origin (i.e start = position - spherePosition)
float2 SphereRayIntersect(float3 start, float3 dir, float radius, out bool intersect)
{

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


var canHaveRefraction = !material.HasProperty(kPreRefractionPass) || material.GetFloat(kPreRefractionPass) <= 0.0;
SetKeyword(material, "_REFRACTION_PLANE", (refractionModeValue == Lit.RefractionMode.Plane) && canHaveRefraction);
SetKeyword(material, "_REFRACTION_SPHERE", (refractionModeValue == Lit.RefractionMode.Sphere) && canHaveRefraction);
SetKeyword(material, "_REFRACTION_BOX", (refractionModeValue == Lit.RefractionMode.Box) && canHaveRefraction);
}
}
} // namespace UnityEditor

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


{
None = 0,
Plane = 1,
Sphere = 2,
Box = 3
Sphere = 2
};
//-----------------------------------------------------------------------------

43
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#endif
// Define refraction keyword helpers
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE) || defined(_REFRACTION_BOX))
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE))
// In case we pack data uint16 buffer we need to change the output render target format to uint16
// TODO: Is there a way to automate these output type based on the format declare in lit.cs ?

// Sphere shape model:
// We approximate locally the shape of the object as sphere, that is tangent to the shape.
// The sphere has a diameter of {bsdfData.thickness}
// The center of the sphere is at {bsdfData.positionWS} - {bsdfData.normalWS} * {bsdfData.thickness} * 0.5
// The center of the sphere is at {bsdfData.positionWS} - {bsdfData.normalWS} * {bsdfData.thickness}
//
// So the light is refracted twice: in and out of the tangent sphere

// Refracted source point
refractedBackPointWS = P1 - R2 * (depthFromPosition - NoR1 * VoR1 * bsdfData.thickness) / N1oR2;
#elif defined(_REFRACTION_BOX)
// Box shape model:
// We approximate locally the shape of the object as box, that is tangent to the shape.
// The box has a size of {bsdfData.thickness}
// The center of the box is at {bsdfData.positionWS} - {bsdfData.normalWS} * {bsdfData.thickness} * 0.5
//
// So the light is refracted twice: in and out of the tangent box
// Get the depth of the approximated back plane
float pyramidDepth = LOAD_TEXTURE2D_LOD(_PyramidDepthTexture, posInput.positionSS * (depthSize >> 2), 2).r;
float depth = LinearEyeDepth(pyramidDepth, _ZBufferParams);
// Distance from point to the back plane
float depthFromPosition = depth - posInput.depthVS;
// First refraction (tangent box in)
// Refracted ray
float3 R1 = refract(-V, bsdfData.normalWS, 1.0 / bsdfData.ior);
float3 R1LS = float3(dot(R1, bsdfData.tangentWS), dot(R1, bsdfData.bitangentWS), dot(R1, bsdfData.normalWS));
float3 boxSize = float3(bsdfData.thickness, bsdfData.thickness, bsdfData.thickness) * 0.5;
// Second interface hit
float3 N2LS = float3(0.0, 0.0, 0.0);
opticalDepth = BoxRayIntersectSimple(float3(0.0, 0.0, 0.0), R1LS, -boxSize, boxSize, N2LS);
float3 N2WS = N2LS.x * bsdfData.tangentWS + N2LS.y * bsdfData.bitangentWS + N2LS.z * bsdfData.normalWS;
float3 P2 = posInput.positionWS + R1 * opticalDepth;
// Second refraction
float3 R2 = refract(R1, N2WS, bsdfData.ior);
float NoR1 = dot(bsdfData.normalWS, R1);
float NoR2 = dot(bsdfData.normalWS, R2);
float N2oR2 = dot(N2WS, R2);
float VoR1 = dot(V, R1);
// Refracted source point
refractedBackPointWS = P2 - R2 * (depthFromPosition - NoR1 * VoR1 * bsdfData.thickness) / N2oR2;
#endif

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2, Box, 3)]_RefractionMode("Refraction Mode", Int) = 0
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionMode("Refraction Mode", Int) = 0
_IOR("Indice Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

#pragma shader_feature _DISPLACEMENT_LOCK_TILING_SCALE
#pragma shader_feature _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE
#pragma shader_feature _VERTEX_WIND
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_BOX
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

4
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2, Box, 3)]_RefractionMode("Refraction Mode", Int) = 0
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionMode("Refraction Mode", Int) = 0
_IOR("Indice Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

#pragma shader_feature _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE
#pragma shader_feature _VERTEX_WIND
#pragma shader_feature _ _TESSELLATION_PHONG
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE _REFRACTION_BOX
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR
#pragma shader_feature _NORMALMAP_TANGENT_SPACE

正在加载...
取消
保存