Dom fixed depth rendering! (Changed unity color space to Gamma)

This commit is contained in:
buncccc 2025-04-16 16:05:53 +12:00
parent 23b2e78356
commit 054ae366fd
7 changed files with 162 additions and 22 deletions

View File

@ -14,20 +14,33 @@ Shader "Custom/DepthOnly"
{ {
float4 pos : SV_POSITION; float4 pos : SV_POSITION;
float depth : TEXCOORD0; float depth : TEXCOORD0;
float4 pos2 : TEXCOORD2;
}; };
v2f vert(appdata_base v) v2f vert(appdata_base v)
{ {
v2f o; v2f o;
o.pos = UnityObjectToClipPos(v.vertex); o.pos = UnityObjectToClipPos(v.vertex);
o.depth = o.pos.z / o.pos.w; // o.depth = (o.pos.z + 1.) / 2. / o.pos.w;
// o.depth = (o.pos.z + 1.) / 2.;
o.depth = o.pos.z;
// o.depth = o.pos.z/ o.pos.w ;
//o.depth = mul(UNITY_MATRIX_M, v.vertex).x;
// o.pos2 = o.pos;
return o; return o;
} }
fixed4 frag(v2f i) : SV_Target fixed4 frag(v2f i) : SV_Target
{ {
// ****We had to change Unity's color space to Gamma such that it doesn't add its own gamma correction,
// for this to work *******
return fixed4(i.depth, i.depth, i.depth, 1.0);
// Output depth as grayscale // Output depth as grayscale
return fixed4((i.depth / 2), (i.depth / 2), (i.depth / 2), 1.0); // return fixed4((i.depth), (i.depth), (i.depth), 1.0);
// return fixed4(
// (i.pos2.x) * .5 + .5,
// (i.pos2.x) * .5 + .5,
// (i.pos2.x) * .5 + .5, 1.0);
} }
ENDCG ENDCG
} }

View File

@ -38,6 +38,10 @@ public class RT3script : MonoBehaviour
depthImages = new RenderTexture[cameraList.Length]; depthImages = new RenderTexture[cameraList.Length];
depthCameraList = new Camera[cameraList.Length]; depthCameraList = new Camera[cameraList.Length];
// Matrix4x4 ort = Matrix4x4.Ortho(-2, 2, -2, 2, 0, 10);
// UnityEngine.Debug.Log(ort.ToString());
Matrix4x4 testTranslate = Matrix4x4.Translate(new Vector3(0, 0, 2)); Matrix4x4 testTranslate = Matrix4x4.Translate(new Vector3(0, 0, 2));
// UnityEngine.Debug.Log(testTranslate.ToString()); // UnityEngine.Debug.Log(testTranslate.ToString());
@ -110,6 +114,10 @@ public class RT3script : MonoBehaviour
rowOffset = encodeMatrix(cameraList[i].cameraToWorldMatrix, i, rowOffset); rowOffset = encodeMatrix(cameraList[i].cameraToWorldMatrix, i, rowOffset);
rowOffset = encodeMatrix(cameraList[i].projectionMatrix, i, rowOffset); rowOffset = encodeMatrix(cameraList[i].projectionMatrix, i, rowOffset);
// if (i == 0) {
// UnityEngine.Debug.Log(cameraList[0].projectionMatrix.ToString());
// }
// encodeData(rowOffset, i, rowOffset); // encodeData(rowOffset, i, rowOffset);
//encode into pixels transform matrix for this camera //encode into pixels transform matrix for this camera

View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994} m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -213,14 +213,14 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 91574286} m_GameObject: {fileID: 91574286}
m_LocalRotation: {x: -0.028943438, y: -0.7065142, z: 0.7065142, w: -0.028943438} m_LocalRotation: {x: 0, y: -0.38268343, z: 0, w: 0.92387956}
m_LocalPosition: {x: -0.0031539078, y: 0, z: 0.076987565} m_LocalPosition: {x: 0, y: 0, z: 1}
m_LocalScale: {x: 2.2267053, y: 2.2267056, z: 2.226706} m_LocalScale: {x: 3, y: 3, z: 3}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 1871562477} m_Father: {fileID: 0}
m_RootOrder: 12 m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: -45, z: 0}
--- !u!1 &103678967 --- !u!1 &103678967
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -620,11 +620,11 @@ PrefabInstance:
m_Modifications: m_Modifications:
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3} - target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 9 value: 10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3} - target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 0 value: 0.02
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3} - target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
@ -632,7 +632,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3} - target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 0 value: 0.245
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3} - target: {fileID: 3277633862007588681, guid: d59516398c7be0643b8b0658abc4c8c6, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
@ -845,10 +845,10 @@ Camera:
width: 1 width: 1
height: 1 height: 1
near clip plane: 0 near clip plane: 0
far clip plane: 1 far clip plane: 2
field of view: 60 field of view: 60
orthographic: 1 orthographic: 1
orthographic size: 2 orthographic size: 1
m_Depth: -1 m_Depth: -1
m_CullingMask: m_CullingMask:
serializedVersion: 2 serializedVersion: 2
@ -872,7 +872,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225} m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -1} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
@ -891,6 +891,104 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a42175a861c72054982b102c884dd2a6, type: 3} m_Script: {fileID: 11500000, guid: a42175a861c72054982b102c884dd2a6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1 &1272761324
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1272761325}
- component: {fileID: 1272761328}
- component: {fileID: 1272761327}
- component: {fileID: 1272761326}
m_Layer: 0
m_Name: Quad (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1272761325
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272761324}
m_LocalRotation: {x: -0.028943438, y: -0.7065142, z: 0.7065142, w: -0.028943438}
m_LocalPosition: {x: -0.0031539074, y: 0, z: 0.07698757}
m_LocalScale: {x: 2.2267053, y: 2.2267058, z: 2.2267063}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1871562477}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!64 &1272761326
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272761324}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1272761327
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272761324}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8786b1b5c83353f47bd31d02c0fef4e8, 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
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1272761328
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272761324}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1332006756 --- !u!1 &1332006756
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -20,7 +20,7 @@ varying float paintfordiscard;
mat4 unity_to_opengl(mat4 U) { mat4 unity_to_opengl(mat4 U) {
return mat4( return mat4(
1., 0., 0., 0., 1., 0., 0., 0.,
0., 1., 0., 0., 0., 1., 0., 0.,
0., 0.,-1., 0., 0., 0.,-1., 0.,
0., 0., 0., 1. 0., 0., 0., 1.

View File

@ -8,15 +8,17 @@ Material:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_Name: screen material m_Name: screen material
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_ValidKeywords: [] m_ValidKeywords:
- _EMISSION
m_InvalidKeywords: [] m_InvalidKeywords: []
m_LightmapFlags: 4 m_LightmapFlags: 0
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: -1 m_CustomRenderQueue: -1
stringTagMap: {} stringTagMap: {}
disabledShaderPasses: [] disabledShaderPasses:
- GRABPASS
m_SavedProperties: m_SavedProperties:
serializedVersion: 3 serializedVersion: 3
m_TexEnvs: m_TexEnvs:
@ -58,23 +60,42 @@ Material:
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
m_Ints: [] m_Ints: []
m_Floats: m_Floats:
- _BlendOp: 0
- _BumpScale: 1 - _BumpScale: 1
- _CameraFadingEnabled: 0
- _CameraFarFadeDistance: 2
- _CameraNearFadeDistance: 1
- _ColorMode: 0
- _Cull: 2
- _Cutoff: 0.5 - _Cutoff: 0.5
- _DetailNormalMapScale: 1 - _DetailNormalMapScale: 1
- _DistortionBlend: 0.5
- _DistortionEnabled: 0
- _DistortionStrength: 1
- _DistortionStrengthScaled: 0
- _DstBlend: 0 - _DstBlend: 0
- _EmissionEnabled: 1
- _FlipbookMode: 0
- _GlossMapScale: 1 - _GlossMapScale: 1
- _Glossiness: 0.5 - _Glossiness: 0.5
- _GlossyReflections: 1 - _GlossyReflections: 1
- _LightingEnabled: 0
- _Metallic: 0 - _Metallic: 0
- _Mode: 0 - _Mode: 0
- _OcclusionStrength: 1 - _OcclusionStrength: 1
- _Parallax: 0.02 - _Parallax: 0.02
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0
- _SoftParticlesEnabled: 0
- _SoftParticlesFarFadeDistance: 1
- _SoftParticlesNearFadeDistance: 0
- _SpecularHighlights: 1 - _SpecularHighlights: 1
- _SrcBlend: 1 - _SrcBlend: 1
- _UVSec: 0 - _UVSec: 0
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}
- _ColorAddSubDiff: {r: 1, g: 0, b: 0, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

View File

@ -47,7 +47,7 @@ PlayerSettings:
defaultScreenWidthWeb: 960 defaultScreenWidthWeb: 960
defaultScreenHeightWeb: 600 defaultScreenHeightWeb: 600
m_StereoRenderingPath: 0 m_StereoRenderingPath: 0
m_ActiveColorSpace: 1 m_ActiveColorSpace: 0
m_MTRendering: 1 m_MTRendering: 1
mipStripping: 0 mipStripping: 0
numberOfMipsStripped: 0 numberOfMipsStripped: 0