Skip to content

Instantly share code, notes, and snippets.

View forkercat's full-sized avatar
🉑
一杯咖啡、一只猫

Junhao Wang forkercat

🉑
一杯咖啡、一只猫
View GitHub Profile
@forkercat
forkercat / ShaderInteractor.cs
Last active August 14, 2023 05:06
Making Sky's Stylized Grass with Compute Shader in Unity. Check out junhaow.com for an article! Update: https://www.patreon.com/posts/urp-compute-54164790
// Credit: https://www.patreon.com/posts/grass-geometry-1-40090373
using UnityEngine;
public class ShaderInteractor : MonoBehaviour
{
private void Update()
{
// Set player position
Shader.SetGlobalVector("_MovingPosition", transform.position);
@forkercat
forkercat / GrassComputeRenderer.cs
Last active February 1, 2023 08:20
Compute Shader Renderer C# Script
//
// Created by @Forkercat on 03/04/2021.
//
// A URP compute shader renderer to upload data (created by grass painter tool)
// to compute shader. Check out shader files for mode definitions and comments.
//
// [Added Features]
// 1. Override Material Properties (color, ambient strength)
// 2. Cast Shadow Checkbox (since we are not using MeshRenderer anymore, we can do it here)
//
@forkercat
forkercat / GrassCompute.compute
Last active March 7, 2021 18:01
GrassCompute (the Compute Shader)
//
// Created by @Forkercat on 03/04/2021.
//
// A URP grass shader using compute shader rather than geometry shader.
// This file contains kernel function which works like a geometry function.
// It defines the buffers needed to pass data from renderer C# script to here
// and from here to our vertex and fragment functions.
//
// Note that data flows differently in different cases.
// [Compute Shader] Data Flow : Mesh -> Compute Shader -> Vertex Shader -> Fragment Shader
@forkercat
forkercat / GrassCompute.hlsl
Last active March 6, 2021 18:36
GrassCompute vertex & fragment functions (for Compute Shader)
//
// Created by @Forkercat on 03/04/2021.
//
// A URP grass shader using compute shader rather than geometry shader.
// This file contains vertex and fragment functions. It also defines the
// structures which should be the same with the ones used in GrassCompute.compute.
//
// References & Credits:
// 1. GrassBlades.hlsl (https://gist.github.com/NedMakesGames/3e67fabe49e2e3363a657ef8a6a09838)
// 2. GrassGeometry.shader (https://pastebin.com/VQHj0Uuc)
@forkercat
forkercat / GrassCompute.shader
Created March 5, 2021 04:31
GrassCompute Shader (for Compute Shader)
//
// Created by @Forkercat on 03/04/2021.
//
// A URP grass shader using compute shader rather than geometry shader.
// It includes "GrassCompute.hlsl" which contains vertex and fragment functions.
//
// Note that this shader works with the grass painter tool created by MinionsArt.
// Checkout the website for the tool scripts. I also made an updated version that
// introduces shortcuts just for convenience.
// https://www.patreon.com/posts/geometry-grass-46836032
@forkercat
forkercat / GeometryGrassPainter.cs
Created March 5, 2021 04:29
Updated Version of The Grass Painter by MinionsArt
// Compute Shader Version of The Grass Painter by MinionsArt
// 1. Some renames
// 2. Added several shortcuts
// 3. Added mesh name
// 4. Mesh component is public
// 5. Remove MeshRenderer component requirement
// Source: https://pastebin.com/xwhSJkFV
// Tutorial: https://www.patreon.com/posts/geometry-grass-46836032
using System.Collections.Generic;
@forkercat
forkercat / GrassPainterEditor.cs
Last active March 4, 2021 20:33
Updated Version of The Grass Paint Editor by MinionsArt
// Updated Version of The Grass Paint Editor by MinionsArt
// 1. Some renames
// 2. Added shortcut hint
// 3. Updated UI (progress bar, etc)
// Source: https://pastebin.com/Y7dCRAd3
// Tutorial: https://www.patreon.com/posts/geometry-grass-46836032
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
@forkercat
forkercat / GeometryGrassPainter.cs
Last active January 15, 2024 21:56
Updated Version of The Grass Painter by MinionsArt
// Updated Version of The Grass Painter by MinionsArt
// 1. Some renames
// 2. Added several shortcuts
// 3. Added mesh name
// Source: https://pastebin.com/xwhSJkFV
// Tutorial: https://www.patreon.com/posts/geometry-grass-46836032
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
import java.util.HashMap;
import java.util.Map;
/**
* @author Junhao Wang
* @date 01/05/2020
*/
// WayBid.java
import java.util.*;
// 记得导入类
/**
* @author Junhao Wang
* @date 01/05/2020
*/
// 注意不要用下划线命名!