浏览代码

Circular based rendering added

/Shaders2019
Arturo Nereu 5 年前
当前提交
4266497a
共有 8 个文件被更改,包括 524 次插入7 次删除
  1. 147
      Assets/Shaders/Scenes/Shaders Test Bed.unity
  2. 64
      Assets/Shaders/Scripts/BarycentricDataBuilder.cs
  3. 97
      Assets/Common/Materials/PositionBased.mat
  4. 8
      Assets/Common/Materials/PositionBased.mat.meta
  5. 24
      Assets/Shaders/Scripts/ContactPosition.cs
  6. 11
      Assets/Shaders/Scripts/ContactPosition.cs.meta
  7. 170
      Assets/Shaders/Shader Graphs/PositionBasedRendering.shadergraph
  8. 10
      Assets/Shaders/Shader Graphs/PositionBasedRendering.shadergraph.meta

147
Assets/Shaders/Scenes/Shaders Test Bed.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &738691673
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 738691675}
- component: {fileID: 738691674}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &738691674
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738691673}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3856305635085454e8af9cbef1878b3b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_TargetObject: {fileID: 1776377517}
--- !u!4 &738691675
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 738691673}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.78, y: 0, z: 0.84}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &776631972
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 919132149155446097, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_Name
value: TestARMesh
value: TestARMesh_Wireframe
value: 1
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0ebc67c00f2ddb143a9839247caf9ab6, type: 3}

m_Script: {fileID: 11500000, guid: 728e3adc9244c8348a969a6545a32bda, type: 3}
m_Name:
m_EditorClassIdentifier:
m_VertexDistance: 2
--- !u!1001 &1776377516
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalPosition.x
value: 0.91
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalPosition.z
value: -0.19
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalRotation.y
value: 0.91927123
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.39362466
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_RootOrder
value: 3
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 133.64
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -7511558181221131132, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 9c50a26f8f4822547a53c52638848bd3, type: 2}
- target: {fileID: 919132149155446097, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_Name
value: TestARMesh_Wireframe (1)
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 0ebc67c00f2ddb143a9839247caf9ab6, type: 3}
--- !u!1 &1776377517 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 0ebc67c00f2ddb143a9839247caf9ab6,
type: 3}
m_PrefabInstance: {fileID: 1776377516}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1776377521
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1776377517}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 728e3adc9244c8348a969a6545a32bda, type: 3}
m_Name:
m_EditorClassIdentifier:
m_VertexDistance: 0.2

64
Assets/Shaders/Scripts/BarycentricDataBuilder.cs


// Based on: https://catlikecoding.com/unity/tutorials/advanced-rendering/flat-and-wireframe-shading/
using System.Collections.Generic;
//void Start()
//{
// GenerateBarycentricData();
//}
void Start()
{
//GenerateBarycentricData();
GenerateUVData();
}
private void Reset()
{

SplitMesh(mesh);
SetVertexColors(mesh);
}
void GenerateUVData()
{
Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
GenerateUVs(mesh);
}
public void GenerateData(Mesh mesh)

mesh.normals = newNormals;
mesh.uv = newUvs;
mesh.triangles = triangles;
}
static List<Vector3> s_Vertices = new List<Vector3>();
static List<Vector3> s_UVs = new List<Vector3>();
[SerializeField]
private float m_VertexDistance;
public void GenerateUVs(Mesh mesh)
{
int vertexCount = mesh.vertexCount;
s_UVs.Clear();
if (s_UVs.Capacity < vertexCount) { s_UVs.Capacity = vertexCount; }
mesh.GetVertices(s_Vertices);
Vector3 centerInPlaneSpace = s_Vertices[s_Vertices.Count - 1];
Vector3 uv = new Vector3(0, 0, 0);
float shortestUVMapping = float.MaxValue;
// Assume the last vertex is the center vertex.
for (int i = 0; i < vertexCount - 1; i++)
{
float vertexDist = Vector3.Distance(s_Vertices[i], centerInPlaneSpace);
// Remap the UV so that a UV of "1" marks the feathering boudary.
// The ratio of featherBoundaryDistance/edgeDistance is the same as featherUV/edgeUV.
// Rearrange to get the edge UV.
float uvMapping = vertexDist / Mathf.Max(vertexDist-0.2f, 0.001f);
uv.x = vertexDist/uvMapping;
// All the UV mappings will be different. In the shader we need to know the UV value we need to fade out by.
// Choose the shortest UV to guarentee we fade out before the border.
// This means the feathering widths will be slightly different, we again rely on a fairly uniform plane.
//if (shortestUVMapping > uvMapping)
//{
// shortestUVMapping = uvMapping;
//}
s_UVs.Add(uv);
}
uv.Set(0, 0, 0);
s_UVs.Add(uv);
mesh.SetUVs(0, s_UVs);
mesh.UploadMeshData(false);
}
}

97
Assets/Common/Materials/PositionBased.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-6645622649702549290
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PositionBased
m_Shader: {fileID: -6465566751694194690, guid: 5339d23c4585cf8439edd87ecaf4759c,
type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- Texture2D_272C4861:
m_Texture: {fileID: 2800000, guid: 5e543473a544a4efb8008f3b27f6f9a5, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- Vector1_62687469: 1.5
- _AlphaClip: 0
- _Blend: 0
- _BumpScale: 1
- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _Surface: 0
- _WorkflowMode: 1
- _ZWrite: 1
m_Colors:
- Vector3_E80427D: {r: 0.85, g: 0, b: 0, a: 0}
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _ContactPosition: {r: 2.025, g: 0, b: 1.406, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

8
Assets/Common/Materials/PositionBased.mat.meta


fileFormatVersion: 2
guid: 9c50a26f8f4822547a53c52638848bd3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

24
Assets/Shaders/Scripts/ContactPosition.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContactPosition : MonoBehaviour
{
private Material m_TargetMaterial;
private int m_PropertyHash;
public GameObject m_TargetObject;
// Start is called before the first frame update
void Start()
{
m_PropertyHash = Shader.PropertyToID("_ContactPosition");
m_TargetMaterial = m_TargetObject.GetComponent<Renderer>().sharedMaterial;
}
// Update is called once per frame
void Update()
{
m_TargetMaterial.SetVector(m_PropertyHash, transform.position);
}
}

11
Assets/Shaders/Scripts/ContactPosition.cs.meta


fileFormatVersion: 2
guid: 3856305635085454e8af9cbef1878b3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

170
Assets/Shaders/Shader Graphs/PositionBasedRendering.shadergraph
文件差异内容过多而无法显示
查看文件

10
Assets/Shaders/Shader Graphs/PositionBasedRendering.shadergraph.meta


fileFormatVersion: 2
guid: 5339d23c4585cf8439edd87ecaf4759c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
正在加载...
取消
保存