Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / Paint Diffuse.shader
Created October 18, 2021 11:09
Using RenderTexture Painting Shader
// https://80.lv/articles/using-rendertexture-painting-shader/
Shader "Custom/Paint Diffuse" {
Properties{
_MainTex("Main Texture", 2D) = "white" {}
_PaintMap("PaintMap", 2D) = "white" {} // texture to paint on
}
@unitycoder
unitycoder / SetupRawInput.cs
Created October 18, 2021 16:41
c# read raw keyboard input
// https://forum.unity.com/threads/keyboard-input-is-not-registered-when-unity-is-embedded-in-a-wpf-application.962928/
[StructLayout(LayoutKind.Sequential)]
public struct RAWINPUTDEVICE
{
   public ushort usUsagePage;
   public ushort usUsage;
   public uint dwFlags;
   public IntPtr hwndTarget;
}
 
@unitycoder
unitycoder / TextFx.shader
Last active October 19, 2021 05:55
Scrolling Text Effect Shaders
// https://unitycoder.com/blog/2021/10/19/old-school-scrolling-text-with-shaders-rendertexture/
// this is for text mesh
Shader "Unlit/TextFx" {
Properties {
_MainTex ("Texture", 2D) = "white" { }
_Col1 ("Color 1", Color) = (1, 0.0, 0.0, 1.0)
_Col2 ("Color 2", Color) = (0, 1, 0.0, 1.0)
_Col3 ("Color 3", Color) = (0, 0, 1, 1.0)
_Scale ("Scale", Float) = 1
@unitycoder
unitycoder / frag.shader
Created October 21, 2021 10:35
Shader: Get the colour of light at the current fragment
// I made an additional camera underneath my main camera, set the target texture to a render texture,
// blit that texture through a material with a basic Image Effect Shader with:
fixed4 frag(v2f i) : SV_Target
{
const float val = Linear01Depth(tex2D(_CameraDepthTexture, i.uv).r);
return fixed4(val, val, val, 1);
}
// then used tex2dproj with my shadowPos to check if the
using UnityEngine;
using UnityEditor;
using UnityEngine.Timeline;
using UnityEngine.Playables;
using System.Collections.Generic;
using UnityEditor.Timeline;
using uOSC;
using UnityEngine.Events;
using EVMC4U;
using VRM;
@unitycoder
unitycoder / RimLight.shader
Created October 26, 2021 07:29
Rim Light Shader
// https://forum.unity.com/threads/soft-occlussion-shader.1188325/
Shader "CustomShader/Rim Light" {
    Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _RimColor ("Rim Color", Color) = (1, 1, 1, 1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _RimWidth ("RimWidth", Range(0,20.0)) = 0.7
    }
 
    SubShader {
@unitycoder
unitycoder / educational-discounts.md
Created October 26, 2021 08:01
Free stuff for students (educational freebies)
@unitycoder
unitycoder / SpriteExtension.cs
Created October 26, 2021 08:09
get sprite SecondaryTexture at runtime
// https://forum.unity.com/threads/how-to-get-secondarytexture-at-runtime.980334/
public static class SpriteExtension
    {
        public static Texture2D GetSecondary(this Sprite sprite, int index)
        {
            var methods = sprite.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (MethodInfo methodInfo in methods)
            {
                if (methodInfo.Name == "GetSecondaryTexture")
                {
@unitycoder
unitycoder / Client.cs
Created October 27, 2021 07:05
TCP image stream server
// https://answers.unity.com/questions/1741279/right-way-to-receive-images-over-tcp.html?childToView=1741342#answer-1741342
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
@unitycoder
unitycoder / gist:ceb32d20509bb4f5a28e4f1cd1f9a7f7
Created October 27, 2021 11:05 — forked from v21/gist:5378391
A script to get a random point on a mesh, for Unity3D
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RandomPointOnMesh : MonoBehaviour
{
public MeshCollider lookupCollider;
public bool bangGetPoint;
private Vector3 randomPoint;