Compare commits

...

2 commits

Author SHA1 Message Date
57d07d2258 Raymarcher cleanup 2023-07-22 23:48:05 +02:00
08bb09a5da cleanup 2023-07-22 23:32:01 +02:00
14 changed files with 8 additions and 533 deletions

View file

@ -64,7 +64,7 @@ Material:
- _Glossiness: 0.5
- _GlossyReflections: 1
- _MaxDist: 100
- _MaxSteps: 256
- _MaxSteps: 128
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
@ -72,7 +72,7 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SurfDist: 0.001
- _SurfDist: 0.01
- _UVSec: 0
- _ZWrite: 1
m_Colors:

View file

@ -64,7 +64,7 @@ Material:
- _Glossiness: 0.5
- _GlossyReflections: 1
- _MaxDist: 100
- _MaxSteps: 256
- _MaxSteps: 128
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
@ -72,7 +72,7 @@ Material:
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SurfDist: 0.001
- _SurfDist: 0.01
- _UVSec: 0
- _ZWrite: 1
m_Colors:

View file

@ -305,85 +305,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 124.6, y: -30, z: 0}
--- !u!1 &1059347476
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1059347479}
- component: {fileID: 1059347478}
- component: {fileID: 1059347477}
m_Layer: 0
m_Name: Cylinder
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &1059347477
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1059347476}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: c17c9048a4216420cad3de8ca5a67eeb, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1059347478
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1059347476}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1059347479
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1059347476}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.244, y: -0.008, z: 0.638}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1450495540
GameObject:
m_ObjectHideFlags: 0

View file

@ -1,192 +0,0 @@
Shader "CrispyPin/Raymarch1"
{
Properties
{
[Header(Raymarcher Properties)]
_MaxSteps ("Max steps", Int) = 256
_MaxDist ("Max distance", Float) = 100
_SurfDist ("Surface distance threshold", Range(0.00001, 0.05)) = 0.001
}
SubShader
{
Tags { "RenderType"="Opaque" }
Cull Off
LOD 100
/* Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 ro : TEXCOORD1;
float3 hitPos : TEXCOORD2;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
//object space
o.ro = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1));
o.hitPos = v.vertex;
//world space
//o.ro = _WorldSpaceCameraPos;
//o.hitPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
discard;
return fixed4(0,0,0,0);
}
ENDCG
} */
Pass
{
Name "AddPass"
Tags { "LightMode" = "ForwardAdd"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 ro : TEXCOORD1;
float3 hitPos : TEXCOORD2;
};
int _MaxSteps;
float _MaxDist;
float _SurfDist;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
//object space
o.ro = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1));
o.hitPos = v.vertex;
//world space
//o.ro = _WorldSpaceCameraPos;
//o.hitPos = mul(unity_ObjectToWorld, v.vertex);
return o;
}
float smoothMin(float a, float b, float k)
{
return min(a, b) - pow(max(k - abs(a-b), 0), 3)/(6*k*k);
}
float sdSphere(float3 p, float3 o, float r) {
return length(p - o) - r;
}
float sdBox(float3 p, float3 dim)
{
return length(float3(
max(abs(p.x) - dim.x/2.0, 0),
max(abs(p.y) - dim.y/2.0, 0),
max(abs(p.z) - dim.z/2.0, 0)));
}
float3 repDomain(float3 p, float3 r)
{
return fmod(abs(p + r/2.0), r) - r/2.0;
}
float GetDist(float3 p)
{
/* float d = 0;
float s = sin(100*_Time + p.x*10) * 0.02 + 0.028;
float s2 = cos(105*_Time + p.x*10) * 0.02 + 0.028;
//s += sin(p.x/10)*0.03;
float3 rep = repDomain(p, float3(0.026, 0.15, 0.2));// fmod(abs(p + 0.05), 0.1)-0.05;
d = sdBox(rep, float3(0.02, s2, s)) - 0.004;
d = smoothMin(d, sdBox(rep, float3(0.01, s*1.0, s2*1.5)) - 0.004, 0.01);
*/
float d = sdSphere(p, 0, 0.1f);
// float3 second = ObjSpaceLightDir(0);
// float3 second = _WorldSpaceLightPos0;
float3 second = mul(unity_WorldToObject, _WorldSpaceLightPos0);
d = smoothMin(d, sdBox(p-second, 0.3f), 0.2);
//d = smoothMin(d, sdSphere(p, float3(0,0,0), 5), .3);
return d;
}
//marches a ray through the scene
float Raymarch(float3 ro, float3 rd)
{
float rayLen = 0;// total distance marched / distance from origin
float dist; // distance from the raymarched scene
for ( int i = 0; i < _MaxSteps; i++)
{
//position = origin + distance * direction
float3 p = ro + rayLen * rd;
dist = GetDist(p);
rayLen += dist;// move forward
if (dist < _SurfDist || rayLen > _MaxDist) {
break;
}
}
return rayLen;
}
float3 GetNormal(float3 p)
{
float2 e = float2(0.001, 0);
float3 n = GetDist(p) - float3(
GetDist(p-e.xyy),
GetDist(p-e.yxy),
GetDist(p-e.yyx));
return normalize(n);
}
fixed4 frag (v2f i) : SV_Target
{
float3 ro = i.ro;
float3 rd = normalize(i.hitPos - ro);
float d = Raymarch(ro, rd);
fixed4 col = 1;
if (d >= _MaxDist)
{
discard;
}
float3 p = ro + rd * d;
float3 n = GetNormal(p);
col.rgb = dot(n, normalize(float3(1,0.5,1)));
col *= float4(d, 1, 1, 1);
return col;
}
ENDCG
}
}
}

View file

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: f9118b166a8a02f3a8984624e2611e6c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,4 +1,4 @@
Shader "CrispyPin/Raymarch1"
Shader "CrispyPin/RaymarchOrigin"
{
Properties
{

View file

@ -170,7 +170,8 @@ fragOut frag (v2f i) {
float3 n = GetNormal(p);
// col.rgb = max(dot(n, normalize(float3(1,0.5,1))), 0.05f);
col.r = dot(-rd, n);
col.rgb = lerp(0, float3(0,1,1), pow(1 - dot(-rd, n), 2));
// col *= float4(d, 1, 1, 1);
fragOut o;

View file

@ -1,54 +0,0 @@
Shader "Custom/surf_t"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
// o.Depth += 0.1;
}
ENDCG
}
FallBack "Diffuse"
}

View file

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: f87aed02a2188c4f98cee590c5bfb06b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,89 +0,0 @@
Shader "Unlit/tes"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
ZWrite On
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
// UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float3 ro : TEXCOORD1;
float3 vert_obspace : TEXCOORD2;
};
struct fragOut
{
fixed4 col : SV_Target;
float depth : SV_Depth;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.vert_obspace = v.vertex;
o.ro = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1));
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
// UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fragOut frag (v2f i)
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
// UNITY_APPLY_FOG(i.fogCoord, col);
fragOut o;
// o.col = _Color*0.5;
o.col.a=1;
// o.depth = 1;
float3 rd = normalize(i.vert_obspace - i.ro);
float d = 0;//-0.1;
float4 vClipPos = mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, i.vert_obspace));
// o.depth = (vClipPos.z / vClipPos.w + 1.0) * 0.5 ;
// o.col.r = o.depth;
// o.col.gb = i.ro;
return o;
}
ENDCG
}
}
}

View file

@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 6be601fdc9efee139829a555e35180f0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,77 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: test
m_Shader: {fileID: 4800000, guid: 6be601fdc9efee139829a555e35180f0, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0.5330188, b: 0.6564782, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: c17c9048a4216420cad3de8ca5a67eeb
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = { version = "0.24.6", default_features = false, features = ["png"] }
image = { version = "0.24.6", features = ["png"], default-features = false }