Skip to content

Instantly share code, notes, and snippets.

View aras-p's full-sized avatar

Aras Pranckevičius aras-p

View GitHub Profile
@aras-p
aras-p / gist:5969838
Last active December 19, 2015 14:29
keywords metadata idea
// Likely winning idea:
// Rename multi_compile to shader_feature. When single name is passed, that expands into
// two variants; first without the define and second with the define.
// "_" (or any string of only underscores) is special case that makes a shader variant
// with no keywords defined for that feature.
#pragma shader_feature ALPHATEST_ON
#pragma shader_feature _ NORMALMAP_ON HEIGHTMAP_ON
#pragma shader_feature _ SPEC_CHEAP SPEC_GOOD SPEC_EXCELLENT
@aras-p
aras-p / swizzle.hlsl
Created August 6, 2013 19:23
ARB_texture_swizzle "emulation" for D3D
uniform float4 weightsR; // default 1,0,0,0
uniform float4 weightsG; // default 0,1,0,0
uniform float4 weightsB; // default 0,0,1,0
uniform float4 weightsA; // default 0,0,0,1
float4 swizzledTex2D (sampler2D smp, float2 uv)
{
float4 smp = tex2D (mysampler, myuv);
float4 res;
res.r = dot(smp,weightsR);
// this script on a default camera (identity rotation, 0,1,-10 position):
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
void Start () {
Debug.Log("camToW:\n" + camera.cameraToWorldMatrix);
Debug.Log("camToW^1:\n" + camera.cameraToWorldMatrix.inverse);
Debug.Log("wToCam:\n" + camera.worldToCameraMatrix);
Debug.Log("wToCam^1:\n" + camera.worldToCameraMatrix.inverse);
}
@aras-p
aras-p / shadow_filter.md
Created August 9, 2013 21:02
hacking shadow filtering in unity

Forward rendering:

  • Most of "shadow sampling" is in AutoLight.cginc include file somewhere in Unity.
  • Now, if you copy that file into your project somewhere, and have some shaders in the same folder - then these shaders will use yur local "hijacked" copy.
  • In all the functions that sample shadowmap, you could for example add more taps etc.

Deferred lighting:

  • most of shadow sampling code is in Internal-PrePassCollectShadows.shader / Internal-PrePassLighting.shader.
  • copy these built-in shaders into Resources folder of your project (Resources so they are always included into game build)
  • restart Unity and hack them.
@aras-p
aras-p / YourProbe.cs
Created August 12, 2013 15:50
probe pseudocode
class YourProbe : MonoBehaviour {
public Cubemap m_Probe;
public void Start() {
SetOntoShaders();
}
public void OnSelect() {
// do your "user picks stuff" thing,
// mip blurring and whatever
@aras-p
aras-p / preprocessor_fun.h
Last active September 8, 2025 11:28
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@aras-p
aras-p / foo.txt
Last active December 21, 2015 14:18
tracking down a bug
Build playe data:
WriteFileInternal, SerializedFile* tempSerialize = UNITY_NEW_AS_ROOT (this is our root!)
- eventually creates ExternalProcess, using that tempSerialize root for m_Buffer
DisplayProgressBar, which processes messages and repaints editor (?)
- eventually calls GetBuiltinSkin
-- this tries to load the skin (?), i.e. MonoBehaviour
--- PersistentManager::GetStreamNameSpaceInternal
---- nameSpace.stream = UNITY_NEW_AS_ROOT
@aras-p
aras-p / hg.md
Created September 3, 2013 18:44
hg multiple heads, no problem

Say you're working on a branch and comitting from two machines. Your regular work:

hg commit -m "foobar"
hg push -r tip

Now, two cases:

  1. no merge or nothing needed.
@aras-p
aras-p / cg.md
Last active December 22, 2015 10:49
Cg error reporting, wonderful!

Cg error reporting fun (Cg 3.1.0013). The actual error in both cases is on line 4.

This file:

  float4 vert () : POSITION
  {
    float4 v = 0;
    error_line_4;
    return 0;
 }
GL_VENDOR Apple Inc.
GL_VERSION OpenGL ES 2.0 Apple A7 GPU - 27.10
GL_RENDERER Apple A7 GPU
GL_EXTENSIONS GL_APPLE_copy_texture_levels
GL_APPLE_framebuffer_multisample
GL_APPLE_rgb_422
GL_APPLE_sync
GL_APPLE_texture_format_BGRA8888
GL_APPLE_texture_max_level
GL_EXT_blend_minmax