Procedural Drawing
This commit is contained in:
parent
a64346ee62
commit
2f409b3606
24
Assets/Point/Point GPU.hlsl
Normal file
24
Assets/Point/Point GPU.hlsl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||||
|
StructuredBuffer<float3> _Positions;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float _Step;
|
||||||
|
|
||||||
|
void ConfigureProcedural()
|
||||||
|
{
|
||||||
|
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||||
|
float3 position = _Positions[unity_InstanceID];
|
||||||
|
|
||||||
|
unity_ObjectToWorld = 0.0;
|
||||||
|
unity_ObjectToWorld._m03_m13_m23_m33 = float4(position, 1.0);
|
||||||
|
unity_ObjectToWorld._m00_m11_m22 = _Step;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderGraphFunction_float (float3 In, out float3 Out) {
|
||||||
|
Out = In;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderGraphFunction_half (half3 In, out half3 Out) {
|
||||||
|
Out = In;
|
||||||
|
}
|
9
Assets/Point/Point GPU.hlsl.meta
Normal file
9
Assets/Point/Point GPU.hlsl.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 52ba3338a3c5fd040985e2d7cd13ae29
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
78
Assets/Point/Point Surface GPU.mat
Normal file
78
Assets/Point/Point Surface GPU.mat
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Point Surface GPU
|
||||||
|
m_Shader: {fileID: 4800000, guid: 777e5d31099aed84eab73d2aff7dcfca, type: 3}
|
||||||
|
m_ShaderKeywords:
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
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}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Floats:
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0.5
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _Smoothness: 0.5
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
8
Assets/Point/Point Surface GPU.mat.meta
Normal file
8
Assets/Point/Point Surface GPU.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 584eab0d393b59e40ac387043a54b24f
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
35
Assets/Point/Point Surface GPU.shader
Normal file
35
Assets/Point/Point Surface GPU.shader
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Shader "Graph/Point Surface GPU"
|
||||||
|
{
|
||||||
|
Properties
|
||||||
|
{
|
||||||
|
_Smoothness("Smoothness", Range(0, 1)) = 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
SubShader
|
||||||
|
{
|
||||||
|
CGPROGRAM
|
||||||
|
#pragma surface ConfigureSurface Standard fullforwardshadows addshadow
|
||||||
|
#pragma instancing_options assumeuniformscaling procedural:ConfigureProcedural
|
||||||
|
#pragma editor_sync_compilation
|
||||||
|
#pragma target 4.5
|
||||||
|
|
||||||
|
#include "Point GPU.hlsl"
|
||||||
|
|
||||||
|
struct Input
|
||||||
|
{
|
||||||
|
float3 worldPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
float _Smoothness;
|
||||||
|
|
||||||
|
void ConfigureSurface(Input input, inout SurfaceOutputStandard surface)
|
||||||
|
{
|
||||||
|
surface.Albedo = saturate(input.worldPos * 0.5 + 0.5);
|
||||||
|
surface.Smoothness = _Smoothness;
|
||||||
|
}
|
||||||
|
|
||||||
|
ENDCG
|
||||||
|
}
|
||||||
|
|
||||||
|
FallBack "Diffuse"
|
||||||
|
}
|
9
Assets/Point/Point Surface GPU.shader.meta
Normal file
9
Assets/Point/Point Surface GPU.shader.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 777e5d31099aed84eab73d2aff7dcfca
|
||||||
|
ShaderImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
defaultTextures: []
|
||||||
|
nonModifiableTextures: []
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
90
Assets/Point/Point URP GPU.mat
Normal file
90
Assets/Point/Point URP GPU.mat
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &-3089080242542461839
|
||||||
|
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: 2
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 6
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Point URP GPU
|
||||||
|
m_Shader: {fileID: -6465566751694194690, guid: edb00fc61da38e141a5047af96ae1a0a,
|
||||||
|
type: 3}
|
||||||
|
m_ShaderKeywords:
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _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:
|
||||||
|
- _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:
|
||||||
|
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
8
Assets/Point/Point URP GPU.mat.meta
Normal file
8
Assets/Point/Point URP GPU.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e470d4aed9c37a448b5bccf749811b9d
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
128
Assets/Point/Point URP GPU.shadergraph
Normal file
128
Assets/Point/Point URP GPU.shadergraph
Normal file
File diff suppressed because one or more lines are too long
10
Assets/Point/Point URP GPU.shadergraph.meta
Normal file
10
Assets/Point/Point URP GPU.shadergraph.meta
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: edb00fc61da38e141a5047af96ae1a0a
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
|
@ -98,7 +98,7 @@ LightmapSettings:
|
|||||||
m_TrainingDataDestination: TrainingData
|
m_TrainingDataDestination: TrainingData
|
||||||
m_LightProbeSampleCountMultiplier: 4
|
m_LightProbeSampleCountMultiplier: 4
|
||||||
m_LightingDataAsset: {fileID: 0}
|
m_LightingDataAsset: {fileID: 0}
|
||||||
m_UseShadowmask: 0
|
m_UseShadowmask: 1
|
||||||
--- !u!196 &4
|
--- !u!196 &4
|
||||||
NavMeshSettings:
|
NavMeshSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@ -130,7 +130,6 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 75389716}
|
- component: {fileID: 75389716}
|
||||||
- component: {fileID: 75389715}
|
|
||||||
- component: {fileID: 75389717}
|
- component: {fileID: 75389717}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Graph
|
m_Name: Graph
|
||||||
@ -139,25 +138,6 @@ GameObject:
|
|||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 1
|
||||||
--- !u!114 &75389715
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 75389714}
|
|
||||||
m_Enabled: 0
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 14cd06bfa92d53e4ebc0cde4a0e39db8, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
pointPrefab: {fileID: 5221897554875366738, guid: d73a635284aa0ca4eb9cc40879b3267d,
|
|
||||||
type: 3}
|
|
||||||
resolution: 200
|
|
||||||
function: 4
|
|
||||||
transitionMode: 2
|
|
||||||
functionDuration: 1
|
|
||||||
transitionDuration: 1
|
|
||||||
--- !u!4 &75389716
|
--- !u!4 &75389716
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -184,7 +164,10 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 4e99d61420a0d1f459f961121d6fbe77, type: 3}
|
m_Script: {fileID: 11500000, guid: 4e99d61420a0d1f459f961121d6fbe77, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
resolution: 200
|
computeShader: {fileID: 7200000, guid: c7f7fcb3b4a90614b80aa341489318e7, type: 3}
|
||||||
|
material: {fileID: 2100000, guid: e470d4aed9c37a448b5bccf749811b9d, type: 2}
|
||||||
|
mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
resolution: 1000
|
||||||
function: 4
|
function: 4
|
||||||
transitionMode: 1
|
transitionMode: 1
|
||||||
functionDuration: 1
|
functionDuration: 1
|
||||||
|
@ -5,7 +5,15 @@ public class GPUGraph : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
ComputeShader computeShader = default;
|
ComputeShader computeShader = default;
|
||||||
|
|
||||||
[SerializeField, Range(10, 200)]
|
[SerializeField]
|
||||||
|
Material material = default;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
Mesh mesh = default;
|
||||||
|
|
||||||
|
const int maxResolution = 1000;
|
||||||
|
|
||||||
|
[SerializeField, Range(10, maxResolution)]
|
||||||
int resolution = 10;
|
int resolution = 10;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -37,7 +45,7 @@ public class GPUGraph : MonoBehaviour
|
|||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
positionsBuffer = new ComputeBuffer(resolution * resolution, 3 * 4);
|
positionsBuffer = new ComputeBuffer(maxResolution * maxResolution, 3 * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDisable()
|
private void OnDisable()
|
||||||
@ -86,5 +94,10 @@ public class GPUGraph : MonoBehaviour
|
|||||||
|
|
||||||
var groups = Mathf.CeilToInt(resolution / 8f);
|
var groups = Mathf.CeilToInt(resolution / 8f);
|
||||||
computeShader.Dispatch(0, groups, groups, 1);
|
computeShader.Dispatch(0, groups, groups, 1);
|
||||||
|
|
||||||
|
material.SetBuffer(positionsId, positionsBuffer);
|
||||||
|
material.SetFloat(stepId, step);
|
||||||
|
var bounds = new Bounds(Vector3.zero, Vector3.one * (2f + 2f / resolution));
|
||||||
|
Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, resolution * resolution);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user