This repo contains common code that I keep using over and over in Unity shaders.
It is designed to be pulled into other projects as a git submodule.
Examples of usage can be found here.
From Unity's Package Manager pane, click the plus sign and choose "Add package from git URL..."
Enter the following URL:
https://github.com/ephemeral-laboratories/HakanaiShaderCommons.git#vX.Y.Z
Replace X.Y.Z with the version you want to use, hopefully the latest.
Usage in Unity:
- Assets→Create→Shader→EL Raycast Shader, Assets→Create→Shader→EL Raymarch Shader menu items will create a new shader of the respective type from a basic template.
- Right-click your new shader, Create→Material
- File→New Scene
- GameObject→3D Object→Cube
- Assign your material to the cube
- You should now see a sphere. Edit your shader to make something more interesting. :)
Functions are generally prefixed with EL
to avoid any future clashes
with Unity function names or other people's utilities.
Functions have been grouped into files roughly by theme.
Filling in utility methods which could be provided by Unity but seemingly weren't, or just generally enhancing quality of life:
ELMathUtilities.cginc
- general matrix utilities.ELUnityUtilities.cginc
- utilities using Unity transforms.ELScuttledUnityLighting.cginc
- Wrappers around annoying Unity macros and generated surface shader code to allow them to be used as normal functions.
Libraries of generally useful stuff:
ELDistanceFunctions.cginc
- distance functions scuttled from various places where if you do any shader stuff at all you can probably guess.ELIntersectionFunctions.cginc
- exact ray intersection functions.
Framework for writing raycast shaders without duplicating code:
ELRaycastBase.cginc
- defines vertex shaderELRaycastBaseVertex
, and fragment shadersELFragmentRaycast
andELRaycastShadowCasterFragment
; declares functionsELRaycast
andELDecodeMaterial
which the user implements to define how the ray hits the surface, and the properties of the material where it hit.ELRaycastBaseInputOutput.cginc
- input and output structures for the raycaster.ELRaycastBaseRays.cginc
- ray structure and common functions thereon.
Framework for writing raymarch shaders without duplicating code:
ELRaymarchCommon.cginc
- declares functionsELMap
andELBoundingBox
which the user implements to define a raymarched object.ELRaymarchBase.cginc
- defines functionELRaycast
to perform a raymarch.
And this outlier:
ELGeometry.cginc
- not much at present, just a geometry shader for making a cube from two verts. (How to get an avatar down to zero polygons.)