Skip to content

Instantly share code, notes, and snippets.

View quizcanners's full-sized avatar

Yurii Selinnyi quizcanners

View GitHub Profile
@quizcanners
quizcanners / PEGI vs EditorGUILayout
Last active September 17, 2018 09:08
PEGI wrapper for EditorGUILayout
// How it would have been written with standard functions. Class palced inside Editor Folder.
EditorGUILayout.BeginHorizontal();
int before = target.transparency;
target.transparency = EditorGUILayout.IntField("Transparency:", target.transparency);
if (target.transparency != before)
target.RecalculateShaderParameters();
// An example snippet for: https://www.quizcanners.com/single-post/2018/04/20/Story-Trigger-Data-Interface-iSTD
public stdEncoder Encode() => new stdEncoder()
.Add("mrkP", mapMarkerPosition);
.Add("mrkC", mapMarkerColor);
public bool Decode (string tag, string data){
switch (tag){
case "mrkP": mapMarkerPosition = data.ToVactor2(); break;
case "mrkC": mapMarkerColor = data.ToColor(); break;
public override void OnInspectorGUI() {
var controller = (MyMaterialController )target;
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
controller .transparency = EditorGUILayout.FloatField("Object's Transparency:", controller .transparency);
inline float3 DetectSmoothEdge(float3 edge, float3 junkNorm, float3 sharpNorm, float3 edge0, float3 edge1, float3 edge2) {
edge = max(0, edge - 0.965) * 28;
 float allof = edge.r + edge.g + edge.b;
float border = min(1, allof);
float3 edgeN = edge0*edge.r + edge1*edge.g + edge2*edge.b;
float junk = min(1, (edge.g*edge.b + edge.r*edge.b + edge.r*edge.g)*2);
return normalize((sharpNorm*(1 - border)+ border*edgeN)*(1 - junk) + junk*(junkNorm));
}
// Transparency
alpha:fade // Means it is not a glass
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
// Adjusting strength of the Normal
o.Normal = UnpackNormal(bump0);
o.Normal.xy *= wet;
o.Normal.z = 1;
// https://gist.github.com/hecomi/9580605
//Dirctionary:
View Matrix : camera.worldToCameraMatrix
// How to project a texture:
//cs:
projectionMatrix = camera.projectionMatrix * camera.worldToCameraMatrix
//vert:
// Article: https://medium.com/@quizcanners/unity-i-have-a-custom-editor-for-every-script-5eddf20fdacc
using System.Collections.Generic;
using QuizCanners.Inspector;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class SomeScript : MonoBehaviour: IPEGI {
public Inspect()
{
if ("Object's Transparency:".edit(ref transparency))
RecalculateShaderParameters();
if (transparency != 0.5f && icon.Refresh.Click("Will load default value",25).nl())
transparency = 0.5f;
}
@quizcanners
quizcanners / Tricks for SDF
Last active June 13, 2022 17:33
SDF Functions
Revolution. Use length(xy) as one of the parameters for any function.
Subtract X from SDF - scale it up.
max - intersect
min - unite
lerp(sdf1, sdf2, t) to morph the two
@quizcanners
quizcanners / Circle.shader
Last active September 5, 2022 03:31
Vert Frag Shader Template
// This is a starting point for most effects I make.
Shader "Playtime Painter/Effects/Circle" {
Properties{
_MainTex("Albedo (RGB)", 2D) = "white" {}
[Toggle(_DEBUG)] debugOn("Debug", Float) = 0
}
SubShader{
Tags{