I created a simple water shader graph and I was wondering if it was possible to apply it to a generated mesh. I can’t find much information on it, am I missing something?
This is the mesh generator:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class MeshGenerator : MonoBehaviour
{
Mesh mesh;
public Transform cam;
Vector3[ ] vertices;
int[ ] triangles;
public int xSize = 1000;
public int zSize = 1000;
public int previousXPos = -999, previousZPos = -999;
// Start is called before the first frame update
void Start()
{
mesh = new Mesh();
GetComponent().mesh = mesh;
}
void CreateShape(int zPos, int xPos)
{
vertices = new Vector3[(xSize + 1) * (zSize + 1)] ;
int jump = 50;
for (int i = 0, z = zPos - (zSize/2); z <= zPos + (zSize/2); z += jump)
{
for (int x = xPos - (xSize/2); x <= xPos + (xSize/2); x += jump )
{
vertices = new Vector3(x, 0, z); i++; } } triangles = new int[(xSize * zSize * 6)/jump]; int vert = 0; int tris = 0; for (int z = 0; z < zSize; z+= jump) { for (int x = 0; x < xSize; x+= jump) { triangles[tris + 0] = vert + 0; triangles[tris + 1] = vert + (xSize/jump) + 1; triangles[tris + 2] = vert + 1; triangles[tris + 3] = vert + 1; triangles[tris + 4] = vert + (xSize / jump) + 1; triangles[tris + 5] = vert + (xSize / jump) + 2; vert++; tris += 6; } vert++; }
} void UpdateMesh() { mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); } } Here is the Shader Graph: Imgur: The magic of the Internet
I know this is old, i just wanted to say thank you for going back and answering it yourself! I used a long time on trying to figure out why my shader didnt work. This worked smoothly!