Skip to content

Instantly share code, notes, and snippets.

View noisecrime's full-sized avatar

NoiseCrime noisecrime

View GitHub Profile
@aras-p
aras-p / gist:dea83b8309a75554067c
Created August 13, 2014 09:37
sampling shadowmap without comparison on d3d11
// Problem is that by default SamplerComparisonState sampler is coupled with the shadowmap.
// So if you want to sample it regularly, you'll have to find a suitable sampler from another used texture.
// For example, let's say _MainTex has a suitable sampler (set to bilinear, whatever).
UNITY_DECLARE_TEX2D(_MainTex); // will declare Texture2D _MainTex and SamplerState sampler_MainTex
UNITY_DECLARE_SHADOWMAP(_Myshadow); // will declare Texture2D _Myshadow and SamplerComparisonState sampler_Myshadow
// sample as a shadowmap with comparison (all platforms)
float s = UNITY_SAMPLE_SHADOW_PROJ(_Myshadow, float4(xy,depth,1.0));
@aras-p
aras-p / gist:ac4339c040afabea6ee7
Created August 18, 2014 09:13
fog macros WIP
// ------------------------------------------------------------------
// Fog helpers
//
// multi_compile_fog Will compile fog variants.
// UNITY_FOG_COORDS(texcoordindex) Declares the fog data interpolator.
// UNITY_TRANSFER_FOG(outputStruct,clipspacePos) Outputs fog data from the vertex shader.
// UNITY_APPLY_FOG(fogData,col) Applies fog to color "col". Automatically applies black fog when in forward-additive pass.
// Can also use UNITY_APPLY_FOG_COLOR to supply your own fog color.
// In case someone by accident tries to compile fog code in one of the g-buffer or shadow passes:
@aras-p
aras-p / gist:d345e7292b62e7844508
Created August 21, 2014 12:28
mecanim per animation speed
Here's what the animation folks say:
"There is a speed per node in blend tree editor"
Now, if you need to change these speeds at runtime, then that feature is on their roadmap; for now you could do a workaround:
1. create a blend tree with 2 times the same clip
2. with different speeds (set in the editor)
3. then at runtime change the blend parameter of that blend tree; it will control the speed of the clip at runtime
Shader "GUI/Text Shader" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags {
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
@aras-p
aras-p / using_vpos.shader
Last active February 3, 2018 12:39
Using VPOS
// yeah it's not terribly nice
Shader "Foo" {
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
@aras-p
aras-p / foo.md
Last active January 27, 2021 06:32
Controlling fixed function states from materials/scripts in Unity

(typing off the top of my head, might not compile)

Since Unity 4.3:

In the shader, instead of writing Cull Off, write Cull [_MyCullVariable], the value will be fetched from the material or global float/int variable _MyCullVariable then.

You could have it be part of material, e.g. inside Properties block:

[Enum(Off,0,Front,1,Back,2)] _MyCullVariable ("Cull", Int) = 1
@aras-p
aras-p / z.shader
Created January 8, 2015 13:31
View space Z shader
Shader "Aaa" {
SubShader {
Cull Off ZTest Always ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
@mzaks
mzaks / RectTransformTools.cs
Last active April 14, 2025 18:11
Adjust RectTransform Anchors for Unity UI
using UnityEngine;
using UnityEditor;
public class RectTransformTools {
[MenuItem("GameObject/Adjust RectTransform Anchors %l")]
static void Adjust()
{
foreach(GameObject gameObject in Selection.gameObjects){
adjustRectTransform(gameObject);
@simonbroggi
simonbroggi / TouchScriptInputModule.cs
Last active May 7, 2024 09:16
Input Module to use the new unity ui with multitouch from https://github.com/TouchScript
/**
* Input Module to use the new unity ui with multitouch from https://github.com/TouchScript
* Install TouchScript in your unity project, then add an EventSystem and replace the InputModules by this one.
*
*
* Basically modified TouchInputModule from
* https://bitbucket.org/Unity-Technologies/ui/src/5fc21bb4ecf4b40ff6630057edaa070252909b2e/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs?at=4.6
* and changing ProcessTouchEvent to take events from TouchScript
*
* Got the TouchScript stuff from
@aras-p
aras-p / gist:1c2e27b71006023a1108
Last active August 29, 2015 14:17
min16float workaround
// add this in your shader before using min16float etc. in current (4.x and 5.0)
// unity versions. will fix this soon
#if !defined(SHADER_API_D3D11) && !defined(SHADER_API_D3D11_9X)
#define min16float half
#define min16float2 half2
#define min16float3 half3
#define min16float4 half4
#define min10float fixed
#define min10float2 fixed2
#define min10float3 fixed3