Skip to content

Instantly share code, notes, and snippets.

Avatar

Felipe Lira phi-lira

View GitHub Profile
@phi-lira
phi-lira / DrawMeshPass
Last active Mar 29, 2021
Custom Pass injected by script
View DrawMeshPass
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
[ExecuteInEditMode]
public class CustomPass : MonoBehaviour
{
public Mesh mesh;
public Material material;
DrawMeshPass m_DrawMeshPass;
@phi-lira
phi-lira / HowToProfilerBuildTime.txt
Created Jul 15, 2020
How to profile build time for a Unity project
View HowToProfilerBuildTime.txt
1) Enable Profiler in OnPreprocessBuild like following:
public void OnPreprocessBuild(BuildReport report)
{
Profiler.enabled = true;
Profiler.enableBinaryLog = true;
Profiler.logFile = "profilerlog.raw";
Debug.Log("Enabling Profiler");
}
2) Disable Profiler in OnPostProcessBuild
3) Now put Profiler.Begin/EndSample in the desired code.
@phi-lira
phi-lira / RunXCodeCapture.txt
Created Jul 8, 2020
Run XCode Capture from Unity
View RunXCodeCapture.txt
1. Create a new XCode Metal (library) project.
2. Edit Scheme. Product->Scheme->Edit Scheme
3. Run, Info tab, and point to your application
E.g. /Application/Unity/Hub/Editor/Unity.app
4. Run, Arguments tab to add cmdline arguments
E.g. -projectPath "/Users/name.name/projects/MyProject"
5. Run, Options tab, set to GPU Frame Capture to Metal
6. Run the project and click the camera icon from XCode to take a capture
@phi-lira
phi-lira / UnlitTextureShadows.shader
Created Apr 30, 2020
Unlit Texture + Realtime Shadows shader
View UnlitTextureShadows.shader
Shader "Universal Render Pipeline/Custom/UnlitTextureShadows"
{
Properties
{
[MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
[MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
}
SubShader
{
@phi-lira
phi-lira / UnlitTexture.shader
Last active Sep 29, 2021
URP Unlit Texture example
View UnlitTexture.shader
Shader "Custom/UnlitTexture"
{
Properties
{
[MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
[MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
}
// Universal Render Pipeline subshader. If URP is installed this will be used.
SubShader
@phi-lira
phi-lira / LightweightLightSorting.cs
Created Dec 11, 2019
Old example of LWRP that sorted lights using the LightIndexMap
View LightweightLightSorting.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
#if UNITY_EDITOR
using UnityEditor.Experimental.Rendering.LightweightPipeline;
#endif
using UnityEngine.Experimental.GlobalIllumination;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
@phi-lira
phi-lira / CustomRenderPassFeature.cs
Created Jun 19, 2019
Custom Render Feature script template to be added to a LWRP Renderer. Drag 'n Drop this script to your project, write the desired rendering code. It now it's available to be added to a LWRP renderer by clicking on the + icon under renderer features in the Renderer inspector.
View CustomRenderPassFeature.cs
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.LWRP;
public class CustomRenderPassFeature : ScriptableRendererFeature
{
class CustomRenderPass : ScriptableRenderPass
{
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
@phi-lira
phi-lira / FullScreenQuad.cs
Created Mar 19, 2019
LWRP FullScreenQuad feature example. This can be used to extend LWRP render to render a full screen quad.
View FullScreenQuad.cs
namespace UnityEngine.Rendering.LWRP
{
// A renderer feature contains data and logic to enqueue one or more render passes in the LWRP renderer.
// In order to add a render feature to a LWRP renderer, click on the renderer asset and then on the + icon in
// the renderer features list. LWRP uses reflection to list all renderer features in the project as available to be
// added as renderer features.
public class FullScreenQuad : ScriptableRendererFeature
{
[System.Serializable]
public struct FullScreenQuadSettings
@phi-lira
phi-lira / PhysicallyBasedExample.shader
Last active May 19, 2020
Physically Based Example shader that works with Lightweight Render Pipeline (LWRP) 4.X.X-preview
View PhysicallyBasedExample.shader
Use https://gist.github.com/phi-lira/225cd7c5e8545be602dca4eb5ed111ba instead.
@phi-lira
phi-lira / PerfTracker.cs
Created Mar 16, 2018
Performance Tracker scripts.
View PerfTracker.cs
// Script made by aleks01010101
// Slightly modified
// Displays avg and median ms + frames sampled during clipLenght
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PerfTracker : MonoBehaviour {
public float clipLength = 20.0f;