Created
September 10, 2017 05:02
-
-
Save CharStiles/e152dcc785e060eee72865b9810a25db to your computer and use it in GitHub Desktop.
raymarching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "GlitchRayMarchingNoise" { | |
Properties { | |
_Size ("Size", Vector) = (1,1,1,1) | |
_Height ("Height", Float) = 1 | |
_Rotate ("Rotate", Vector) = (0,0,0,0) | |
[Header(GBuffer)] | |
_MainTex ("Albedo Map", 2D) = "white" {} | |
// _NoiseTex("Noise Texture", 2D) = "white" {} | |
// _BumpTex ("Normal Map", 2D) = "bump" {} | |
_SpecularGloss ("Specular/Gloss", Color) = (0.5,0.5,0.5,0) | |
_Emission ("Emission", Color) = (0,0,0,0) | |
_Glossiness ("Smoothness", Range(0,1)) = 0.5 | |
_Metallic ("Metallic", Range(0,1)) = 0.0 | |
[Header(Framework)] | |
_RayDamp ("Ray Damp", Float) = 1 | |
_LocalOffset ("Local Offset", Vector) = (0,0,0,0) | |
_LocalTangent ("Local Tangent", Vector) = (0.15,1.24,0.89,0) | |
} | |
SubShader { | |
Tags { "RenderType"="Opaque" } | |
LOD 200 | |
CGINCLUDE | |
float4 _Size; | |
float _Height; | |
float4 _Rotate; | |
float _Scale; | |
float _Lacunarity; | |
float _WaterTime; | |
float _Gain; | |
float _NoiseWalk; | |
float _FlipAxis; | |
float _CenterOfMass; | |
#include "RaymarchModules.cginc" | |
#include "noiseSimplex.cginc" | |
float distFunc(float3 p) { | |
p = trScale(p, _Size.xyz / _Size.w); | |
float3 p0 = p; | |
// p = float3(p.x+cos(_WaterTime*_Distance),p.y+sin(_WaterTime*_Distance),p.z); | |
p = trRotate3(p, _Rotate.xyz); | |
float height = _Height*_Scale; | |
// float height = _Height; | |
_Size = float4(_Size.x, _Size.y*_Gain, _Size.z , _Size.w); | |
float d2 = p.y - height + snoise((p * _Lacunarity) + _WaterTime) * _Gain;// this is the sexyness | |
// float d2 = p.y - height + snoise(p * _Gain) * _Lacunarity;// this is the sexyness | |
// float d2 = p.y - height ;// + snoise(p * 0.5) * 2; | |
// this is the sexyness p * (lunericity? smaller the bigger) * amt in variation (grain) | |
// float3 p3 = fBoxFold(fBoxFold(fBoxFold(fBoxFold(fBoxFold(p, 4), 4), 4), 4), 4); | |
// float3 p3 = fBoxFold(p, 1);// this is the amount of smooth box breaks in jelly | |
// float d3 = sdBox(p3, float3(1,10,1)); // size of each box and its depth | |
// d3 = opUni(opSub(d3, d2), p.y - height + 3); // ray marching | |
// float d4 = sdSphere(p0 - float3(0,-2,0), 2); | |
return d2; | |
} | |
float4 normalFunc(float4 buf, float3 p, float d, float i) { | |
float3 cameraPos = _WorldSpaceCameraPos.xyz; | |
float3 ray = normalize(p - cameraPos); | |
float t = (0 - cameraPos.y) / ray.y; | |
float3 surPos = cameraPos + ray * t; | |
if ((cameraPos.y > 0 && ray.y > 0) || (cameraPos.y < 0 && ray.y < 0)) return float4(buf.xyz, 0); | |
if (length(p - cameraPos) < length(surPos - cameraPos)) return float4(buf.xyz, 0); | |
float dist = distFunc(surPos); | |
buf.a = exp(-dist); | |
return buf; | |
} | |
float2 uvFunc(float3 p) { | |
float2 uv = uvFuncQuartz(p); | |
return uv; | |
} | |
#define NORMAL_FUNC normalFunc | |
#define DIST_FUNC distFunc | |
#define UV_FUNC uvFunc | |
#define USE_OBJECTSPACE 0 | |
#define NORMAL_PRECISION 0.01 | |
#define CHECK_CONV_BY_CLIP_THRESHOLD 1 | |
#define USE_CLIP_THRESHOLD 1 | |
#define CLIP_THRESHOLD 0.01 | |
#define RAY_ITERATION 64 //64 // 128 | |
#include "RaymarchCore.cginc" | |
ENDCG | |
Pass { | |
Tags { "LightMode" = "Deferred" } | |
CGPROGRAM | |
#pragma vertex vert_raymarch | |
#pragma fragment frag_raymarch | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a unity shader that makes a really good VR pointer laser