(Unity) vertex color importer for MeshLab's OBJ files
This toy code worked fine in the older Unity version but stopped working correctly in the newer ones. Something about the vertex data order. I suggest using different format - FBX for example.
| Shader "Unlit/InfiniteGrid" | |
| { | |
| Properties | |
| { | |
| [Toggle] _WorldUV ("Use World Space UV", Float) = 1.0 | |
| _GridScale ("Grid Scale", Float) = 1.0 | |
| _GridBias ("Grid Bias", Float) = 0.5 | |
| _GridDiv ("Grid Divisions", Float) = 10.0 | |
| _BaseColor ("Base Color", Color) = (0,0,0,1) | |
| _LineColor ("Line Color", Color) = (1,1,1,1) |
| // https://twitter.com/Cyanilux/status/1396848736022802435?s=20 | |
| #ifndef GRASS_INSTANCED_INCLUDED | |
| #define GRASS_INSTANCED_INCLUDED | |
| // ---------------------------------------------------------------------------------- | |
| // Graph should contain Boolean Keyword, "PROCEDURAL_INSTANCING_ON", Global, Multi-Compile. | |
| // Must have two Custom Functions in vertex stage. One is used to attach this file (see Instancing_float below), | |
| // and another to set #pragma instancing_options : |
| // https://twitter.com/Cyanilux/status/1396848736022802435 | |
| // Requires a specific shader to read the _PerInstanceData buffer at SV_InstanceID | |
| // I use a shader made in Shader Graph, See : https://gist.github.com/Cyanilux/4046e7bf3725b8f64761bf6cf54a16eb | |
| // Also note, there's no frustum culling involved in this example. Typically a compute shader is used for this. | |
| using UnityEngine; | |
| public class DrawGrass : MonoBehaviour { |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using UnityEditor; | |
| using UnityEngine; | |
| using Object = UnityEngine.Object; | |
| public class MaterialGradientDrawer : MaterialPropertyDrawer { | |
| private int resolution; |
| using System.Collections.Generic; | |
| /// <summary>A Kalman filter implementation for <c>float</c> values.</summary> | |
| public class KalmanFilterFloat { | |
| //----------------------------------------------------------------------------------------- | |
| // Constants: | |
| //----------------------------------------------------------------------------------------- | |
| public const float DEFAULT_Q = 0.000001f; |
| void vert(inout appdata_full v, out Input o) | |
| { | |
| UNITY_INITIALIZE_OUTPUT(Input, o); | |
| // get the camera basis vectors | |
| float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22); | |
| float3 up = float3(0, 1, 0); //normalize(UNITY_MATRIX_V._m10_m11_m12); | |
| float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02); | |
| // rotate to face camera |
Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative
float rand(float n){return fract(sin(n) * 43758.5453123);}
float noise(float p){
float fl = floor(p);
float fc = fract(p);