浏览代码
Merge pull request #318 from EvgeniiG/hdrp_matrix
Merge pull request #318 from EvgeniiG/hdrp_matrix
Set HDRP matrices from scripts (except shadows)/RenderPassXR_Sandbox
GitHub
8 年前
当前提交
1fb45557
共有 36 个文件被更改,包括 548 次插入 和 395 次删除
-
2Assets/ScriptableRenderPipeline/Core/Shadow/Resources/DebugDisplayShadowMap.shader
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplayLatlong.shader
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugFullScreen.shader
-
124Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
8Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs.meta
-
30Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
-
15Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
15Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
-
14Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
-
13Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
10Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/PreIntegratedFGD.shader
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawSssProfile.shader
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs
-
1Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
-
338Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/BlitCubemap.shader
-
6Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/GGXConvolve.shader
-
3Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
-
2Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
-
7Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
-
19Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
-
13Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
-
36Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
-
171Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesFunctions.hlsl
-
10Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesFunctions.hlsl.meta
-
20Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl
-
10Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl.meta
-
20Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsLegacyUnity.hlsl
-
10Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsLegacyUnity.hlsl.meta
-
10Assets/TestScenes/HDTest/HDRenderLoopTest.meta
|
|||
#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED |
|||
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED |
|||
|
|||
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; |
|||
} |
|||
|
|||
float GetOddNegativeScale() |
|||
{ |
|||
return unity_WorldTransformParams.w; |
|||
} |
|||
|
|||
float3 TransformWorldToView(float3 positionWS) |
|||
{ |
|||
return mul(GetWorldToViewMatrix(), float4(positionWS, 1.0)).xyz; |
|||
} |
|||
|
|||
float3 TransformObjectToWorld(float3 positionOS) |
|||
{ |
|||
return mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)).xyz; |
|||
} |
|||
|
|||
float3 TransformWorldToObject(float3 positionWS) |
|||
{ |
|||
return mul(GetWorldToObjectMatrix(), float4(positionWS, 1.0)).xyz; |
|||
} |
|||
|
|||
float3 TransformObjectToWorldDir(float3 dirOS) |
|||
{ |
|||
// Normalize to support uniform scaling |
|||
return normalize(mul((float3x3)GetObjectToWorldMatrix(), dirOS)); |
|||
} |
|||
|
|||
float3 TransformWorldToObjectDir(float3 dirWS) |
|||
{ |
|||
// Normalize to support uniform scaling |
|||
return normalize(mul((float3x3)GetWorldToObjectMatrix(), dirWS)); |
|||
} |
|||
|
|||
// Transforms normal from object to world space |
|||
float3 TransformObjectToWorldNormal(float3 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, (float3x3)GetWorldToObjectMatrix())); |
|||
#endif |
|||
} |
|||
|
|||
// Tranforms position from world space to homogenous space |
|||
float4 TransformWorldToHClip(float3 positionWS) |
|||
{ |
|||
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0)); |
|||
} |
|||
|
|||
float3 GetCurrentCameraPosition() |
|||
{ |
|||
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS) |
|||
return _WorldSpaceCameraPos; |
|||
#else |
|||
// TEMP: this is rather expensive. Then again, we need '_WorldSpaceCameraPos' |
|||
// to represent the position of the primary (scene view) camera in order to |
|||
// have identical tessellation levels for both the scene view and shadow views. |
|||
// Otherwise, depth comparisons become meaningless! |
|||
float4x4 trViewMat = transpose(GetWorldToViewMatrix()); |
|||
float3 rotCamPos = trViewMat[3].xyz; |
|||
return mul((float3x3)trViewMat, -rotCamPos); |
|||
#endif |
|||
} |
|||
|
|||
// Returns the forward direction of the current camera in the world space. |
|||
float3 GetCameraForwardDir() |
|||
{ |
|||
float4x4 viewMat = GetWorldToViewMatrix(); |
|||
return -viewMat[2].xyz; |
|||
} |
|||
|
|||
// Returns 'true' if the current camera performs a perspective projection. |
|||
bool IsPerspectiveCamera() |
|||
{ |
|||
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS) |
|||
return (unity_OrthoParams.w == 0); |
|||
#else |
|||
// TODO: set 'unity_OrthoParams' during the shadow pass. |
|||
return (GetWorldToHClipMatrix()[3].x != 0 || |
|||
GetWorldToHClipMatrix()[3].y != 0 || |
|||
GetWorldToHClipMatrix()[3].z != 0 || |
|||
GetWorldToHClipMatrix()[3].w != 1); |
|||
#endif |
|||
} |
|||
|
|||
// Computes the world space view direction (pointing towards the camera). |
|||
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS) |
|||
{ |
|||
if (IsPerspectiveCamera()) |
|||
{ |
|||
// Perspective |
|||
float3 V = GetCurrentCameraPosition() - positionWS; |
|||
return normalize(V); |
|||
} |
|||
else |
|||
{ |
|||
// Orthographic |
|||
return -GetCameraForwardDir(); |
|||
} |
|||
} |
|||
|
|||
float3x3 CreateWorldToTangent(float3 normal, float3 tangent, float flipSign) |
|||
{ |
|||
// For odd-negative scale transforms we need to flip the sign |
|||
float sgn = flipSign * GetOddNegativeScale(); |
|||
float3 bitangent = cross(normal, tangent) * sgn; |
|||
|
|||
return float3x3(tangent, bitangent, normal); |
|||
} |
|||
|
|||
float3 TransformTangentToWorld(float3 dirTS, float3x3 worldToTangent) |
|||
{ |
|||
// Use transpose transformation to go from tangent to world as the matrix is orthogonal |
|||
return mul(dirTS, worldToTangent); |
|||
} |
|||
|
|||
float3 TransformWorldToTangent(float3 dirWS, float3x3 worldToTangent) |
|||
{ |
|||
return mul(worldToTangent, dirWS); |
|||
} |
|||
|
|||
float3 TransformTangentToObject(float3 dirTS, float3x3 worldToTangent) |
|||
{ |
|||
// Use transpose transformation to go from tangent to world as the matrix is orthogonal |
|||
float3 normalWS = mul(dirTS, worldToTangent); |
|||
return mul((float3x3)GetWorldToObjectMatrix(), normalWS); |
|||
} |
|||
|
|||
float3 TransformObjectToTangent(float3 dirOS, float3x3 worldToTangent) |
|||
{ |
|||
return mul(worldToTangent, TransformObjectToWorldDir(dirOS)); |
|||
} |
|||
|
|||
// UNITY_MATRIX_V defines a right-handed view space with the Z axis pointing towards the viewer. |
|||
// This function reverses the direction of the Z axis (so that it points forward), |
|||
// making the view space coordinate system left-handed. |
|||
void GetLeftHandedViewSpaceMatrices(out float4x4 viewMatrix, out float4x4 projMatrix) |
|||
{ |
|||
viewMatrix = UNITY_MATRIX_V; |
|||
viewMatrix._31_32_33_34 = -viewMatrix._31_32_33_34; |
|||
|
|||
projMatrix = UNITY_MATRIX_P; |
|||
projMatrix._13_23_33_43 = -projMatrix._13_23_33_43; |
|||
} |
|||
|
|||
#endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 919263f29f66aed49a283fe1f971c094 |
|||
timeCreated: 1498227267 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifdef UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED |
|||
#error Mixing HDCamera and legacy Unity matrix definitions |
|||
#endif |
|||
|
|||
#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED |
|||
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED |
|||
|
|||
#define UNITY_MATRIX_M unity_ObjectToWorld |
|||
#define UNITY_MATRIX_I_M unity_WorldToObject |
|||
#define UNITY_MATRIX_V _ViewMatrix |
|||
#define UNITY_MATRIX_I_V _InvViewMatrix |
|||
#define UNITY_MATRIX_P _ProjMatrix |
|||
#define UNITY_MATRIX_I_P _InvProjMatrix |
|||
#define UNITY_MATRIX_VP _ViewProjMatrix |
|||
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) |
|||
#define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M) |
|||
#define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) |
|||
#define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) |
|||
|
|||
#endif // UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 6ebd64e795ba636469c74676014ac454 |
|||
timeCreated: 1498228363 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifdef UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED |
|||
#error Mixing HDCamera and legacy Unity matrix definitions |
|||
#endif |
|||
|
|||
#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED |
|||
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED |
|||
|
|||
#define UNITY_MATRIX_M unity_ObjectToWorld |
|||
#define UNITY_MATRIX_I_M unity_WorldToObject |
|||
#define UNITY_MATRIX_V unity_MatrixV |
|||
#define UNITY_MATRIX_I_V unity_MatrixInvV |
|||
#define UNITY_MATRIX_P glstate_matrix_projection |
|||
#define UNITY_MATRIX_I_P inverse_glstate_matrix_projection_is_not_defined |
|||
#define UNITY_MATRIX_VP unity_MatrixVP |
|||
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M) |
|||
#define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M) |
|||
#define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV) |
|||
#define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) |
|||
|
|||
#endif // UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED |
|
|||
fileFormatVersion: 2 |
|||
guid: 77ec57a2ba7588b4b96bc4c87934003f |
|||
timeCreated: 1498228363 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c2d16fcd50b9fda4b908060b0afcd890 |
|||
folderAsset: yes |
|||
timeCreated: 1497448738 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue