浏览代码
Merge pull request #98 from Unity-Technologies/Vertex-interpolator-and-tesselation-improvement
Merge pull request #98 from Unity-Technologies/Vertex-interpolator-and-tesselation-improvement
Change Vertex / attributes / Interpolator management/main
GitHub
8 年前
当前提交
531082c1
共有 49 个文件被更改,包括 2420 次插入 和 1202 次删除
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta
-
37Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
49Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
24Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
44Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
-
91Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
25Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
61Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
67Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
195Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
173Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
91Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
-
252Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
-
215Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
111Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
-
49Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
-
126Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
-
1Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
-
10Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta
-
69Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl.meta
-
363Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl.meta
-
182Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl.meta
-
1001Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset
-
8Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset.meta
-
13Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl.meta
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl
-
61Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
|
|||
fileFormatVersion: 2 |
|||
guid: e185fecca3c73cd47a09f1092663ef32 |
|||
timeCreated: 1483606455 |
|||
timeCreated: 1484329328 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
CBUFFER_START(UnityMetaPass) |
|||
// x = use uv1 as raster position |
|||
// y = use uv2 as raster position |
|||
bool4 unity_MetaVertexControl; |
|||
|
|||
// x = return albedo |
|||
// y = return normal |
|||
bool4 unity_MetaFragmentControl; |
|||
|
|||
CBUFFER_END |
|||
|
|||
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency |
|||
float unity_OneOverOutputBoost; |
|||
float unity_MaxOutputValue; |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
float2 uv0 : TEXCOORD0; |
|||
float2 uv1 : TEXCOORD1; |
|||
float2 uv2 : TEXCOORD2; |
|||
}; |
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float2 texCoord0; |
|||
float2 texCoord1; |
|||
}; |
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
// 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].xy = input.texCoord0; |
|||
output.interpolators[0].zw = input.texCoord1; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position |
|||
output.texCoord0 = input.interpolators[0].xy; |
|||
output.texCoord1 = input.interpolators[0].zw; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
// Output UV coordinate in vertex shader |
|||
if (unity_MetaVertexControl.x) |
|||
{ |
|||
input.positionOS.xy = input.uv1 * unity_LightmapST.xy + unity_LightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
if (unity_MetaVertexControl.y) |
|||
{ |
|||
input.positionOS.xy = input.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; |
|||
// OpenGL right now needs to actually use incoming vertex position, |
|||
// so use it in a very dummy way |
|||
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f; |
|||
} |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
output.texCoord0 = input.uv0; |
|||
output.texCoord1 = input.uv1; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: 83421d7ac8db22148903e8ecee502314 |
|||
folderAsset: yes |
|||
timeCreated: 1484323639 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1e29a17691259ac4e9de48d4cfd72d06 |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct TessellationFactors |
|||
{ |
|||
float edge[3] : SV_TessFactor; |
|||
float inside : SV_InsideTessFactor; |
|||
}; |
|||
|
|||
TessellationFactors HullConstant(InputPatch<PackedVaryingsToDS, 3> input) |
|||
{ |
|||
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]); |
|||
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]); |
|||
VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]); |
|||
|
|||
float4 tf = TessellationEdge( varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS, |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS |
|||
#else |
|||
float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0) |
|||
#endif |
|||
); |
|||
|
|||
TessellationFactors ouput; |
|||
ouput.edge[0] = tf.x; |
|||
ouput.edge[1] = tf.y; |
|||
ouput.edge[2] = tf.z; |
|||
ouput.inside = tf.w; |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
[maxtessfactor(15.0)] // AMD recommand this value for GCN http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/05/GCNPerformanceTweets.pdf |
|||
[domain("tri")] |
|||
[partitioning("fractional_odd")] |
|||
[outputtopology("triangle_cw")] |
|||
[patchconstantfunc("HullConstant")] |
|||
[outputcontrolpoints(3)] |
|||
PackedVaryingsToDS Hull(InputPatch<PackedVaryingsToDS, 3> input, uint id : SV_OutputControlPointID) |
|||
{ |
|||
// Pass-through |
|||
return input[id]; |
|||
} |
|||
|
|||
[domain("tri")] |
|||
PackedVaryingsToPS Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsToDS, 3> input, float3 baryCoords : SV_DomainLocation) |
|||
{ |
|||
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]); |
|||
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]); |
|||
VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]); |
|||
|
|||
VaryingsToDS varying = InterpolateWithBaryCoordsToDS(varying0, varying1, varying2, baryCoords); |
|||
|
|||
// We have Phong tessellation in all case where we don't have displacement only |
|||
#ifndef _TESSELLATION_DISPLACEMENT |
|||
varying.vmesh.positionWS = PhongTessellation( varying.vmesh.positionWS, |
|||
varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS, |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS, |
|||
#else |
|||
float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0), |
|||
#endif |
|||
baryCoords, _TessellationShapeFactor); |
|||
#endif |
|||
|
|||
#if defined(_TESSELLATION_DISPLACEMENT) || defined(_TESSELLATION_DISPLACEMENT_PHONG) |
|||
varying.vmesh.positionWS += GetDisplacement(varying.vmesh); |
|||
#endif |
|||
|
|||
return VertTesselation(varying); |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 7a951f9236225024eb694af870ee4efe |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct AttributesMesh |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
#ifdef ATTRIBUTES_NEED_NORMAL |
|||
float3 normalOS : NORMAL; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TANGENT |
|||
float4 tangentOS : TANGENT; // Store sign in w |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD0 |
|||
float2 uv0 : TEXCOORD0; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD1 |
|||
float2 uv1 : TEXCOORD1; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD2 |
|||
float2 uv2 : TEXCOORD2; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_TEXCOORD3 |
|||
float2 uv3 : TEXCOORD3; |
|||
#endif |
|||
#ifdef ATTRIBUTES_NEED_COLOR |
|||
float4 color : COLOR; |
|||
#endif |
|||
|
|||
// UNITY_INSTANCE_ID |
|||
}; |
|||
|
|||
struct VaryingsMeshToPS |
|||
{ |
|||
float4 positionCS; |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
float3 positionWS; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
float3 tangentToWorld[3]; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
float4 color; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsMeshToPS |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
// if present, pack positionWS |
|||
float4 interpolators1 : TEXCOORD1; |
|||
float4 interpolators2 : TEXCOORD2; |
|||
float4 interpolators3 : TEXCOORD3; |
|||
#else |
|||
float3 interpolators1 : TEXCOORD1; |
|||
float3 interpolators2 : TEXCOORD2; |
|||
float3 interpolators3 : TEXCOORD3; |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
float3 interpolators0 : TEXCOORD0; |
|||
#endif |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
float4 interpolators4 : TEXCOORD4; |
|||
#elif defined(VARYINGS_NEED_TEXCOORD0) |
|||
float2 interpolators4 : TEXCOORD4; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
float4 interpolators5 : TEXCOORD5; |
|||
#elif defined(VARYINGS_NEED_TEXCOORD2) |
|||
float2 interpolators5 : TEXCOORD5; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_COLOR |
|||
float4 interpolators6 : TEXCOORD6; |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryingsMeshToPS PackVaryingsMeshToPS(VaryingsMeshToPS input) |
|||
{ |
|||
PackedVaryingsMeshToPS output; |
|||
|
|||
output.positionCS = input.positionCS; |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
output.interpolators1.xyz = input.tangentToWorld[0]; |
|||
output.interpolators2.xyz = input.tangentToWorld[1]; |
|||
output.interpolators3.xyz = input.tangentToWorld[2]; |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.interpolators1.w = input.positionWS.x; |
|||
output.interpolators2.w = input.positionWS.y; |
|||
output.interpolators3.w = input.positionWS.z; |
|||
#else |
|||
output.interpolators1.w = 0.0; |
|||
output.interpolators2.w = 0.0; |
|||
output.interpolators3.w = 0.0; |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.interpolators0 = input.positionWS; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.interpolators4.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.interpolators4.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.interpolators5.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.interpolators5.zw = input.texCoord3; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.interpolators6 = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input) |
|||
{ |
|||
FragInputs output = InitializeFragInputs(); |
|||
|
|||
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position |
|||
|
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
output.tangentToWorld[0] = input.interpolators1.xyz; |
|||
output.tangentToWorld[1] = input.interpolators2.xyz; |
|||
output.tangentToWorld[2] = input.interpolators3.xyz; |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w); |
|||
#endif |
|||
#else |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.positionWS.xyz = input.interpolators0.xyz; |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators5.xy; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators5.zw; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.color = input.interpolators6; |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT |
|||
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
// Varying DS - use for domain shader |
|||
// We can deduce these defines from the other defines |
|||
// We need to pass to DS any varying required by pixel shader |
|||
// If we have required an attributes that is not present in varyings it mean we will be for DS |
|||
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(ATTRIBUTES_NEED_NORMAL) |
|||
#define VARYINGS_DS_NEED_NORMAL |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(ATTRIBUTES_NEED_TANGENT) |
|||
#define VARYINGS_DS_NEED_TANGENT |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(ATTRIBUTES_NEED_TEXCOORD0) |
|||
#define VARYINGS_DS_NEED_TEXCOORD0 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(ATTRIBUTES_NEED_TEXCOORD1) |
|||
#define VARYINGS_DS_NEED_TEXCOORD1 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(ATTRIBUTES_NEED_TEXCOORD2) |
|||
#define VARYINGS_DS_NEED_TEXCOORD2 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(ATTRIBUTES_NEED_TEXCOORD3) |
|||
#define VARYINGS_DS_NEED_TEXCOORD3 |
|||
#endif |
|||
#if defined(VARYINGS_NEED_COLOR) || defined(ATTRIBUTES_NEED_COLOR) |
|||
#define VARYINGS_DS_NEED_COLOR |
|||
#endif |
|||
|
|||
// Varying for domain shader |
|||
// Position and normal are always present (for tessellation) and in world space |
|||
struct VaryingsMeshToDS |
|||
{ |
|||
float3 positionWS; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 normalWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
float4 tangentWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
float2 texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
float2 texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
float2 texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
float2 texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
float4 color; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsMeshToDS |
|||
{ |
|||
float3 interpolators0 : INTERNALTESSPOS; // positionWS |
|||
|
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 interpolators1 : NORMAL; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
float4 interpolators2 : TANGENT; |
|||
#endif |
|||
|
|||
// Allocate only necessary space if shader compiler in the future are able to automatically pack |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
float4 interpolators3 : TEXCOORD0; |
|||
#elif defined(VARYINGS_DS_NEED_TEXCOORD0) |
|||
float2 interpolators3 : TEXCOORD0; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
float4 interpolators4 : TEXCOORD1; |
|||
#elif defined(VARYINGS_DS_NEED_TEXCOORD2) |
|||
float2 interpolators4 : TEXCOORD1; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
float4 interpolators5 : TEXCOORD2; |
|||
#endif |
|||
}; |
|||
|
|||
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions |
|||
PackedVaryingsMeshToDS PackVaryingsMeshToDS(VaryingsMeshToDS input) |
|||
{ |
|||
PackedVaryingsMeshToDS output; |
|||
|
|||
output.interpolators0 = input.positionWS; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
output.interpolators1 = input.normalWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
output.interpolators2 = input.tangentWS; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
output.interpolators3.xy = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
output.interpolators3.zw = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
output.interpolators4.xy = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
output.interpolators4.zw = input.texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
output.interpolators5 = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsMeshToDS UnpackVaryingsMeshToDS(PackedVaryingsMeshToDS input) |
|||
{ |
|||
VaryingsMeshToDS output; |
|||
|
|||
output.positionWS = input.interpolators0; |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
output.normalWS = input.interpolators1; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
output.tangentWS = input.interpolators2; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.interpolators3.xy; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.interpolators3.zw; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.interpolators4.xy; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.interpolators4.zw; |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
output.color = input.interpolators5; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsMeshToDS InterpolateWithBaryCoordsMeshToDS(VaryingsMeshToDS input0, VaryingsMeshToDS input1, VaryingsMeshToDS input2, float3 baryCoords) |
|||
{ |
|||
VaryingsMeshToDS ouput; |
|||
|
|||
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords); |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
TESSELLATION_INTERPOLATE_BARY(normalWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TANGENT |
|||
// This will interpolate the sign but should be ok in practice as we may expect a triangle to have same sign (? TO CHECK) |
|||
TESSELLATION_INTERPOLATE_BARY(tangentWS, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord0, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord1, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord2, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
TESSELLATION_INTERPOLATE_BARY(texCoord3, baryCoords); |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_COLOR |
|||
TESSELLATION_INTERPOLATE_BARY(color, baryCoords); |
|||
#endif |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|
|||
fileFormatVersion: 2 |
|||
guid: ccef7a3da040ef845a907f77250d85b2 |
|||
timeCreated: 1484258505 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
struct VaryingsToPS |
|||
{ |
|||
VaryingsMeshToPS vmesh; |
|||
#ifdef VARYINGS_NEED_PASS |
|||
VaryingsPassToPS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsToPS |
|||
{ |
|||
PackedVaryingsMeshToPS vmesh; |
|||
#ifdef VARYINGS_NEED_PASS |
|||
PackedVaryingsPassToPS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input) |
|||
{ |
|||
PackedVaryingsToPS output; |
|||
output.vmesh = PackVaryingsMeshToPS(input.vmesh); |
|||
#ifdef VARYINGS_NEED_PASS |
|||
output.vpass = PackVaryingsPassToPS(input.vpass); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
|
|||
struct VaryingsToDS |
|||
{ |
|||
VaryingsMeshToDS vmesh; |
|||
#ifdef VARYINGS_NEED_PASS |
|||
VaryingsPassToDS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
struct PackedVaryingsToDS |
|||
{ |
|||
PackedVaryingsMeshToDS vmesh; |
|||
#ifdef VARYINGS_NEED_PASS |
|||
PackedVaryingsPassToDS vpass; |
|||
#endif |
|||
}; |
|||
|
|||
PackedVaryingsToDS PackVaryingsToDS(VaryingsToDS input) |
|||
{ |
|||
PackedVaryingsToDS output; |
|||
output.vmesh = PackVaryingsMeshToDS(input.vmesh); |
|||
#ifdef VARYINGS_NEED_PASS |
|||
output.vpass = PackVaryingsPassToDS(input.vpass); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsToDS UnpackVaryingsToDS(PackedVaryingsToDS input) |
|||
{ |
|||
VaryingsToDS output; |
|||
output.vmesh = UnpackVaryingsMeshToDS(input.vmesh); |
|||
#ifdef VARYINGS_NEED_PASS |
|||
output.vpass = UnpackVaryingsPassToDS(input.vpass); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS input1, VaryingsToDS input2, float3 baryCoords) |
|||
{ |
|||
VaryingsToDS output; |
|||
|
|||
output.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords); |
|||
#ifdef VARYINGS_NEED_PASS |
|||
output.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords); |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
#define VaryingsType VaryingsToDS |
|||
#define VaryingsMeshType VaryingsMeshToDS |
|||
#define PackedVaryingsType PackedVaryingsToDS |
|||
#define PackVaryingsType PackVaryingsToDS |
|||
#else |
|||
#define VaryingsType VaryingsToPS |
|||
#define VaryingsMeshType VaryingsMeshToPS |
|||
#define PackedVaryingsType PackedVaryingsToPS |
|||
#define PackVaryingsType PackVaryingsToPS |
|||
#endif |
|||
|
|||
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16) |
|||
VaryingsMeshType VertMesh(AttributesMesh input) |
|||
{ |
|||
VaryingsMeshType output; |
|||
|
|||
#if defined(TESSELLATION_ON) |
|||
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) |
|||
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_NORMAL) |
|||
output.normalWS = TransformObjectToWorldNormal(input.normalOS); |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_TANGENT) |
|||
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w); |
|||
#endif |
|||
#else |
|||
float3 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) |
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.positionWS = positionWS; |
|||
#endif |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
#ifdef VARYINGS_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 |
|||
#endif |
|||
|
|||
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(VARYINGS_DS_NEED_TEXCOORD0) |
|||
output.texCoord0 = input.uv0; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(VARYINGS_DS_NEED_TEXCOORD1) |
|||
output.texCoord1 = input.uv1; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(VARYINGS_DS_NEED_TEXCOORD2) |
|||
output.texCoord2 = input.uv2; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(VARYINGS_DS_NEED_TEXCOORD3) |
|||
output.texCoord3 = input.uv3; |
|||
#endif |
|||
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR) |
|||
output.color = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#ifdef TESSELLATION_ON |
|||
|
|||
VaryingsMeshToPS VertMeshTesselation(VaryingsMeshToDS input) |
|||
{ |
|||
VaryingsMeshToPS output; |
|||
|
|||
#ifdef VARYINGS_NEED_POSITION_WS |
|||
output.positionWS = input.positionWS; |
|||
#endif |
|||
output.positionCS = TransformWorldToHClip(input.positionWS); |
|||
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD |
|||
float3x3 tangentToWorld = CreateTangentToWorld(input.normalWS, input.tangentWS.xyz, input.tangentWS.w); |
|||
output.tangentToWorld[0] = tangentToWorld[0]; |
|||
output.tangentToWorld[1] = tangentToWorld[1]; |
|||
output.tangentToWorld[2] = tangentToWorld[2]; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_NEED_TEXCOORD0 |
|||
output.texCoord0 = input.texCoord0; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD1 |
|||
output.texCoord1 = input.texCoord1; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD2 |
|||
output.texCoord2 = input.texCoord2; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_TEXCOORD3 |
|||
output.texCoord3 = input.texCoord3; |
|||
#endif |
|||
#ifdef VARYINGS_NEED_COLOR |
|||
output.color = input.color; |
|||
#endif |
|||
|
|||
return output; |
|||
} |
|||
|
|||
#endif // TESSELLATION_ON |
|
|||
fileFormatVersion: 2 |
|||
guid: 5f7d62bf425b54942b9b212cad7efb1a |
|||
timeCreated: 1484313687 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 3d51fc2c60f333c44b613049001dfba8 |
|||
timeCreated: 1484352329 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
#define ATTRIBUTES_NEED_TEXCOORD1 |
|||
#define ATTRIBUTES_NEED_TEXCOORD2 |
|||
|
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
#define VARYINGS_NEED_TEXCOORD1 |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: 34b6e92ecac8a054085e28dc783b1a80 |
|||
timeCreated: 1484323639 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
#define ATTRIBUTES_NEED_TEXCOORD0 |
|||
|
|||
#define VARYINGS_NEED_TEXCOORD0 |
|||
|
|||
// This include will define the various Attributes/Varyings structure |
|||
#include "../../ShaderPass/VaryingMesh.hlsl" |
|
|||
#ifndef SHADERPASS |
|||
#error Undefine_SHADERPASS |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Attribute/Varying |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float2 uv0 : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionCS; |
|||
float2 texCoord0; |
|||
}; |
|||
|
|||
struct PackedVaryings |
|||
{ |
|||
float4 positionCS : SV_Position; |
|||
float4 interpolators[1] : TEXCOORD0; |
|||
}; |
|||
|
|||
PackedVaryings PackVaryings(Varyings input) |
|||
{ |
|||
PackedVaryings output; |
|||
output.positionCS = input.positionCS; |
|||
output.interpolators[0] = float4(input.texCoord0.xy, 0.0, 0.0); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
FragInputs UnpackVaryings(PackedVaryings input) |
|||
{ |
|||
FragInputs output; |
|||
ZERO_INITIALIZE(FragInputs, output); |
|||
|
|||
output.unPositionSS = input.positionCS; |
|||
output.texCoord0.xy = input.interpolators[0].xy; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Vertex shader |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
PackedVaryings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
|
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionCS = TransformWorldToHClip(positionWS); |
|||
|
|||
output.texCoord0 = input.uv0; |
|||
|
|||
return PackVaryings(output); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d56e29698894b440905cc5d63814ef9 |
|||
timeCreated: 1479292899 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9582236b174d65b4391e0f9890fd2194 |
|||
folderAsset: yes |
|||
timeCreated: 1483692743 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue