John Parsaie
7 年前
当前提交
4c2af84a
共有 12 个文件被更改,包括 241 次插入 和 245 次删除
-
5ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
-
15ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineResources.cs
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/DiffusionProfile/DiffusionProfileSettings.cs
-
1ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
-
238ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/CoreFunctions.hlsl
-
158ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader
-
18ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/DrawTransmittanceGraph.shader.meta
-
15ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader
-
18ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader/PreintegratedScatter.shader.meta
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader.meta
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/Subsurface/DiffusionProfile.meta
-
0/ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/DiffusionProfile/Shader
|
|||
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; |
|||
} |
|
|||
#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 |
|
|||
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 |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: db930d68409d0d94ebbb2a14fa07f3ee |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
fileFormatVersion: 2 |
|||
guid: db930d68409d0d94ebbb2a14fa07f3ee |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c509c4fbe7201384f9bfea1d062070a6 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
fileFormatVersion: 2 |
|||
guid: c509c4fbe7201384f9bfea1d062070a6 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7bad08ede8981d44eaf9e3571df6c42c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1790e4a0d6a8b8443b88dfcff73cc9fe |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue