depth feature set aside

This commit is contained in:
spatialfree 2021-12-24 20:40:13 -05:00
parent 802451bafa
commit ef9fb3527d
4 changed files with 94 additions and 140 deletions

View file

@ -1,7 +1,8 @@
#include "stereokit.hlsli" #include "stereokit.hlsli"
//--name = dofdev/oriel // --name = dofdev/oriel
// float4 color; // float4 color;
float _distmax;
float _height; float _height;
float _ypos; float _ypos;
float3 _dimensions; float3 _dimensions;
@ -9,11 +10,13 @@ float3 _center;
Texture2D tex; // : register(t0); Texture2D tex; // : register(t0);
SamplerState tex_s; // : register(s0); SamplerState tex_s; // : register(s0);
cbuffer BufferData : register(b3) { cbuffer BufferData : register(b3) {
float3 position; float3 position;
float windStrength; float time;
}; };
struct vsIn { struct vsIn {
float4 pos : SV_POSITION; float4 pos : SV_POSITION;
float3 norm : NORMAL0; float3 norm : NORMAL0;
@ -46,9 +49,9 @@ psIn vs(vsIn input, uint id : SV_InstanceID) {
o.uv = input.uv; o.uv = input.uv;
o.color = input.col; o.color = input.col;
float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1))); // float lighting = dot(o.norm, normalize(float3(-0.3, 0.6, 0.1)));
lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2; // lighting = (clamp(lighting, 0, 1) * 0.8) + 0.2;
o.color.rgb = o.color.rgb * lighting; // * sk_inst[id].color; // o.color.rgb = o.color.rgb * lighting; // * sk_inst[id].color;
return o; return o;
} }
@ -60,31 +63,6 @@ float dot(float3 a, float3 b) {
return a.x * b.x + a.y * b.y + a.z * b.z; return a.x * b.x + a.y * b.y + a.z * b.z;
} }
// float tri_raycast(float3 origin, float3 dir) {
// float final = -1;
// float3 v0 = tri[0].xyz;
// float3 v1 = tri[1].xyz;
// float3 v2 = tri[2].xyz;
// float3 e1 = v1 - v0;
// float3 e2 = v2 - v0;
// float3 h = cross(dir, e2);
// float a = dot(e1, h);
// if (a > -0.00001 && a < 0.00001) {} else{
// float f = 1 / a;
// float3 s = origin - v0;
// float u = f * dot(s, h);
// if (u < 0.0 || u > 1.0) {} else {
// float3 q = cross(s, e1);
// float v = f * dot(dir, q);
// if (v < 0.0 || u + v > 1.0) {} else {
// float t = f * dot(e2, q);
// if (t > 0.00001) { final = 1.0;} // t
// }
// }
// }
// return final;
// }
float sdSphere(float3 p, float s) { float sdSphere(float3 p, float s) {
return length(p) - s; return length(p) - s;
} }
@ -116,30 +94,47 @@ float sdBoxFrame(float3 p, float3 b, float e) {
); );
} }
float opRep(float3 p, float3 c) float oriel(float3 ro, float3 rd) {
{ float dist = 0.0;
float3 q = modf(p + 0.5 * c, c) - 0.5 * c; for (int i = 0; i < 256; i++) {
return sdSphere(q, 0.1); float3 pos = ro + dist * rd;
float step = sdBox(pos - _center, _dimensions / 2);
if (step < 0.0001 || dist > _distmax) break;
dist += step;
}
return dist;
} }
float map(float3 pos) { float map(float3 pos) {
// pos.x = _center.x + pos.x; // pos.x = _center.x + pos.x;
// pos.y = _center.y + pos.y; // pos.y = _center.y + pos.y;
// pos.z = _center.z - pos.z; // pos.z = _center.z - pos.z;
float sphere = sdSphere(pos + float3(0, 0, -1) - _center, 0.1); float3 spin = float3(sin(time), 0, cos(time)) * 0.5;
float sphere = sdSphere(pos + spin - _center, 0.1);
// return sdLink(pos, 0.1, 0.1, 0.1); // return sdLink(pos, 0.1, 0.1, 0.1);
// float octo = sdOctahedron(pos - _center - position, 0.2); // float octo = sdOctahedron(pos - _center - position, 0.2);
float frame = sdBoxFrame(pos - _center - position, float3(0.06, 0.06, 0.06), 0.004); float frame = sdBoxFrame(pos - _center - position, float3(0.06, 0.06, 0.06), 0.004);
float orielFrame = sdBoxFrame(pos - _center, _dimensions / 2, 0.004); float orielFrame = sdBoxFrame(pos - _center, _dimensions / 2, 0.001);
// return lerp(sphere, octo, windStrength); // float box = sdBox(pos - _center, _dimensions / 2.1);
// return lerp(sphere, octo, time);
float plane = sdPlane(pos - _center + float3(0, 0.5, 0), float3(0, 1, 0), 0); float plane = sdPlane(pos - _center + float3(0, 0.5, 0), float3(0, 1, 0), 0);
// float blendd = lerp(octo, frame, windStrength); // float blendd = lerp(octo, frame, time);
// return min(min(plane, orielFrame), frame);
return min(min(plane, orielFrame), sphere); return min(min(plane, orielFrame), sphere);
}
float raymarch(float3 ro, float3 rd) {
float dist = 0.0;
for (int i = 0; i < 256; i++) {
float3 pos = ro + dist * rd;
float step = map(pos);
if (step < 0.0001 || dist > _distmax) break;
dist += step;
}
// return opRep(pos - _center, float3(0, 0, 0)); return dist;
} }
float3 calcNormal(float3 pos) float3 calcNormal(float3 pos)
@ -172,76 +167,28 @@ float calcShadow(float3 pos, float3 light) {
float3 rd = normalize(light - pos); float3 rd = normalize(light - pos);
float3 ro = pos + rd * 0.1; float3 ro = pos + rd * 0.1;
float tmax = 100; float dist = raymarch(ro, rd);
float t = 0.0; return (float)(dist > _distmax);
for (int i = 0; i < 256; i++) {
float3 pos = ro + t * rd;
float h = map(pos);
if (h < 0.0001 || t > tmax) break;
t += h;
}
if (t < tmax) {
t = 0;
} else {
t = 1;
}
return t;
} }
float calcSoftshadow(in float3 ro, in float3 rd, in float mint, in float tmax, in float k) {
// bounding volume
float tp = (0.8-ro.y)/rd.y; if( tp>0.0 ) tmax = min( tmax, tp );
float res = 1.0;
float t = mint;
for( int i=0; i<24; i++ ) {
float h = map( ro + rd*t ).x;
float s = clamp(8.0*h/t,0.0,1.0);
res = min( res, k*s*s*(3.0-2.0*s) );
t += clamp( h, 0.02, 0.2 );
if( res<0.004 || t>tmax ) break;
}
return clamp( res, 0.0, 1.0 );
}
// float RayMarch(vec3 ro, vec3 rd) {
// float dO=0.;
// for(int i=0; i<MAX_STEPS; i++) {
// vec3 p = ro + rd*dO;
// float dS = GetDist(p);
// dO += dS;
// if(dO>MAX_DIST || dS<SURF_DIST) break;
// }
// return dO;
// }
psOut ps(psIn input) { psOut ps(psIn input) {
psOut result; psOut result;
result.depth = input.pos.z; result.depth = input.pos.z;
float3 worldIntersection;
float3 ro = input.campos; // ray origin float3 ro = input.campos; // ray origin
float3 rd = normalize(input.world - ro); // ray direction float3 rd = normalize(input.world - ro); // ray direction
// input.color = float4(float3(1,1,1) * max(tri_raycast(input.world, ray), 0.0), 1); float oriel = oriel(ro, rd);
ro += oriel * rd;
// raymarch float dist = raymarch(ro, rd);
float tmax = 100; // float dist = raymarch(ro, rd);
float t = 0.0;
for (int i = 0; i < 256; i++) {
float3 pos = ro + t * rd;
float h = map(pos);
if (h < 0.0001 || t > tmax) break;
t += h;
}
// shading/lighting // shading/lighting
float3 col = float3(0.5, 0.75, 0.9); float3 col = float3(0.5, 0.75, 0.9);
if (t < tmax) { if (dist == 0.0) {
float3 pos = ro + (t * rd); col = float3(0.15, 0.15, 0.15);
}
if (dist < _distmax && dist > 0.0) {
float3 pos = ro + dist * rd;
float3 light = float3(0.0, 1.0, 0.0); float3 light = float3(0.0, 1.0, 0.0);
float3 lightDir = normalize(light - pos); float3 lightDir = normalize(light - pos);
float3 nor = calcNormal(pos); float3 nor = calcNormal(pos);
@ -249,48 +196,26 @@ psOut ps(psIn input) {
float amb = 0.5 + 0.5 * dot(nor, lightDir); float amb = 0.5 + 0.5 * dot(nor, lightDir);
float ao = calcAO(pos, nor); float ao = calcAO(pos, nor);
float sh = calcShadow(pos, light); float sh = calcShadow(pos, light);
// float sh = calcSoftshadow(pos, light, 0.02, 2.5, 32);
dif *= ao * sh; dif *= ao * sh;
col = float3(0.1, 0.5, 0.3) * amb + float3(0.6, 0.8, 0.3) * dif; col = float3(0.1, 0.5, 0.3) * amb + float3(0.6, 0.8, 0.3) * dif;
// float3 lightPos = float3(0, 3, 0); // if (sdBox(pos - _center, _dimensions / 2) == 0.0) {
// float3 rayo = pos; // float4 clipPos = mul(float4(pos, 1), sk_viewproj[input.view_id]);
// float3 rayd = normalize(lightPos - pos); // float near = 0.0;
// float ttmax = 6.0; // float far = _distmax;
// float tt = 0.0; // float a = (far + near) / (far - near);
// for (int i = 0; i < 256; i++) { // float b = 2.0 * far * near / (far - near);
// float3 pp = rayo + tt * rayd; // result.depth = a + b / clipPos.z;
// float hh = map(pp); // // result.depth = clipPos.z;
// if (hh < 0.0001 || tt > tmax) break;
// tt += hh;
// } // }
// if (tt < length(lightPos - rayo)) {
// col *= 0.5;
// }
if(sdBox(pos - _center, _dimensions / 2) <= 0.005) {
float4 clipPos = mul(float4(pos, 1), sk_viewproj[input.view_id]);
// o.pos = mul(float4(o.world, 1), sk_viewproj[o.view_id]);
result.depth = clipPos.z;
// float4 viewWorldPos = mul(float4(pos, 1), sk_view[input.view_id]);
// float near = 0.05;
// float far = 100;
// float a = (far+near)/(far-near);
// float b = 2.0*far*near/(far-near);
// result.depth = a + b/viewWorldPos.z;
}
} }
// input.color = float4(float3(1,1,1) * max(t, 0.0), 1); // input.color = float4(col, 1);
input.color = float4(col, 1);
// if (input.world.x > 0.0) {
// input.color = float4(float3(1,1,1) * sdSphere(input.uv, float2(0.2, 0.2), float2(0.8, 0.8)), 1); // col = float3(1 - col.r, 1 - col.g, 1 - col.b);
// input.color.r = rr; // }
result.color = input.color; result.color = float4(col, 1);
// float4x4 worldToViewMatrix = sk_view[input.view_id]; // float4x4 worldToViewMatrix = sk_view[input.view_id];
// float4 viewIntersectionPos = worldToViewMatrix * float4(worldIntersection, 1.0); // float4 viewIntersectionPos = worldToViewMatrix * float4(worldIntersection, 1.0);
@ -301,9 +226,10 @@ psOut ps(psIn input) {
// result.depth = (-viewIntersectionPos.z - n) / (f - n) * viewIntersectionPos.w; // result.depth = (-viewIntersectionPos.z - n) / (f - n) * viewIntersectionPos.w;
// worldIntersection = float3(0.0); // worldIntersection = float3(0.0);
///input.pos.w; // input.pos.w;
// result.depth = zc/wc; // result.depth = zc/wc;
// result.color.rgb = float3(zc/wc); // result.color.rgb = float3(zc/wc);
return result; return result;
} }

View file

@ -26,6 +26,8 @@ class MonoNet {
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
string ip = "192.168.1.70"; string ip = "192.168.1.70";
ip = "139.177.201.219"; ip = "139.177.201.219";
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234); EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234);
socket.Connect(serverEndPoint); socket.Connect(serverEndPoint);
rData = new byte[bufferSize]; rData = new byte[bufferSize];

View file

@ -28,7 +28,8 @@ public class Monolith {
Mesh cube = Default.MeshCube; Mesh cube = Default.MeshCube;
public void Run() { public void Run() {
Renderer.SetClip(0.05f, 10f); Renderer.SetClip(0.0f, 1000f);
// Renderer.
// mic = new Mic(); // mic = new Mic();
Vec3 pos = new Vec3(0, 0, 0); Vec3 pos = new Vec3(0, 0, 0);
Vec3 vel = new Vec3(0, 0, 0); Vec3 vel = new Vec3(0, 0, 0);
@ -127,6 +128,28 @@ public class Monolith {
// subPlanted = !subPlanted; // subPlanted = !subPlanted;
// } // }
// there is a lot of stuff in this class that needs to move out
// as we need to make way for an oriel game, for god's sake
// start with the largest and work our way down
// is there someway to package these systems in a sensible way
// there is something about a player here... though that may be to general...
// don't crash if server isn't up
// its not tho...
if (rCon.stick.Magnitude > 0.1f) { if (rCon.stick.Magnitude > 0.1f) {
if (rCon.stick.y < 0f) { if (rCon.stick.y < 0f) {
rightPlanted = true; rightPlanted = true;

View file

@ -6,7 +6,7 @@ using StereoKit;
struct BufferData { struct BufferData {
public Vec3 position; public Vec3 position;
// public Vec3[] tri; // public Vec3[] tri;
public float windStrength; public float time;
} }
public class Oriel { public class Oriel {
@ -37,7 +37,7 @@ public class Oriel {
// new Vec3(1, 0, 0), // new Vec3(1, 0, 0),
// }; // };
data.windStrength = (1 + (float)Math.Sin(Time.Total)) / 2; data.time = (float)Time.Total;
buffer.Set(data); buffer.Set(data);
@ -47,7 +47,10 @@ public class Oriel {
mat.FaceCull = Cull.Front; mat.FaceCull = Cull.Front;
// mat.QueueOffset = -1; mat.DepthTest = DepthTest.Always;
mat.QueueOffset = 1000;
mat.SetFloat("_distmax", 1000);
mat.SetVector("_dimensions", bounds.dimensions); mat.SetVector("_dimensions", bounds.dimensions);
mat.SetVector("_center", bounds.center); mat.SetVector("_center", bounds.center);
// mat.Wireframe = true; // mat.Wireframe = true;