浏览代码

Potential fix to the broken preintegrator, checking OSX

/projects-TheLastStand
John Parsaie 7 年前
当前提交
4c2af84a
共有 12 个文件被更改,包括 241 次插入245 次删除
  1. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 15
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs
  3. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/DiffusionProfile/DiffusionProfileSettings.cs
  4. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  5. 238
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/CoreFunctions.hlsl
  6. 158
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader
  7. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader.meta
  8. 15
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader
  9. 18
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader.meta
  10. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader.meta
  11. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/DiffusionProfile.meta
  12. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


{
get { return resources != null ? resources.ScreenSpaceShadowShader : null; }
}
public Shader PreintegratedScatterShader
{
get { return resources != null ? resources.PreintegratedScatterShader : null; }
}
}
}

15
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs


using UnityEngine;
public class LightweightPipelineResources : ScriptableObject
{
public Shader BlitShader;
public Shader CopyDepthShader;
public Shader ScreenSpaceShadowShader;
public Shader PreintegratedScatterShader;
using UnityEngine;
public class LightweightPipelineResources : ScriptableObject
{
public Shader BlitShader;
public Shader CopyDepthShader;
public Shader ScreenSpaceShadowShader;
}

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/DiffusionProfile/DiffusionProfileSettings.cs


}
public void BakeLUT()
{
{
CommandBuffer cmd = new CommandBuffer() { name = "BuildLUT" };
Material preintegration = CoreUtils.CreateEngineMaterial("Hidden/LightweightPipeline/PreintegratedScatter");

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


m_BlitMaterial = CoreUtils.CreateEngineMaterial(m_Asset.BlitShader);
m_CopyDepthMaterial = CoreUtils.CreateEngineMaterial(m_Asset.CopyDepthShader);
m_ScreenSpaceShadowsMaterial = CoreUtils.CreateEngineMaterial(m_Asset.ScreenSpaceShadowShader);
m_PreintegratedScatterMaterial = CoreUtils.CreateEngineMaterial(m_Asset.PreintegratedScatterShader);
m_ErrorMaterial = CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader");
}

238
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/CoreFunctions.hlsl


#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
float3 GetCameraPositionWS()
{
return _WorldSpaceCameraPos;
}
float4x4 GetWorldToViewMatrix()
{
return UNITY_MATRIX_V;
}
float4x4 GetObjectToWorldMatrix()
{
return UNITY_MATRIX_M;
}
float4x4 GetWorldToObjectMatrix()
{
return UNITY_MATRIX_I_M;
}
// Transform to homogenous clip space
float4x4 GetWorldToHClipMatrix()
{
return UNITY_MATRIX_VP;
}
real GetOddNegativeScale()
{
return unity_WorldTransformParams.w;
}
float3 TransformWorldToView(float3 positionWS)
{
return mul(GetWorldToViewMatrix(), real4(positionWS, 1.0)).xyz;
}
float3 TransformObjectToWorld(float3 positionOS)
{
return mul(GetObjectToWorldMatrix(), real4(positionOS, 1.0)).xyz;
}
float3 TransformWorldToObject(float3 positionWS)
{
return mul(GetWorldToObjectMatrix(), float4(positionWS, 1.0)).xyz;
}
real3 TransformObjectToWorldDir(real3 dirOS)
{
// Normalize to support uniform scaling
return normalize(mul((real3x3)GetObjectToWorldMatrix(), dirOS));
}
real3 TransformWorldToObjectDir(real3 dirWS)
{
// Normalize to support uniform scaling
return normalize(mul((real3x3)GetWorldToObjectMatrix(), dirWS));
}
// Transforms normal from object to world space
real3 TransformObjectToWorldNormal(real3 normalOS)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(normalOS);
#else
// Normal need to be multiply by inverse transpose
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(normalOS, (real3x3)GetWorldToObjectMatrix()));
#endif
}
// Transforms position from object space to homogenous space
float4 TransformObjectToHClip(float3 positionOS)
{
// More efficient than computing M*VP matrix product
return mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)));
}
// Tranforms position from world space to homogenous space
float4 TransformWorldToHClip(float3 positionWS)
{
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
}
real3x3 CreateWorldToTangent(real3 normal, real3 tangent, real flipSign)
{
// For odd-negative scale transforms we need to flip the sign
real sgn = flipSign * GetOddNegativeScale();
real3 bitangent = cross(normal, tangent) * sgn;
return real3x3(tangent, bitangent, normal);
}
real3 TransformTangentToWorld(real3 dirTS, real3x3 worldToTangent)
{
// Use transpose transformation to go from tangent to world as the matrix is orthogonal
return mul(dirTS, worldToTangent);
}
real3 TransformWorldToTangent(real3 dirWS, real3x3 worldToTangent)
{
return mul(worldToTangent, dirWS);
}
real3 TransformTangentToObject(real3 dirTS, real3x3 worldToTangent)
{
// Use transpose transformation to go from tangent to world as the matrix is orthogonal
real3 normalWS = mul(dirTS, worldToTangent);
return mul((real3x3)GetWorldToObjectMatrix(), normalWS);
}
real3 TransformObjectToTangent(real3 dirOS, real3x3 worldToTangent)
{
return mul(worldToTangent, TransformObjectToWorldDir(dirOS));
}
#endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
float3 GetCameraPositionWS()
{
return _WorldSpaceCameraPos;
}
float4x4 GetWorldToViewMatrix()
{
return UNITY_MATRIX_V;
}
float4x4 GetObjectToWorldMatrix()
{
return UNITY_MATRIX_M;
}
float4x4 GetWorldToObjectMatrix()
{
return UNITY_MATRIX_I_M;
}
// Transform to homogenous clip space
float4x4 GetWorldToHClipMatrix()
{
return UNITY_MATRIX_VP;
}
real GetOddNegativeScale()
{
return unity_WorldTransformParams.w;
}
float3 TransformWorldToView(float3 positionWS)
{
return mul(GetWorldToViewMatrix(), real4(positionWS, 1.0)).xyz;
}
float3 TransformObjectToWorld(float3 positionOS)
{
return mul(GetObjectToWorldMatrix(), real4(positionOS, 1.0)).xyz;
}
float3 TransformWorldToObject(float3 positionWS)
{
return mul(GetWorldToObjectMatrix(), float4(positionWS, 1.0)).xyz;
}
real3 TransformObjectToWorldDir(real3 dirOS)
{
// Normalize to support uniform scaling
return normalize(mul((real3x3)GetObjectToWorldMatrix(), dirOS));
}
real3 TransformWorldToObjectDir(real3 dirWS)
{
// Normalize to support uniform scaling
return normalize(mul((real3x3)GetWorldToObjectMatrix(), dirWS));
}
// Transforms normal from object to world space
real3 TransformObjectToWorldNormal(real3 normalOS)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(normalOS);
#else
// Normal need to be multiply by inverse transpose
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(normalOS, (real3x3)GetWorldToObjectMatrix()));
#endif
}
// Transforms position from object space to homogenous space
float4 TransformObjectToHClip(float3 positionOS)
{
// More efficient than computing M*VP matrix product
return mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)));
}
// Tranforms position from world space to homogenous space
float4 TransformWorldToHClip(float3 positionWS)
{
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
}
real3x3 CreateWorldToTangent(real3 normal, real3 tangent, real flipSign)
{
// For odd-negative scale transforms we need to flip the sign
real sgn = flipSign * GetOddNegativeScale();
real3 bitangent = cross(normal, tangent) * sgn;
return real3x3(tangent, bitangent, normal);
}
real3 TransformTangentToWorld(real3 dirTS, real3x3 worldToTangent)
{
// Use transpose transformation to go from tangent to world as the matrix is orthogonal
return mul(dirTS, worldToTangent);
}
real3 TransformWorldToTangent(real3 dirWS, real3x3 worldToTangent)
{
return mul(worldToTangent, dirWS);
}
real3 TransformTangentToObject(real3 dirTS, real3x3 worldToTangent)
{
// Use transpose transformation to go from tangent to world as the matrix is orthogonal
real3 normalWS = mul(dirTS, worldToTangent);
return mul((real3x3)GetWorldToObjectMatrix(), normalWS);
}
real3 TransformObjectToTangent(real3 dirOS, real3x3 worldToTangent)
{
return mul(worldToTangent, TransformObjectToWorldDir(dirOS));
}
#endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED

158
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader


Shader "Hidden/LightweightPipeline/DrawTransmittanceGraph"
{
SubShader
{
Pass
{
Cull Off
ZTest Always
ZWrite Off
Blend Off
HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#pragma vertex Vert
#pragma fragment Frag
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl"
#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "HDRP/ShaderVariables.hlsl"
#include "HDRP/Material/DiffusionProfile/DiffusionProfile.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs
//-------------------------------------------------------------------------------------
float4 _HalfRcpVarianceAndWeight1, _HalfRcpVarianceAndWeight2;
float4 _TransmissionTint, _ThicknessRemap;
//-------------------------------------------------------------------------------------
// Implementation
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float d = (_ThicknessRemap.x + input.texcoord.x * (_ThicknessRemap.y - _ThicknessRemap.x));
float3 T;
T = ComputeTransmittanceJimenez(_HalfRcpVarianceAndWeight1.rgb,
_HalfRcpVarianceAndWeight1.a,
_HalfRcpVarianceAndWeight2.rgb,
_HalfRcpVarianceAndWeight2.a,
float3(0.25, 0.25, 0.25), d);
// Apply gamma for visualization only. Do not apply gamma to the color.
return float4(sqrt(T) * _TransmissionTint.rgb, 1);
}
ENDHLSL
}
}
Fallback Off
}
Shader "Hidden/LightweightPipeline/DrawTransmittanceGraph"
{
SubShader
{
Pass
{
Cull Off
ZTest Always
ZWrite Off
Blend Off
HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#pragma vertex Vert
#pragma fragment Frag
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/CommonMaterial.hlsl"
#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "HDRP/ShaderVariables.hlsl"
#include "HDRP/Material/DiffusionProfile/DiffusionProfile.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs
//-------------------------------------------------------------------------------------
float4 _HalfRcpVarianceAndWeight1, _HalfRcpVarianceAndWeight2;
float4 _TransmissionTint, _ThicknessRemap;
//-------------------------------------------------------------------------------------
// Implementation
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float d = (_ThicknessRemap.x + input.texcoord.x * (_ThicknessRemap.y - _ThicknessRemap.x));
float3 T;
T = ComputeTransmittanceJimenez(_HalfRcpVarianceAndWeight1.rgb,
_HalfRcpVarianceAndWeight1.a,
_HalfRcpVarianceAndWeight2.rgb,
_HalfRcpVarianceAndWeight2.a,
float3(0.25, 0.25, 0.25), d);
// Apply gamma for visualization only. Do not apply gamma to the color.
return float4(sqrt(T) * _TransmissionTint.rgb, 1);
}
ENDHLSL
}
}
Fallback Off
}

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader.meta


fileFormatVersion: 2
guid: db930d68409d0d94ebbb2a14fa07f3ee
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: db930d68409d0d94ebbb2a14fa07f3ee
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

15
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader


// Include
//-------------------------------------------------------------------------------------
#include "CoreRP/ShaderLibrary/Common.hlsl"
#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "HDRP/ShaderVariables.hlsl"
#include "LWRP/DiffusionProfile/DiffusionProfileSettings.cs.hlsl"
#define PI 3.14159265358979323846
#define TWO_PI 6.28318530717958647693
float4x4 unity_MatrixVP;
#define DIFFUSION_PROFILE_COUNT (4)
#define DIFFUSION_PROFILE_NEUTRAL_ID (0)
#define SSS_N_SAMPLES (11)
#define SSS_DISTANCE_SCALE (3)
//-------------------------------------------------------------------------------------
// Inputs & outputs

Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.vertex = mul(unity_MatrixVP, float4(input.vertex.xyz, 1)); //TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}

18
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader.meta


fileFormatVersion: 2
guid: c509c4fbe7201384f9bfea1d062070a6
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c509c4fbe7201384f9bfea1d062070a6
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader.meta


fileFormatVersion: 2
guid: 7bad08ede8981d44eaf9e3571df6c42c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/DiffusionProfile.meta


fileFormatVersion: 2
guid: 1790e4a0d6a8b8443b88dfcff73cc9fe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/DiffusionProfile → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader

正在加载...
取消
保存