Pokud "bod" je vertex, tak manipulovat s vertexy můžeš. Záleží kde s nimi budeš manipulovat?
Na CPU (C# script) to v případě častých úprav (každý frame) bude pomalé (upravit v CPU paměti, přesun z RAM do VRAM, rendering).
Na GPU to zase můžeš být složitější - pomocí vertex shaderu, ale bude to rychlé a výkonné.
Ukázka CPU varianty:
Mesh mesh = GetComponent<MeshFilter>().mesh; // Get mesh reference
Vector3[] vertices = mesh.vertices; // Get all verticies as Vector3 array, its copy not reference
for (int i = 0; i < vertices.Length; i++) {
vertices[i] += Vector3.right * Time.deltaTime; // Move every vertex to right in time
}
mesh.vertices = vertices; // Override verticies
mesh.RecalculateBounds(); // This is important step, Unity have to recalculate bounds with new verticies
Unity běžně používá surface shadery, ale lze si šáhnout i přímo na Vertex a Fragment shadery.Ukázka GPU varianty (vertex a surface shader):
Shader "MoveVerticiesToRight" {
Properties {
_MainTex ("Texture", 2D) = "white" {} // Texture input of object
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma vertex vert
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
};
struct v2f {
float4 pos : SV_POSITION;
};
// Vertex shader
v2f vert (inout appdata_full v)
{
v2f o;
v.vertex.xyz += float3(1, 0, 0) * _Time; // Move to right
o.pos = mul (UNITY_MATRIX_MVP, v.vertex); // Align position to MVP matrix
return o;
}
sampler2D _MainTex;
// Surface shader
// You must write fragment or surface shader or your object will not be rendered to render target color buffer
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; // Sample texture color into albedo channel
}
ENDCG
}
Fallback "Diffuse"
}
Problém GPU varianty je taky to, že když pohneš vertexy v GPU tak fyzikální collider se nepohne s nimi.BTW: Dal jsem tam menší komentáře k tomu kódu, tak snad to nějak půjde pochopit.