Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / RenderObjectsPass.cs
Created December 6, 2023 09:17 — forked from ArieLeo/RenderObjectsPass.cs
Unity URP sample -RenderObjects's RenderPass
using System.Collections.Generic;
using UnityEngine.Rendering.Universal;
using UnityEngine.Rendering;
using UnityEngine.Scripting.APIUpdating;
namespace UnityEngine.Experimental.Rendering.Universal
{
[MovedFrom("UnityEngine.Experimental.Rendering.LWRP")] public class RenderObjectsPass : ScriptableRenderPass
{
RenderQueueType renderQueueType;
@unitycoder
unitycoder / Usage.cs
Created December 6, 2023 09:16 — forked from ArieLeo/Usage.cs
DrawMeshInstancedIndirect with ShaderGraph and URP
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
class Render : MonoBehaviour
{
struct DrawData
{
public Vector3 Pos;
public Quaternion Rot;
@unitycoder
unitycoder / gist:b1a9fdbae5e35e70a52608ea776d59f8
Created November 26, 2023 18:37 — forked from texone/gist:66a46554a6fbda50ccc9831561e4037f
Unity lockless (no GPU readback) marching cubes via Graphics.DrawProceduralIndirect - some slight faffing because compute shader must append full triangle (3 verts) at a time to render correctly, but this means the appendbuffer count is 3 times smaller than it needs to be, so we have to invoke a very short compute shader (FixupIndirectArgs) just…
MarchingCubesGPU.cs:
...
// DrawProceduralIndirect
ComputeBuffer argsBuffer;
[StructLayout(LayoutKind.Sequential)]
struct DrawCallArgBuffer
{
public const int size =
sizeof(int) +
sizeof(int) +
@unitycoder
unitycoder / GlobalVariables.cs
Created November 17, 2023 09:14 — forked from hasanbayatme/GlobalVariables.cs
A simple C# static class to get and set globally accessible variables through a key-value approach (C#, Unity, .NET)
using System.Collections.Generic;
/// <summary>
/// A simple static class to get and set globally accessible variables through a key-value approach.
/// </summary>
/// <remarks>
/// <para>Uses a key-value approach (dictionary) for storing and modifying variables.</para>
/// <para>It also uses a lock to ensure consistency between the threads.</para>
/// </remarks>
public static class GlobalVariables
@unitycoder
unitycoder / AnimatorUtility.cs
Created November 17, 2023 09:13 — forked from hasanbayatme/AnimatorUtility.cs
Unity animator utilities such as checking if the animator has parameter or safely setting the animator parameters.
/**
MIT License
Copyright (c) 2023 Bayat Games
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@unitycoder
unitycoder / PoshWebHarness.ps1
Created October 31, 2023 08:43 — forked from pmolchanov/PoshWebHarness.ps1
Simple PowerShell HTTP/HTTPS web server useful for mocking web services
# Use the following commands to bind/unbind SSL cert
# netsh http add sslcert ipport=0.0.0.0:443 certhash=3badca4f8d38a85269085aba598f0a8a51f057ae "appid={00112233-4455-6677-8899-AABBCCDDEEFF}"
# netsh http delete sslcert ipport=0.0.0.0:443
$HttpListener = New-Object System.Net.HttpListener
$HttpListener.Prefixes.Add("http://+:80/")
$HttpListener.Prefixes.Add("https://+:443/")
$HttpListener.Start()
While ($HttpListener.IsListening) {
$HttpContext = $HttpListener.GetContext()
$HttpRequest = $HttpContext.Request
@unitycoder
unitycoder / PostDepthToWorldPos.shader
Created October 24, 2023 20:44 — forked from bgolus/PostDepthToWorldPos.shader
Get the world position from the camera depth texture with no external dependencies. Works as a post process or on an transparent object in the scene.
Shader "PostDepthToWorldPos"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
@unitycoder
unitycoder / MacroKiller.cs
Created October 23, 2023 17:31 — forked from frarees/MacroKiller.cs
Evaluate C# code on editor for Unity3D
// https://frarees.github.io/default-gist-license
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
// A modification of Kyle Halladay's Pencil Sketch Effect shader
// http://kylehalladay.com/blog/tutorial/2017/02/21/Pencil-Sketch-Effect.html
// Blends between two scales of hatching based on distance and camera fov to
// keep a perceptually constant hatching scale (assuming consistent mesh UVs).
Shader "Unlit/SingleObjectHatch_DistanceAndFOVCorrected"
{
Properties
{
Shader "Custom/ACNH_SewingCloth"
{
Properties
{
[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
[NoScaleOffset] _BumpMap ("Normal Map", 2D) = "bump" {}
[NoScaleOffset] _EdgeAlpha ("Alpha", 2D) = "white" {}
_Cutoff ("Alpha Test Cutoff", Range(0,1)) = 0.5
_Offset ("Offset (XY)", Vector) = (0,0,0,0)