Skip to content

Instantly share code, notes, and snippets.

Dave Pape davepape

View GitHub Profile
@davepape
davepape / noiseland2.cs
Last active Nov 6, 2018
Combination of noiseland.cs & noisetex.cs - creates landscape geometry and a texture to apply to the geometry
View noiseland2.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class noiseland2 : MonoBehaviour {
public int numRows=10, numCols=10;
public float minX=-1, maxX=1, minY=-1, maxY=1;
public int tex_width=256;
@davepape
davepape / noisetex.cs
Last active Nov 6, 2018
Create a fractal, procedural texture by combining different frequencies of Perlin noise
View noisetex.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class noisetex : MonoBehaviour {
public int width=256;
public int height=256;
private Texture2D tex;
private Color32[] colors;
@davepape
davepape / noiseland.cs
Last active Nov 6, 2018
Create a fractal landscape by combining different frequencies of Perlin noise
View noiseland.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class noiseland : MonoBehaviour {
public int numRows=10, numCols=10;
public float minX=-1, maxX=1, minY=-1, maxY=1;
float height(float x, float y)
@davepape
davepape / fractalland.cs
Created Nov 1, 2018
Create a fractal landscape mesh in Unity3D, using midpoint subdivision
View fractalland.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fractalland : MonoBehaviour {
Vector3[][] newArray(int size)
{
Vector3[][] v = new Vector3[size][];
for (int i=0; i < size; i++)
@davepape
davepape / triangles3.cs
Last active Oct 18, 2018
Create a mesh of 2 triangles, with texture coordinates
View triangles3.cs
// Creating Mesh data in Unity
// This script should be attached to a GameObject that has a MeshFilter and MeshRenderer.
// The script will replace the MeshFilter's geometry by 2 triangles with texture coordinates.
// The vertex coords & tex coords are public variables so they can be manipulated from the Unity inspector.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class triangles3 : MonoBehaviour {
@davepape
davepape / waves.cs
Created Oct 17, 2018
Create simple animated waves
View waves.cs
// Creates a Unity Mesh that contains a wavy 2D surface, then animates that surface.
// Based on grid.cs (except now in the X/Z plane), gives each vertex a different height using Sin & Cos.
// Should be attached to a GameObject that already has a MeshFilter component.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class waves : MonoBehaviour {
public int numRows=10, numCols=10;
@davepape
davepape / grid.cs
Created Oct 17, 2018
Create a Unity mesh containing a simple 2D grid of triangles
View grid.cs
// Create a mesh of triangles in a 2D grid
// Attach this script to a GameObject that already has a MeshFilter - it will use that MeshFilter, replacing its existing mesh data
// Creates a numCols x numRows grid of vertices in the X/Y plane. Then for each square cell in the grid it creates 2 triangles
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grid : MonoBehaviour {
public int numRows=10, numCols=10;
@davepape
davepape / mouseTriangles.cs
Last active Oct 11, 2018
Make a trail of triangles that follow the mouse
View mouseTriangles.cs
// Draw a set of triangles that follow the mouse.
// This script should be attached to a GameObject that has a MeshRenderer (with Material).
// The script will create a MeshFilter and fill it with triangles. On each frame, one triangle will be changed to appear at the mouse position. It cycles through all the triangles, to create a tail of fixed length.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class mouseTriangles : MonoBehaviour {
public int numTriangles=1;
@davepape
davepape / triangles2.cs
Created Oct 11, 2018
Create a Unity Mesh with 2 triangles
View triangles2.cs
// Creating Mesh data in Unity
// This script should be attached to an empty GameObject. It requires vertexColor.shader (https://gist.github.com/davepape/0dee3b1550a1f4159bc173e1b32dbe0c)
// On startup, it will create a MeshFilter containing 2 triangles, and apply a Material.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class triangles2 : MonoBehaviour {
void Start ()
@davepape
davepape / vertexColor.shader
Created Oct 11, 2018
minimal Unity shader, to use vertex colors without lighting or texture
View vertexColor.shader
// taken from http://answers.unity3d.com/questions/391561/create-a-mesh-and-color-cubes.html
Shader "Custom/Vertex Colored"
{
Properties
{
}
SubShader
{
Pass
{
You can’t perform that action at this time.