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 / file.md
Last active September 30, 2016 08:29
"Unity on mobile wtfs"

Too long to reply on twitter, so.

300 vertex limit[900 = uv+norm+pos), 6 passes for dynamic shadows, terrain shader is inefficient, etc... Win RT+Unity sounds FUN!

I haven't watched the video, but have looked at the slides. So, point by point:

300 vertex limit

That is for dynamic batching, i.e. meshes larger than that aren't transformed on the CPU each frame to try to save the draw calls. This isn't a WinRT limiation; it simply doesn't make sense to spend CPU time transforming larger meshes, in order to save some CPU time to save a draw call.

@aras-p
aras-p / assertbreak.h
Created December 3, 2013 08:23
Assert break implementations
#if defined(__ppc__)
#define DEBUG_BREAK __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" : : : "memory","r0","r3","r4" )
#elif UNITY_OSX
#if defined(__clang__)
#define DEBUG_BREAK if (IsDebuggerPresent ()) __builtin_trap ()
#else
#define DEBUG_BREAK if (IsDebuggerPresent ()) __asm { int 3 }
#endif
#elif UNITY_WIN
#define DEBUG_BREAK if (IsDebuggerPresent ()) __debugbreak()
@aras-p
aras-p / opaque-vs-alpha.diff
Created December 24, 2013 09:45
Difference between opaque & alpha surface shader generated code
--- GeneratedFromSurface-NewShader1.shader 2013-12-24 11:42:37.000000000 +0200
+++ GeneratedFromSurface-NewShader.shader 2013-12-24 11:43:01.000000000 +0200
@@ -9,18 +9,20 @@
// ------------------------------------------------------------
// Surface shader code generated out of a CGPROGRAM block:
+ Alphatest Greater 0 ZWrite Off ColorMask RGB
// ---- forward rendering base pass:
@aras-p
aras-p / gist:8219327
Created January 2, 2014 13:43
Math is free! Well, not quite.
Commit message:
Modify CollectShadows shader to handle orthographic case.
This does make the shader more heavy on ALU: +1 float4 interpolant,
+7 d3d9 SM2.0 math ops. Could compile into 2x more variants
for perspective vs ortho if needed.
GPUShaderAnalyzer for Radeon HDs clocks:
HD6450: 15.50 -> 18.50
HD6670: 5.17 -> 6.17
@aras-p
aras-p / hg and git snippets and stats.md
Last active September 28, 2021 10:02
hg churn and log cheat sheet, ono graphql

Git

Fetch single branch (trunk): git fetch origin trunk:trunk (add -u flag when already on that branch)

Make a new worktree (similar to hg share): git worktree add --no-checkout --detach ../mynewfolder

Converting Hg repo to Git:

; get https://github.com/frej/fast-export somewhere
@aras-p
aras-p / disunity.md
Last active January 2, 2016 12:19
"Disassembling" Unity game data files

Question: https://twitter.com/duhroach/status/420268057034911744

Rough answer: yeah the basic approach that disunity (https://github.com/ata4/disunity) takes is as correct as possible, without us providing actual file format docs.

Basically, game data files built by Unity can come in two flavors:

  1. With "type tree" (think RTTI) information. A file has type layout info for all types in it, and then the data itself. This is useful when one wants to load the data built with one Unity version, in a "playback engine" from another Unity version. Think DLC etc.
  2. Without type trees. In most cases this means the data file is built for exact Unity engine version. The code knows how exactly it has serialized data, so no need to emit the "RTTI" info at all. The file is basically a blob of data.

First item is probably done correctly in disunity (haven't looked in detail). It's fairly simple anyway.

@aras-p
aras-p / lambda.cpp
Last active September 24, 2019 02:40
Lambda art
// C++11 lambdas aren't terribly useful at producing art.
// Source below is valid C++11. VS2013 takes about a minute at it (Release config),
// reaches almost 4GB of memory usage and then gives a
//
// 1>ConsoleApplication1.cpp(34): fatal error C1001: An internal error has occurred in the compiler.
// 1> (compiler file 'msc1.cpp', line 1325)
// 1> To work around this problem, try simplifying or changing the program near the locations listed above.
// 1> Please choose the Technical Support command on the Visual C++
// 1> Help menu, or open the Technical Support help file for more information
// 1> This error occurred in injected text:
@aras-p
aras-p / Projector Light.shader
Last active September 9, 2024 14:33
Projector shaders without fixed function
Shader "Projector/Light" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ShadowTex ("Cookie", 2D) = "" {}
_FalloffTex ("FallOff", 2D) = "" {}
}
Subshader {
Pass {
ZWrite Off
// SM3.0+
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile_fwdbase
#include "MyCode.cginc"
ENDCG