diff --git a/Assets/raymarched/Raymarching.unity b/Assets/raymarched/Raymarching.unity index 177d9cb..c468f39 100644 --- a/Assets/raymarched/Raymarching.unity +++ b/Assets/raymarched/Raymarching.unity @@ -121,6 +121,98 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &695617482 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 695617484} + - component: {fileID: 695617483} + m_Layer: 0 + m_Name: Point Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &695617483 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 695617482} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 2 + m_Shape: 0 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &695617484 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 695617482} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.464, y: -0.099, z: 0.326} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &845829380 GameObject: m_ObjectHideFlags: 0 @@ -213,6 +305,85 @@ 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 @@ -299,9 +470,9 @@ Light: serializedVersion: 10 m_Type: 2 m_Shape: 0 - m_Color: {r: 1, g: 1, b: 1, a: 0} + m_Color: {r: 0, g: 0, b: 1, a: 0} m_Intensity: 1 - m_Range: 10 + m_Range: 2 m_SpotAngle: 30 m_InnerSpotAngle: 21.80208 m_CookieSize: 10 @@ -357,7 +528,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1450495540} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.769, y: -0.886, z: -0.762} + m_LocalPosition: {x: 0.844, y: -0.907, z: 0.117} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -383,7 +554,7 @@ MeshFilter: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1450495540} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} + m_Mesh: {fileID: 4393975565123819156, guid: df3c2875c26809684829ae8983ab0a53, type: 3} --- !u!23 &1450495548 MeshRenderer: m_ObjectHideFlags: 0 @@ -510,7 +681,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1485771011} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.695, y: -0.723, z: -0.01} + m_LocalPosition: {x: -0.452, y: 0.221, z: -0.124} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -732,7 +903,7 @@ MeshFilter: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1651833084} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} + m_Mesh: {fileID: 4393975565123819156, guid: df3c2875c26809684829ae8983ab0a53, type: 3} --- !u!4 &1651833091 Transform: m_ObjectHideFlags: 0 @@ -741,7 +912,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1651833084} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.757, z: 0} + m_LocalPosition: {x: 0.265, y: -0.757, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} diff --git a/Assets/raymarched/raymarch_origin.shader b/Assets/raymarched/raymarch_origin.shader index 5634caa..3306993 100644 --- a/Assets/raymarched/raymarch_origin.shader +++ b/Assets/raymarched/raymarch_origin.shader @@ -12,9 +12,31 @@ Tags { "RenderType"="Opaque" } Cull Off LOD 100 + Pass + { + // TODO: does this even do anything? its supposed to be on by default + ZWrite On + CGPROGRAM + #pragma vertex vertex + #pragma fragment fragment + + #define BASE_PASS + #include "raymarcher.cginc" + + v2f vertex (appdata v){ + return vert(v); + } + + fragOut fragment (v2f i) { + return frag(i); + } + ENDCG + } + Pass { Tags { "LightMode" = "ForwardAdd"} + ZWrite On CGPROGRAM #pragma vertex vertex #pragma fragment fragment diff --git a/Assets/raymarched/raymarch_secondary.shader b/Assets/raymarched/raymarch_secondary.shader index caaf9cc..e5648aa 100644 --- a/Assets/raymarched/raymarch_secondary.shader +++ b/Assets/raymarched/raymarch_secondary.shader @@ -27,6 +27,9 @@ fragOut fragment (v2f i) { return frag(i); + // fragOut o = frag(i); + // o.col = 0.4f; + // return o; } ENDCG } diff --git a/Assets/raymarched/raymarcher.cginc b/Assets/raymarched/raymarcher.cginc index 01f6e38..26fe127 100644 --- a/Assets/raymarched/raymarcher.cginc +++ b/Assets/raymarched/raymarcher.cginc @@ -5,6 +5,7 @@ define IS_SECONDARY_SHAPE to only render the second shape */ #include "UnityCG.cginc" +#include "UnityLightingCommon.cginc" struct appdata { @@ -107,12 +108,16 @@ float SecondShape(float3 p) { float GetDist(float3 p) { #ifdef IS_SECONDARY_SHAPE return SecondShape(p); +#else +#ifdef BASE_PASS + return FirstShape(p); #else float first = FirstShape(p); float3 second_pos = mul(unity_WorldToObject, _WorldSpaceLightPos0); float second = SecondShape(p - second_pos); return smin(first, second, 0.15f); #endif +#endif } //marches a ray through the scene @@ -143,6 +148,14 @@ float3 GetNormal(float3 p) { } fragOut frag (v2f i) { +#ifndef IS_SECONDARY_SHAPE +#ifndef BASE_PASS + if (length(_LightColor0 - float4(0,0,1,0)) > 0.01f ){ + discard; + } +#endif +#endif + float3 ro = i.ro; float3 rd = normalize(i.hitPos - ro); @@ -162,6 +175,7 @@ fragOut frag (v2f i) { // col *= float4(d, 1, 1, 1); fragOut o; o.col = col; + // o.col = _LightColor0; float4 vClipPos = mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, float4(p, 1))); o.depth = (vClipPos.z / vClipPos.w + 1.0) * 0.5; return o; diff --git a/Assets/raymarched/sphere_1m.fbx b/Assets/raymarched/sphere_1m.fbx new file mode 100644 index 0000000..615b703 Binary files /dev/null and b/Assets/raymarched/sphere_1m.fbx differ diff --git a/Assets/raymarched/sphere_1m.fbx.meta b/Assets/raymarched/sphere_1m.fbx.meta new file mode 100644 index 0000000..220975d --- /dev/null +++ b/Assets/raymarched/sphere_1m.fbx.meta @@ -0,0 +1,97 @@ +fileFormatVersion: 2 +guid: df3c2875c26809684829ae8983ab0a53 +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: diff --git a/Assets/raymarched/surf_t.shader b/Assets/raymarched/surf_t.shader new file mode 100644 index 0000000..e1c1929 --- /dev/null +++ b/Assets/raymarched/surf_t.shader @@ -0,0 +1,54 @@ +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" +} diff --git a/Assets/raymarched/surf_t.shader.meta b/Assets/raymarched/surf_t.shader.meta new file mode 100644 index 0000000..b9361a8 --- /dev/null +++ b/Assets/raymarched/surf_t.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f87aed02a2188c4f98cee590c5bfb06b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/tes.shader b/Assets/raymarched/tes.shader new file mode 100644 index 0000000..61138a2 --- /dev/null +++ b/Assets/raymarched/tes.shader @@ -0,0 +1,89 @@ +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 + } + } +} diff --git a/Assets/raymarched/tes.shader.meta b/Assets/raymarched/tes.shader.meta new file mode 100644 index 0000000..eaf7857 --- /dev/null +++ b/Assets/raymarched/tes.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6be601fdc9efee139829a555e35180f0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/raymarched/test.mat b/Assets/raymarched/test.mat new file mode 100644 index 0000000..fc65447 --- /dev/null +++ b/Assets/raymarched/test.mat @@ -0,0 +1,77 @@ +%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} diff --git a/Assets/raymarched/test.mat.meta b/Assets/raymarched/test.mat.meta new file mode 100644 index 0000000..837d9fa --- /dev/null +++ b/Assets/raymarched/test.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c17c9048a4216420cad3de8ca5a67eeb +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: