Skip to content

Instantly share code, notes, and snippets.

View phi-lira's full-sized avatar

Felipe Lira phi-lira

View GitHub Profile
@phi-lira
phi-lira / UnlitTextureShadows.shader
Created April 30, 2020 08:28
Unlit Texture + Realtime Shadows 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 / UniversalPipelineTemplateShader.shader
Last active April 4, 2024 13:42
Template shader to use as guide to create Universal Pipeline ready shaders. This shader works with Universal Render Pipeline 7.1.x and above.
// When creating shaders for Universal Render Pipeline you can you the ShaderGraph which is super AWESOME!
// However, if you want to author shaders in shading language you can use this teamplate as a base.
// Please note, this shader does not necessarily match perfomance of the built-in URP Lit shader.
// This shader works with URP 7.1.x and above
Shader "Universal Render Pipeline/Custom/Physically Based Example"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
@phi-lira
phi-lira / UnlitTexture.shader
Last active March 23, 2024 18:12
URP Unlit Texture example
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 / RunXCodeCapture.txt
Created July 8, 2020 20:14
Run XCode Capture from Unity
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 / FullScreenQuad.cs
Created March 19, 2019 14:02
LWRP FullScreenQuad feature example. This can be used to extend LWRP render to render a full screen quad.
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 / HowToProfilerBuildTime.txt
Created July 15, 2020 12:08
How to profile build time for a Unity project
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 / DrawMeshPass
Last active September 6, 2022 14:50
Custom Pass injected by script
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 / LightweightLightSorting.cs
Created December 11, 2019 12:27
Old example of LWRP that sorted lights using the LightIndexMap
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 June 19, 2019 08:13
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.
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 / CustomMaterialEditor.cs
Created January 20, 2016 11:14
CustomMaterialEditor - Unity
//Copyright(c) 2015 Phil Lira - phil.rlira [at] gmail [dot] com
//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
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all