浏览代码

Merge pull request #109 from Unity-Technologies/Add-object-scale-for-tessellation

Add object scale for tessellation
/main
GitHub 8 年前
当前提交
297cb6ad
共有 7 个文件被更改,包括 46 次插入12 次删除
  1. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  2. 16
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  3. 11
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  4. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  5. 19
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  6. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl
  7. 1
      Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELLATION_PHONG
#pragma shader_feature _ _TESSELLATION_DISPLACEMENT _TESSELLATION_DISPLACEMENT_PHONG
#pragma shader_feature _TESSELLATION_OBJECT_SCALE
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _LAYER_MAPPING_TRIPLANAR_0

16
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


public static GUIContent tessellationFactorTriangleSizeText = new GUIContent("Triangle size", "Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)");
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
//public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Scale displacement taking into account the object scale");
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Tesselation displacement will take into account the object scale - Only work with uniform positive scale");
}
public enum SurfaceType

if ((DoubleSidedMode)doubleSidedMode.floatValue == DoubleSidedMode.None)
{
m_MaterialEditor.ShaderProperty(tessellationBackFaceCullEpsilon, Styles.tessellationBackFaceCullEpsilonText);
}
// TODO: Implement
// m_MaterialEditor.ShaderProperty(tessellationObjectScale, Styles.tessellationObjectScaleText);
}
m_MaterialEditor.ShaderProperty(tessellationObjectScale, Styles.tessellationObjectScaleText);
EditorGUI.indentLevel--;
}
}

tessellationFactorTriangleSize = FindProperty(kTessellationFactorTriangleSize, props, false);
tessellationShapeFactor = FindProperty(kTessellationShapeFactor, props, false);
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false);
//tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
}
protected void SetupCommonOptionsKeywords(Material material)

material.DisableKeyword("_TESSELLATION_DISPLACEMENT");
material.EnableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
}
bool tessellationObjectScaleEnable = material.GetFloat(kTessellationObjectScale) == 1.0;
SetKeyword(material, "_TESSELLATION_OBJECT_SCALE", tessellationObjectScaleEnable);
}
}

const string kTessellationShapeFactor = "_TessellationShapeFactor";
MaterialProperty tessellationBackFaceCullEpsilon = null;
const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon";
//MaterialProperty tessellationObjectScale = null;
//const string kTessellationObjectScale = "_TessellationObjectScale";
MaterialProperty tessellationObjectScale = null;
const string kTessellationObjectScale = "_TessellationObjectScale";
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode };

11
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl


float height = 0.0;
#endif
float3 displ = float3(0.0, 0.0, 0.0);
return height * input.normalWS;
#else
return float3(0.0, 0.0, 0.0);
displ = height * input.normalWS;
#endif
// Applying scaling of the object if requested
#ifdef _TESSELLATION_OBJECT_SCALE
displ *= input.objectScale;
return displ;
}

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader


#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELLATION_PHONG
#pragma shader_feature _ _TESSELLATION_DISPLACEMENT _TESSELLATION_DISPLACEMENT_PHONG
#pragma shader_feature _TESSELLATION_OBJECT_SCALE
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _MAPPING_TRIPLANAR

19
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl


#ifdef VARYINGS_DS_NEED_COLOR
float4 color;
#endif
#ifdef _TESSELLATION_OBJECT_SCALE
float3 objectScale;
#endif
};
struct PackedVaryingsMeshToDS

#ifdef VARYINGS_DS_NEED_COLOR
float4 interpolators5 : TEXCOORD2;
#endif
#ifdef _TESSELLATION_OBJECT_SCALE
float3 interpolators6 : TEXCOORD3;
#endif
};
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions

#endif
#ifdef VARYINGS_DS_NEED_COLOR
output.interpolators5 = input.color;
#endif
#ifdef _TESSELLATION_OBJECT_SCALE
output.interpolators6 = input.objectScale;
#endif
return output;

#ifdef VARYINGS_DS_NEED_COLOR
output.color = input.interpolators5;
#endif
#ifdef _TESSELLATION_OBJECT_SCALE
output.objectScale = input.interpolators6;
#endif
return output;
}

#endif
#ifdef VARYINGS_DS_NEED_COLOR
TESSELLATION_INTERPOLATE_BARY(color, baryCoords);
#endif
#ifdef _TESSELLATION_OBJECT_SCALE
// objectScale doesn't change for the whole object.
ouput.objectScale = input0.objectScale;
#endif
return ouput;

9
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl


{
VaryingsMeshType output;
#if defined(TESSELLATION_ON)
#ifdef TESSELLATION_ON
#ifdef _TESSELLATION_OBJECT_SCALE
// Extract scaling from world transform
float4x4 worldTransform = GetObjectToWorldMatrix();
output.objectScale.x = length(float3(worldTransform._m00, worldTransform._m01, worldTransform._m02));
output.objectScale.y = length(float3(worldTransform._m10, worldTransform._m11, worldTransform._m12));
output.objectScale.z = length(float3(worldTransform._m20, worldTransform._m21, worldTransform._m22));
#endif
// 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);

1
Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute


#include "TiledLightingTemplate.hlsl"
#include "TiledReflectionTemplate.hlsl"
UNITY_DECLARE_TEX2D_FLOAT(_CameraDepthTexture);
Texture2D _CameraGBufferTexture0;
Texture2D _CameraGBufferTexture1;
Texture2D _CameraGBufferTexture2;

正在加载...
取消
保存