浏览代码
Merge branch 'master' into Branch_fix-ps4-hdrenderloop
Merge branch 'master' into Branch_fix-ps4-hdrenderloop
# Conflicts: # Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader # Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader # Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader # Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader/main
Julien Ignace
8 年前
当前提交
c83f3d4a
共有 83 个文件被更改,包括 3277 次插入 和 1572 次删除
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta
-
83Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
-
14Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl
-
48Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
14Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
59Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
154Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
-
39Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
-
46Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
-
91Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
31Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
-
89Assets/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
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl
-
166Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.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
-
6Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
-
6Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
-
67Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl
-
9Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
14Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
1Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
-
139Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
-
195Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
-
2Assets/ScriptableRenderLoop/common/TextureCache.cs
-
2README.md
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
-
107Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta
-
86Assets/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
-
49Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute.meta
-
134Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs.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
-
41Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
-
61Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl.meta
-
0/Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl.meta
-
0/Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
-
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" |
|
|||
#define TESSELATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z |
|||
#define TESSELLATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z |
|||
// ---- utility functions |
|||
float UnityCalcDistanceTessFactor(float3 positionOS, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS) |
|||
// TODO: Move in geomtry.hlsl |
|||
float3 ProjectPointOnPlane(float3 position, float3 planePosition, float3 planeNormal) |
|||
float3 positionWS = mul(objectToWorld, float4(positionOS, 1.0)).xyz; |
|||
float dist = distance(positionWS, cameraPosWS); |
|||
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess; |
|||
return f; |
|||
return position - (dot(position - planePosition, planeNormal) * planeNormal); |
|||
float4 UnityCalcTriEdgeTessFactors(float3 triVertexFactors) |
|||
// p0, p1, p2 triangle world position |
|||
// p0, p1, p2 triangle world vertex normal |
|||
float3 PhongTessellation(float3 positionWS, float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2, float3 baryCoords, float shape) |
|||
float4 tess; |
|||
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z); |
|||
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z); |
|||
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y); |
|||
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f; |
|||
return tess; |
|||
float3 c0 = ProjectPointOnPlane(positionWS, p0, n0); |
|||
float3 c1 = ProjectPointOnPlane(positionWS, p1, n1); |
|||
float3 c2 = ProjectPointOnPlane(positionWS, p2, n2); |
|||
|
|||
float3 phongPositionWS = baryCoords.x * c0 + baryCoords.y * c1 + baryCoords.z * c2; |
|||
|
|||
return lerp(positionWS, phongPositionWS, shape); |
|||
/* |
|||
float UnityCalcEdgeTessFactor(float3 wpos0, float3 wpos1, float edgeLen) |
|||
// Reference: http://twvideo01.ubm-us.net/o1/vault/gdc10/slides/Bilodeau_Bill_Direct3D11TutorialTessellation.pdf |
|||
|
|||
// Return true if the triangle must be culled |
|||
// backFaceCullEpsilon is the threshold of the dot product between view and normal ( < 0 mean we cull) |
|||
bool BackFaceCullTriangle(float3 p0, float3 p1, float3 p2, float backFaceCullEpsilon, float3 cameraPosWS) |
|||
// distance to edge center |
|||
float dist = distance(0.5 * (wpos0 + wpos1), _WorldSpaceCameraPos); |
|||
// length of the edge |
|||
float len = distance(wpos0, wpos1); |
|||
// edgeLen is approximate desired size in pixels |
|||
float f = max(len * _ScreenParams.y / (edgeLen * dist), 1.0); |
|||
return f; |
|||
float3 edge0 = p1 - p0; |
|||
float3 edge2 = p2 - p0; |
|||
|
|||
float3 N = normalize(cross(edge0, edge2)); |
|||
float3 midpoint = (p0 + p1 + p2) / 3.0; |
|||
float3 V = normalize(cameraPosWS - midpoint); |
|||
|
|||
return (dot(V, N) < backFaceCullEpsilon) ? true : false; |
|||
float UnityDistanceFromPlane(float3 pos, float4 plane) |
|||
float2 GetScreenSpacePosition(float3 positionWS, float4x4 viewProjectionMatrix, float4 screenParams) |
|||
float d = dot(float4(pos, 1.0f), plane); |
|||
return d; |
|||
float4 positionCS = mul(viewProjectionMatrix, float4(positionWS, 1.0)); |
|||
float2 positionSS = positionCS.xy / positionCS.w; |
|||
|
|||
// TODO: Check if we need to invert y |
|||
return (positionSS * 0.5 + 0.5) * float2(screenParams.x, -screenParams.y); |
|||
} |
|||
|
|||
// Compute both screen and distance based adaptation - return factor between 0 and 1 |
|||
float3 GetScreenSpaceTessFactor(float3 p0, float3 p1, float3 p2, float4x4 viewProjectionMatrix, float4 screenParams, float triangleSize) |
|||
{ |
|||
// Get screen space adaptive scale factor |
|||
float2 edgeScreenPosition0 = GetScreenSpacePosition(p0, viewProjectionMatrix, screenParams); |
|||
float2 edgeScreenPosition1 = GetScreenSpacePosition(p1, viewProjectionMatrix, screenParams); |
|||
float2 edgeScreenPosition2 = GetScreenSpacePosition(p2, viewProjectionMatrix, screenParams); |
|||
|
|||
float EdgeScale = 1.0 / triangleSize; // Edge size in reality, but name is simpler |
|||
float3 tessFactor; |
|||
tessFactor.x = saturate(distance(edgeScreenPosition1, edgeScreenPosition2) * EdgeScale); |
|||
tessFactor.y = saturate(distance(edgeScreenPosition0, edgeScreenPosition2) * EdgeScale); |
|||
tessFactor.z = saturate(distance(edgeScreenPosition0, edgeScreenPosition1) * EdgeScale); |
|||
|
|||
return tessFactor; |
|||
// Returns true if triangle with given 3 world positions is outside of camera's view frustum. |
|||
// cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement) |
|||
bool UnityWorldViewFrustumCull(float3 wpos0, float3 wpos1, float3 wpos2, float cullEps) |
|||
float3 GetDistanceBasedTessFactor(float3 p0, float3 p1, float3 p2, float3 cameraPosWS, float tessMinDist, float tessMaxDist) |
|||
float4 planeTest; |
|||
float3 edgePosition0 = 0.5 * (p1 + p2); |
|||
float3 edgePosition1 = 0.5 * (p0 + p2); |
|||
float3 edgePosition2 = 0.5 * (p0 + p1); |
|||
// left |
|||
planeTest.x = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f); |
|||
// right |
|||
planeTest.y = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f); |
|||
// top |
|||
planeTest.z = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f); |
|||
// bottom |
|||
planeTest.w = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f); |
|||
// TODO: Move to camera relative and change distance to length |
|||
float dist0 = distance(edgePosition0, cameraPosWS); |
|||
float dist1 = distance(edgePosition1, cameraPosWS); |
|||
float dist2 = distance(edgePosition2, cameraPosWS); |
|||
|
|||
// The saturate will handle the produced NaN in case min == max |
|||
float fadeDist = tessMaxDist - tessMinDist; |
|||
float3 tessFactor; |
|||
tessFactor.x = saturate(1.0 - (dist0 - tessMinDist) / fadeDist); |
|||
tessFactor.y = saturate(1.0 - (dist1 - tessMinDist) / fadeDist); |
|||
tessFactor.z = saturate(1.0 - (dist2 - tessMinDist) / fadeDist); |
|||
// has to pass all 4 plane tests to be visible |
|||
return !all(planeTest); |
|||
return tessFactor; |
|||
*/ |
|||
// ---- functions that compute tessellation factors |
|||
// Distance based tessellation: |
|||
// Tessellation level is "tess" before "minDist" from camera, and linearly decreases to 1 |
|||
// up to "maxDist" from camera. |
|||
float4 UnityDistanceBasedTess(float3 positionOS0, float3 positionOS1, float3 positionOS2, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS) |
|||
float4 CalcTriEdgeTessFactors(float3 triVertexFactors) |
|||
float3 f; |
|||
f.x = UnityCalcDistanceTessFactor(positionOS0, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|||
f.y = UnityCalcDistanceTessFactor(positionOS1, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|||
f.z = UnityCalcDistanceTessFactor(positionOS2, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|||
return UnityCalcTriEdgeTessFactors(f); |
|||
float4 tess; |
|||
tess.x = triVertexFactors.x; |
|||
tess.y = triVertexFactors.y; |
|||
tess.z = triVertexFactors.z; |
|||
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0; |
|||
|
|||
return tess; |
|||
/* |
|||
// Desired edge length based tessellation: |
|||
// Approximate resulting edge length in pixels is "edgeLength". |
|||
// Does not take viewing FOV into account, just flat out divides factor by distance. |
|||
float4 UnityEdgeLengthBasedTess(float4 v0, float4 v1, float4 v2, float edgeLength) |
|||
// TODO: Move in geomtry.hlsl |
|||
float DistanceFromPlane(float3 pos, float4 plane) |
|||
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz; |
|||
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz; |
|||
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz; |
|||
float4 tess; |
|||
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength); |
|||
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength); |
|||
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength); |
|||
tess.w = (tess.x + tess.y + tess.z) / 3.0f; |
|||
return tess; |
|||
float d = dot(float4(pos, 1.0f), plane); |
|||
return d; |
|||
// Same as UnityEdgeLengthBasedTess, but also does patch frustum culling: |
|||
// patches outside of camera's view are culled before GPU tessellation. Saves some wasted work. |
|||
float4 UnityEdgeLengthBasedTessCull(float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement) |
|||
// Returns true if triangle with given 3 world positions is outside of camera's view frustum. |
|||
// cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement) |
|||
bool WorldViewFrustumCull(float3 p0, float3 p1, float3 p2, float cullEps, float4 cameraWorldClipPlanes[4]) |
|||
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz; |
|||
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz; |
|||
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz; |
|||
float4 tess; |
|||
if (UnityWorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement)) |
|||
{ |
|||
tess = 0.0f; |
|||
} |
|||
else |
|||
{ |
|||
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength); |
|||
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength); |
|||
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength); |
|||
tess.w = (tess.x + tess.y + tess.z) / 3.0f; |
|||
} |
|||
return tess; |
|||
float4 planeTest; |
|||
|
|||
// left |
|||
planeTest.x = ((DistanceFromPlane(p0, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p1, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p2, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f); |
|||
// right |
|||
planeTest.y = ((DistanceFromPlane(p0, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p1, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p2, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f); |
|||
// top |
|||
planeTest.z = ((DistanceFromPlane(p0, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p1, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p2, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f); |
|||
// bottom |
|||
planeTest.w = ((DistanceFromPlane(p0, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p1, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((DistanceFromPlane(p2, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f); |
|||
|
|||
// has to pass all 4 plane tests to be visible |
|||
return !all(planeTest); |
|||
*/ |
|
|||
float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2) |
|||
{ |
|||
float maxDisplacement = ADD_ZERO_IDX(_HeightAmplitude); |
|||
#ifdef _LAYER_COUNT |
|||
maxDisplacement = max(maxDisplacement, _HeightAmplitude1); |
|||
#if _LAYER_COUNT >= 3 |
|||
maxDisplacement = max(maxDisplacement, _HeightAmplitude2); |
|||
#endif |
|||
#if _LAYER_COUNT >= 4 |
|||
maxDisplacement = max(maxDisplacement, _HeightAmplitude3); |
|||
#endif |
|||
#endif |
|||
|
|||
bool frustumCulled = WorldViewFrustumCull(p0, p1, p2, maxDisplacement, (float4[4])unity_CameraWorldClipPlanes); |
|||
|
|||
bool faceCull = false; |
|||
#if !(defined(_DOUBLESIDED) || defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)) |
|||
// TODO: Handle inverse culling (for mirror)! |
|||
if (_TessellationBackFaceCullEpsilon > -0.99) // Is backface culling enabled ? |
|||
{ |
|||
faceCull = BackFaceCullTriangle(p0, p1, p2, _TessellationBackFaceCullEpsilon, _WorldSpaceCameraPos); |
|||
} |
|||
#endif |
|||
|
|||
if (frustumCulled || faceCull) |
|||
{ |
|||
// Settings factor to 0 will kill the triangle |
|||
return float4(0.0, 0.0, 0.0, 0.0); |
|||
} |
|||
|
|||
float3 tessFactor = float3(1.0, 1.0, 1.0); |
|||
|
|||
// Aaptive screen space tessellation |
|||
if (_TessellationFactorTriangleSize > 0.0) |
|||
{ |
|||
// return a value between 0 and 1 |
|||
tessFactor *= GetScreenSpaceTessFactor( p0, p1, p2, GetWorldToHClipMatrix(), _ScreenParams, _TessellationFactorTriangleSize); |
|||
} |
|||
|
|||
// Distance based tessellation |
|||
if (_TessellationFactorMaxDistance > 0.0) |
|||
{ |
|||
tessFactor *= GetDistanceBasedTessFactor(p0, p1, p2, _WorldSpaceCameraPos, _TessellationFactorMinDistance, _TessellationFactorMaxDistance); |
|||
} |
|||
|
|||
tessFactor *= _TessellationFactor; |
|||
|
|||
// TessFactor below 1.0 have no effect. At 0 it kill the triangle, so clamp it to 1.0 |
|||
tessFactor.xyz = float3(max(1.0, tessFactor.x), max(1.0, tessFactor.y), max(1.0, tessFactor.z)); |
|||
|
|||
return CalcTriEdgeTessFactors(tessFactor); |
|||
} |
|||
|
|||
float3 GetDisplacement(VaryingsMeshToDS input) |
|||
{ |
|||
// This call will work for both LayeredLit and Lit shader |
|||
LayerTexCoord layerTexCoord; |
|||
GetLayerTexCoord( |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD0 |
|||
input.texCoord0, |
|||
#else |
|||
float2(0.0, 0.0), |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD1 |
|||
input.texCoord1, |
|||
#else |
|||
float2(0.0, 0.0), |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD2 |
|||
input.texCoord2, |
|||
#else |
|||
float2(0.0, 0.0), |
|||
#endif |
|||
#ifdef VARYINGS_DS_NEED_TEXCOORD3 |
|||
input.texCoord3, |
|||
#else |
|||
float2(0.0, 0.0), |
|||
#endif |
|||
input.positionWS, |
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
input.normalWS, |
|||
#else |
|||
float3(0.0, 0.0, 1.0), |
|||
#endif |
|||
layerTexCoord); |
|||
|
|||
// TODO: For now just use Layer0, but we are suppose to apply the same heightmap blending than in the pixel shader |
|||
#ifdef _HEIGHTMAP |
|||
// TODO test mip lod to reduce texture cache miss |
|||
// TODO: Move to camera relative and change distance to length |
|||
//float dist = distance(input.positionWS, cameraPosWS); |
|||
// No ddx/ddy to calculate LOD, use camera distance instead |
|||
//float fadeDist = _TessellationFactorMaxDistance - _TessellationFactorMinDistance; |
|||
//float heightMapLod = saturate((dist - _TessellationFactorMinDistance) / min(fadeDist, 0.01)) * 6; // 6 is an arbitrary number here |
|||
float heightMapLod = 0.0; |
|||
|
|||
float height = (SAMPLE_LAYER_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_ZERO_IDX(layerTexCoord.base), heightMapLod).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_ZERO_IDX(_HeightAmplitude); |
|||
#else |
|||
float height = 0.0; |
|||
#endif |
|||
|
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
return height * input.normalWS; |
|||
#else |
|||
return float3(0.0, 0.0, 0.0); |
|||
#endif |
|||
} |
|
|||
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]); |
|||
|
|||
float3 p0 = varying0.vmesh.positionWS; |
|||
float3 p1 = varying1.vmesh.positionWS; |
|||
float3 p2 = varying2.vmesh.positionWS; |
|||
|
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 n0 = varying0.vmesh.normalWS; |
|||
float3 n1 = varying1.vmesh.normalWS; |
|||
float3 n2 = varying2.vmesh.normalWS; |
|||
#else |
|||
float3 n0 = float3(0.0, 0.0, 0.0); |
|||
float3 n1 = float3(0.0, 0.0, 0.0); |
|||
float3 n2 = float3(0.0, 0.0, 0.0); |
|||
#endif |
|||
|
|||
float4 tf = TessellationEdge(p0, p1, p2, n0, n1, n2); |
|||
TessellationFactors output; |
|||
output.edge[0] = tf.x; |
|||
output.edge[1] = tf.y; |
|||
output.edge[2] = tf.z; |
|||
output.inside = tf.w; |
|||
|
|||
return output; |
|||
} |
|||
|
|||
[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 |
|||
|
|||
float3 p0 = varying0.vmesh.positionWS; |
|||
float3 p1 = varying1.vmesh.positionWS; |
|||
float3 p2 = varying2.vmesh.positionWS; |
|||
|
|||
#ifdef VARYINGS_DS_NEED_NORMAL |
|||
float3 n0 = varying0.vmesh.normalWS; |
|||
float3 n1 = varying1.vmesh.normalWS; |
|||
float3 n2 = varying2.vmesh.normalWS; |
|||
#else |
|||
float3 n0 = float3(0.0, 0.0, 0.0); |
|||
float3 n1 = float3(0.0, 0.0, 0.0); |
|||
float3 n2 = float3(0.0, 0.0, 0.0); |
|||
#endif |
|||
|
|||
varying.vmesh.positionWS = PhongTessellation( varying.vmesh.positionWS, |
|||
p0, p1, p2, n0, n1, n2, |
|||
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: |
|
|||
// Precomputes data for IntegrateLD(). See that function for a detailed description. |
|||
|
|||
#include "Common.hlsl" |
|||
#include "ImageBasedLighting.hlsl" |
|||
|
|||
#define MAX_IBL_SAMPLE_CNT 89 |
|||
|
|||
RWTexture2D<float4> output; // [MAX_SAMPLE_CNT x UNITY_SPECCUBE_LOD_STEPS] |
|||
|
|||
#pragma kernel ComputeGgxIblSampleData |
|||
|
|||
[numthreads(MAX_IBL_SAMPLE_CNT, UNITY_SPECCUBE_LOD_STEPS, 1)] |
|||
void ComputeGgxIblSampleData(uint3 groupThreadId : SV_GroupThreadID) |
|||
{ |
|||
uint sampleIndex = groupThreadId.x; |
|||
uint mipLevel = groupThreadId.y + 1; |
|||
uint sampleCount = GetIBLRuntimeFilterSampleCount(mipLevel); |
|||
|
|||
if (sampleIndex >= sampleCount) |
|||
{ |
|||
output[groupThreadId.xy] = float4(0, 0, 0, 0); |
|||
return; |
|||
} |
|||
|
|||
float perceptualRoughness = MipmapLevelToPerceptualRoughness(mipLevel); |
|||
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness); |
|||
|
|||
float bias = 0.5 * roughness; |
|||
|
|||
float2 u = Fibonacci2d(sampleIndex, sampleCount); |
|||
u.x = lerp(u.x, 0, bias); |
|||
|
|||
float3 localL; |
|||
float NdotL, NdotH, VdotH; |
|||
|
|||
SampleGGXDir(u, float3(0, 0, 1), k_identity3x3, roughness, localL, NdotL, NdotH, VdotH, true); |
|||
|
|||
if (NdotL <= 0) |
|||
{ |
|||
// We are not supposed to generate wasteful samples. |
|||
output[groupThreadId.xy] = float4(0, 0, 0, 0); |
|||
return; |
|||
} |
|||
|
|||
float pdf = D_GGX(NdotH, roughness) * 0.25; |
|||
float omegaS = rcp(sampleCount * pdf); |
|||
|
|||
output[groupThreadId.xy] = float4(localL, omegaS); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 764a24bb47ef5ba4781d9ae82ca07445 |
|||
timeCreated: 1484572881 |
|||
licenseType: Pro |
|||
ComputeShaderImporter: |
|||
currentAPIMask: 4 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class IBLFilterGGX |
|||
{ |
|||
RenderTexture m_GgxIblSampleData = null; |
|||
const int k_GgxIblMaxSampleCount = 89; // Width
|
|||
const int k_GgxIblMipCountMinusOne = 6; // Height (UNITY_SPECCUBE_LOD_STEPS)
|
|||
|
|||
ComputeShader m_ComputeGgxIblSampleDataCS = null; |
|||
int m_ComputeIblGgxSampleDataKernel = -1; |
|||
|
|||
ComputeShader m_BuildProbabilityTablesCS = null; |
|||
int m_ConditionalDensitiesKernel = -1; |
|||
int m_MarginalRowDensitiesKernel = -1; |
|||
|
|||
Material m_GgxConvolveMaterial = null; // Convolves a cubemap with GGX
|
|||
|
|||
public bool IsInitialized() |
|||
{ |
|||
return m_GgxIblSampleData != null; |
|||
} |
|||
|
|||
public void Initialize(ScriptableRenderContext context) |
|||
{ |
|||
if (!m_ComputeGgxIblSampleDataCS) |
|||
{ |
|||
m_ComputeGgxIblSampleDataCS = Resources.Load<ComputeShader>("ComputeGgxIblSampleData"); |
|||
m_ComputeIblGgxSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData"); |
|||
} |
|||
|
|||
if (!m_BuildProbabilityTablesCS) |
|||
{ |
|||
m_BuildProbabilityTablesCS = Resources.Load<ComputeShader>("BuildProbabilityTables"); |
|||
m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities"); |
|||
m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities"); |
|||
} |
|||
|
|||
if (!m_GgxConvolveMaterial) |
|||
{ |
|||
m_GgxConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/GGXConvolve"); |
|||
} |
|||
|
|||
if (!m_GgxIblSampleData) |
|||
{ |
|||
m_GgxIblSampleData = new RenderTexture(k_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 1, RenderTextureFormat.ARGBFloat); |
|||
m_GgxIblSampleData.dimension = TextureDimension.Tex2D; |
|||
m_GgxIblSampleData.useMipMap = false; |
|||
m_GgxIblSampleData.autoGenerateMips = false; |
|||
m_GgxIblSampleData.enableRandomWrite = true; |
|||
m_GgxIblSampleData.filterMode = FilterMode.Point; |
|||
m_GgxIblSampleData.Create(); |
|||
|
|||
m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeIblGgxSampleDataKernel, "output", m_GgxIblSampleData); |
|||
|
|||
var cmd = new CommandBuffer() { name = "Compute GGX IBL Sample Data" }; |
|||
cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeIblGgxSampleDataKernel, 1, 1, 1); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
|
|||
void FilterCubemapGgxCommon(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
// Solid angle associated with a texel of the cubemap.
|
|||
float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI); |
|||
|
|||
m_GgxConvolveMaterial.SetTexture("_MainTex", source); |
|||
m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); |
|||
m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1); |
|||
m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); |
|||
|
|||
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) |
|||
{ |
|||
MaterialPropertyBlock props = new MaterialPropertyBlock(); |
|||
props.SetFloat("_Level", mip); |
|||
|
|||
for (int face = 0; face < 6; ++face) |
|||
{ |
|||
Utilities.SetRenderTarget(context, target, ClearFlag.ClearNone, mip, (CubemapFace)face); |
|||
|
|||
var cmd = new CommandBuffer { name = "" }; |
|||
cmd.DrawMesh(cubemapFaceMesh[face], Matrix4x4.identity, m_GgxConvolveMaterial, 0, 0, props); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Filters MIP map levels (other than 0) with GGX using BRDF importance sampling.
|
|||
public void FilterCubemapGgx(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
m_GgxConvolveMaterial.DisableKeyword("USE_MIS"); |
|||
|
|||
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh); |
|||
} |
|||
|
|||
// Filters MIP map levels (other than 0) with GGX using multiple importance sampling.
|
|||
public void FilterCubemapGgxMis(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
RenderTexture conditionalCdf, RenderTexture marginalRowCdf, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
// Bind the input cubemap.
|
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "envMap", source); |
|||
|
|||
// Bind the outputs.
|
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "conditionalDensities", conditionalCdf); |
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "marginalRowDensities", marginalRowCdf); |
|||
m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", marginalRowCdf); |
|||
|
|||
int numRows = conditionalCdf.height; |
|||
|
|||
var cmd = new CommandBuffer() { name = "Build Probability Tables" }; |
|||
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, numRows, 1, 1); |
|||
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
|
|||
m_GgxConvolveMaterial.EnableKeyword("USE_MIS"); |
|||
m_GgxConvolveMaterial.SetTexture("_ConditionalDensities", conditionalCdf); |
|||
m_GgxConvolveMaterial.SetTexture("_MarginalRowDensities", marginalRowCdf); |
|||
|
|||
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 827056f7b26e8a64883735043af76431 |
|||
timeCreated: 1484572874 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
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" |
|
|||
/* |
|||
float _Tess; |
|||
float _TessNear; |
|||
float _TessFar; |
|||
float _UseDisplacementfalloff; |
|||
float _DisplacementfalloffNear; |
|||
float _DisplacementfalloffFar; |
|||
*/ |
|||
|
|||
float4 TesselationEdge(Attributes input0, Attributes input1, Attributes input2) |
|||
{ |
|||
// float minDist = 0; // _TessNear; |
|||
// float maxDist = 15; // _TessFar; |
|||
|
|||
// return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos); |
|||
|
|||
return float4(_TesselationFactor, _TesselationFactor, _TesselationFactor, _TesselationFactor); |
|||
} |
|||
|
|||
void Displacement(inout Attributes v) |
|||
{ |
|||
/* |
|||
float LengthLerp = length(ObjSpaceViewDir(v.vertex)); |
|||
LengthLerp -= _DisplacementfalloffNear; |
|||
LengthLerp /= _DisplacementfalloffFar - _DisplacementfalloffNear; |
|||
LengthLerp = 1 - (saturate(LengthLerp)); |
|||
|
|||
float d = ((tex2Dlod(_DispTex, float4(v.texcoord.xy * _Tiling, 0, 0)).r) - _DisplacementCenter) * (_Displacement * LengthLerp); |
|||
d /= max(0.0001, _Tiling); |
|||
*/ |
|||
|
|||
#ifdef _HEIGHTMAP |
|||
float height = (SAMPLE_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), v.uv0, 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude); |
|||
#else |
|||
float height = 0.0; |
|||
#endif |
|||
|
|||
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION) |
|||
v.positionOS.xyz += height * v.normalOS; |
|||
#endif |
|||
} |
|
|||
#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