fix raymarching depth; add old rm shaders

This commit is contained in:
Crispy 2023-07-23 12:41:47 +02:00
parent 9034d9e2a2
commit 4695be0423
29 changed files with 2242 additions and 7 deletions

92
Assets/test/Demo3.shader Normal file
View file

@ -0,0 +1,92 @@
Shader "Demo/pulsating"
{
Properties
{
[Header(Lighting)]
_SunPos ("Sun position", Vector) = (8, 4, 2)
[Header(Raymarcher Properties)]
_MaxSteps ("Max steps", Int) = 256
_MaxDist ("Max distance", Float) = 256
_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
// #define USE_WORLD_SPACE
#define DYNAMIC_QUALITY
#define USE_REFLECTIONS
// #define CONSTRAIN_TO_MESH
#define MAX_REFLECTIONS 1
#include "RayMarchLib.cginc"
float3 _SunPos;
sdfData gyroid(float3 p, float scale, float bias, material mat = DEFMAT)
{
sdfData o;
o.dist = abs(dot(sin(p * scale), cos(p.zxy * scale))+bias) - 0.2;
o.dist *= .75 / scale;
o.mat = mat;
return o;
}
sdfData scene(float3 p)
{
sdfData o;
material mRed = mat(.12, 0.01, 0.01, sin(_Time*100)*0.1+0.6);
float3 bias = -pow(sin(_Time*60 + p.y*0.1), 8)*.5+1.3;
o = gyroid(p, .5, bias, mRed);
//o = sdfTorus(p, 10 + pow(sin(_Time*50), 4)*5, bias+sin(100*_Time + .1*p.x)*0.5+.5, cRed);
float3 gp = p + sin(_Time + p*0.1);
o.dist -= gyroid(gp, 1.63, .5).dist * 0.3;
o.dist += gyroid(gp, 3.327, 0).dist * 0.1;
o.dist += gyroid(gp, 7.351, .5).dist * 0.1;
o.dist -= gyroid(gp, 17.351, .5).dist * 0.05;
o.dist -= gyroid(gp, 23.521, .2).dist * 0.05;
o = sdfAdd(p, o, sdfSphere(p, 6 + bias*3, mRed), 5);
// o = sdfInter(p, o, sdfSphere(p, 50, mat(0.04, 0.005, 0.035)), 1.1);
o = sdfInter(p, o, sdfBox(p, 20, mRed));
//sdfData bobby = sdfSphere(p, 51, col(0.5, 0.25, 0.001));
//bobby = sdfAdd(p, bobby, sdfSphere(p, 50.5, col(.5,.01,.01)));
//bobby = sdfSub(p, bobby, sdfSphere(p, 50));
//o = sdfAdd(p, o, bobby);
//o = sdfAdd(p, o, sdfPlane(p, -50));
return o;
}
fixed4 lightPoint(rayData ray)
{
float3 vSunDir = normalize(_SunPos);
if (ray.bMissed)
{
return 0.1;
}
fixed4 col = 0;
col = ray.mat.col * lightSun(ray.vNorm, vSunDir, col(5, 2, 0.1));
col += ray.mat.col * lightSky(ray.vNorm, 1);
col *= lightAO(ray.vHit, ray.vNorm, 0.05);
col = pow(col, 0.7);
//col = lightFog(col, col(0.3, .17, 0.001), ray.dist, 0, 48);
return col;
}
ENDCG
}
}
}

View file

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

79
Assets/test/Demo4.shader Normal file
View file

@ -0,0 +1,79 @@
Shader "Demo/Spinny thing"
{
Properties
{
[Header(Lighting)]
_SunPos ("Sun position", Vector) = (8, 4, 2)
[Header(Raymarcher Properties)]
_MaxSteps ("Max steps", Int) = 256
_MaxDist ("Max distance", Float) = 256
_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
#define USE_DYNAMIC_QUALITY
// #define USE_WORLD_SPACE
#define USE_REFLECTIONS
#define MAX_REFLECTIONS 5
#define DISCARD_ON_MISS
//#define CONSTRAIN_TO_MESH
#include "RayMarchLib.cginc"
float3 _SunPos;
sdfData scene(float3 p)
{
sdfData o;
const material mGrass = mat(0.001, 0.1, 0.001, 0.7);
o = sdfPlane(p, 0, mGrass);
material mDirt = mat(0.1, 0.04, 0.01, 1);
o = sdfInter(p, o, sdfSphere(p, 9, mDirt), 0.5);
const material mMetal = mat(0.1, 0);
o = sdfAdd(p, o, sdfSphere(p - V_Y*2, 2, mMetal));
material m = mat(0.05, 0.1, 0.2, 1);
o = sdfAdd(p, o, sdfTorus(rotX(p, _Time* 40+UNITY_PI/2), 5, 0.5, m), 0.5);
o = sdfAdd(p, o, sdfTorus(rotZ(p, _Time* 40+UNITY_PI/2), 5, 0.5, m), 0.5);
o = sdfAdd(p, o, sdfTorus(rotX(p, _Time* 40), 5, 0.5, m), 0.5);
o = sdfAdd(p, o, sdfTorus(rotZ(p, _Time* 40), 5, 0.5, m), 0.5);
o = sdfAdd(p, o, sdfSphere(abs(rotY(p, -20 * _Time)) - float3(1.5,2,1.5), 1, mMetal), 0.2);
return o;
}
fixed4 lightPoint(rayData ray)
{
float3 vSunDir = normalize(_SunPos);
if (ray.bMissed)
{
return sky(ray.vRayDir);
}
fixed4 col = 0;
col = ray.mat.col * lightSun(ray.vNorm, vSunDir);
col *= lightShadow(ray.vHit, vSunDir, 50);
col += ray.mat.col * lightSky(ray.vNorm, 1);
col *= lightAO(ray.vHit, ray.vNorm);
col = pow(col, 0.5);
return col;
}
ENDCG
}
}
}

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -657,6 +657,154 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 124.6, y: -30, z: 0}
--- !u!1 &889393501
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 889393508}
- component: {fileID: 889393507}
- component: {fileID: 889393506}
- component: {fileID: 889393504}
- component: {fileID: 889393503}
- component: {fileID: 889393502}
- component: {fileID: 889393505}
m_Layer: 0
m_Name: Sphere (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &889393502
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 990f6f4efb7f4ec98ad99f6dff1bc6f6, type: 3}
m_Name:
m_EditorClassIdentifier:
type: 3
objectId: 4e7f3dcf-e925-473a-89e2-dfe6cfe7eac5
--- !u!114 &889393503
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a37fd8d654d5c2840a0ab3a5ad65a5ae, type: 3}
m_Name:
m_EditorClassIdentifier:
spawnHeight: 0
useAdditionalValues: 0
syncValues: []
propPrivacy: 1
subSyncs: []
spawnableType: 0
preGeneratedInstanceId:
--- !u!114 &889393504
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12974925555b471580cacf5d2d5fa9e3, type: 3}
m_Name:
m_EditorClassIdentifier:
gripType: 1
gripOrigin: {fileID: 0}
disallowTheft: 0
maximumGrabDistance: 0
snappingReferences: []
autoHold: 0
ikReference: {fileID: 0}
--- !u!65 &889393505
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 20, y: 20, z: 20}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &889393506
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
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: c6c9534ef89e9c77cb3f6307bc66dde4, 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 &889393507
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_Mesh: {fileID: -5495902117074765545, guid: 85702488cb92b9182a44437d143f9fc4, type: 3}
--- !u!4 &889393508
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 889393501}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.6295098, y: 0.42811045, z: 0.014560541}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &927649070
PrefabInstance:
m_ObjectHideFlags: 0

BIN
Assets/test/large_box.fbx Normal file

Binary file not shown.

View file

@ -0,0 +1,97 @@
fileFormatVersion: 2
guid: 85702488cb92b9182a44437d143f9fc4
ModelImporter:
serializedVersion: 19301
internalIDToNameTable: []
externalObjects: {}
materials:
materialImportMode: 1
materialName: 0
materialSearch: 1
materialLocation: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
motionNodeName:
rigImportErrors:
rigImportWarnings:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
importAnimatedCustomProperties: 0
importConstraints: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
extraUserProperties: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
importVisibility: 1
importBlendShapes: 1
importCameras: 1
importLights: 1
fileIdsGeneration: 2
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
keepQuads: 0
weldVertices: 1
preserveHierarchy: 0
skinWeightsMode: 0
maxBonesPerVertex: 4
minBoneWeight: 0.001
meshOptimizationFlags: -1
indexFormat: 0
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 3
normalCalculationMode: 4
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 1
blendShapeNormalImportMode: 1
normalSmoothingSource: 0
referencedClips: []
importAnimation: 1
humanDescription:
serializedVersion: 3
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
globalScale: 1
rootMotionBoneName:
hasTranslationDoF: 0
hasExtraRoot: 0
skeletonHasParents: 1
lastHumanDescriptionAvatarSource: {instanceID: 0}
autoGenerateAvatarMappingIfUnspecified: 1
animationType: 2
humanoidOversampling: 1
avatarSetup: 0
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

81
Assets/test/spinny.mat Normal file
View file

@ -0,0 +1,81 @@
%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: spinny
m_Shader: {fileID: 4800000, guid: 26b714026d4c6e2dc8fefdbcf28344fd, 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
- _MaxDist: 256
- _MaxSteps: 219.31
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SurfDist: 0.001
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SunPos: {r: 8, g: 4, b: 2, a: 1}

View file

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