浏览代码
Merge pull request #46 from Unity-Technologies/Add-distortion/DepthOffset
Merge pull request #46 from Unity-Technologies/Add-distortion/DepthOffset
HDRenderLoop: Add distortion pass control + depth offset support/main
GitHub
8 年前
当前提交
6b8997e6
共有 17 个文件被更改,包括 362 次插入 和 54 次删除
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewTiles.shader
-
4Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
-
7Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl
-
3Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs
-
7Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.hlsl
-
48Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
-
76Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Editor/BaseLitUI.cs
-
48Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
-
26Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
-
41Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitVelocityPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassGBuffer.hlsl
-
2Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
94Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDistortionPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDistortionPass.hlsl.meta
-
23Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDistortion.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDistortion.hlsl.meta
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define NEED_TANGENT_TO_WORLD NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && !defined(_HEIGHTMAP_AS_DISPLACEMENT)) |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float4 tangentOS : TANGENT; |
|||
#endif |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float3 positionWS; |
|||
float2 texCoord0; |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float3 tangentToWorld[3]; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
#if NEED_TANGENT_TO_WORLD |
|||
float4 interpolators[4] : TEXCOORD0; |
|||
#else |
|||
float4 interpolators[2] : TEXCOORD0; |
|||
#endif |
|||
}; |
|||
|
|||
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
output.interpolators[0] = float4(input.positionWS, 0.0); |
|||
|
|||
output.interpolators[0].w = input.texCoord0.x; |
|||
output.interpolators[1] = float4(0.0, 0.0, 0.0, input.texCoord0.y); |
|||
|
|||
#if NEED_TANGENT_TO_WORLD |
|||
output.interpolators[1].xyz = input.tangentToWorld[0]; |
|||
output.interpolators[2].xyz = input.tangentToWorld[1]; |
|||
output.interpolators[3].xyz = input.tangentToWorld[2]; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position |
|||
output.positionWS = input.interpolators[0].xyz; |
|||
|
|||
#if NEED_TANGENT_TO_WORLD |
|||
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w); |
|||
output.tangentToWorld[0] = input.interpolators[1].xyz; |
|||
output.tangentToWorld[1] = input.interpolators[2].xyz; |
|||
output.tangentToWorld[2] = input.interpolators[3].xyz; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
output.positionWS = TransformObjectToWorld(input.positionOS); |
|||
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix) |
|||
output.positionCS = TransformWorldToHClip(output.positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
#if NEED_TANGENT_TO_WORLD |
|||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
|
|||
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w); |
|||
output.tangentToWorld[0] = tangentToWorld[0]; |
|||
output.tangentToWorld[1] = tangentToWorld[1]; |
|||
output.tangentToWorld[2] = tangentToWorld[2]; |
|||
#endif |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a89db0bb66712eb4287e14bbafacfa15 |
|||
timeCreated: 1481762668 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if SHADERPASS != SHADERPASS_DISTORTION |
|||
#error SHADERPASS_is_not_correctly_define |
|||
#endif |
|||
|
|||
float4 Frag(PackedVaryings packedInput) : SV_Target |
|||
{ |
|||
FragInputs input = UnpackVaryings(packedInput); |
|||
|
|||
// input.unPositionSS is SV_Position |
|||
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw); |
|||
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput); |
|||
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); |
|||
|
|||
// Perform alpha testing + get distortion |
|||
SurfaceData surfaceData; |
|||
BuiltinData builtinData; |
|||
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData); |
|||
|
|||
float4 outBuffer; |
|||
EncodeDistortion(builtinData.distortion, builtinData.distortionBlur, outBuffer); |
|||
return outBuffer; |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: b6e11447d75c89a4e99bee65db7c78f5 |
|||
timeCreated: 1481762668 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue