Skip to content

Instantly share code, notes, and snippets.

@lyuma
lyuma / SimpleParallax.shader
Created April 19, 2021 15:13
Simple parallax Unity surface shader using tangent space constructed in the vertex shader.
Shader "Custom/SimpleParallax"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
_ParallaxMap ("Height Map", 2D) = "black" {}
@lyuma
lyuma / VRMChecker.cs
Created March 3, 2021 12:58
Prints out pre- and post- quaternion values from Unity's Humanoid Avatar
// MIT License
// Copyright (c) 2021 Lyuma <[email protected]> and lox9973
// 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:
@lyuma
lyuma / rounded_trail_shaded.shader
Last active March 30, 2021 11:47
Rounded shader for a Unity Particle Trails and TrailRenderer, with shading.
// VERSION 0.3.1. Please get the latest version from:
// https://gist.github.com/lyuma/744e7fe35f7758add2f4468bb12f87f1
// Lyuma's Rounded Trail with Shading
// Based on phi16's rounded trail
// Based on Xiexe's Unity Lit Shader Templates:
// https://github.com/Xiexe/Unity-Lit-Shader-Templates
// Installation Notes:
// YOU MUST COPY ALL OF THE .cginc FILES FROM
@lyuma
lyuma / LightMasking.shader.glsl
Created February 18, 2021 06:05
Example Godot shader showing how writing to ALPHA can allow for a sort of light masking effect in 3D
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform float point_size : hint_range(0,128);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
@lyuma
lyuma / decal_albedo.shader.glsl
Created November 18, 2020 04:47
decal shader for Godot Engine
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
@lyuma
lyuma / GodotToUnitySH9.glsl
Created October 30, 2020 23:49
Convert Godot spherical harmonics to Unity SH9 coefficients (e.g. ShadeSH9)
// Global temporary variables in GLSL, and access to ambient/reflection/SH9 in shaders:
// Requires these patches:
// https://github.com/lyuma/godot/tree/shader_improvements_meta (master)
// https://github.com/lyuma/godot/tree/shader_global_arrays_3.2 (3.2)
// https://github.com/lyuma/godot/tree/shader_npr_lighting_3.2 (3.2)
vec4 unity_SHAr = vec4(0.0);
vec4 unity_SHAg = vec4(0.0);
vec4 unity_SHAb = vec4(0.0);
vec4 unity_SHBr = vec4(0.0);
@lyuma
lyuma / Parse16BitFloat.shader
Last active September 3, 2022 09:43
Godot Shader to extract the raw 16-bit integer in a FORMAT_RGBAH texture.
shader_type spatial;
render_mode unshaded;
uniform usampler2D data_tex;
/*
Use with the following GDScript code:
var data_img = Image.new()
var data := PoolByteArray()
var indexin = 0x8400
@lyuma
lyuma / tag_dockerhub_image.sh
Created September 4, 2020 14:46
Copies an image tag on DockerHub to another tag (such as latest)
#!/bin/bash
# Thanks to:
# https://dille.name/blog/2018/09/20/how-to-tag-docker-images-without-pulling-them/
# https://hub.docker.com/support/doc/how-do-i-authenticate-with-the-v2-api
# https://gist.github.com/alexanderilyin/8cf68f85b922a7f1757ae3a74640d48a
# for all the help.
# TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'"$(cat ~/.docker/config.json | cut -d\" -f8)"'", "password": "'"$(cat ~/.docker/config.json | cut -d\" -f12)"'"}' https://hub.docker.com/v2/users/login/ | cut -d\" -f4)
# "Authorization: JWT $TOKEN"
/* Copyright (c) 2020 Lyuma <[email protected]>
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
@lyuma
lyuma / CubemapTrioSkybox.shader
Created April 16, 2020 08:00
Cubemap shader - Added second and third third skybox if light is at sunset, or below the horizon respectively.
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
// Edited by Lyuma - Added second and third third skybox if light is at sunset, or below the horizon respectively.
Shader "Skybox/CubemapTrio"
{
Properties
{
_Rotation ("Rotation", Range(0, 360)) = 0
[NoScaleOffset] _Tex ("Cubemap Day", Cube) = "grey" {}
[NoScaleOffset] _TexSunset ("Cubemap Sunset", Cube) = "grey" {}
[NoScaleOffset] _TexNight ("Cubemap Night", Cube) = "grey" {}