Kaynağa Gözat

Revert "Revert "Premier essai shader mais jte jure jcomrpend rien\n(est-ce que ça marche même antislash n sur git ?) bref le shader est dans Effects/wMaillage machin truc""

This reverts commit 2a52d1aaa6.
TEST
DemiSel 4 yıl önce
ebeveyn
işleme
67795b5f70

+ 21
- 0
FreeCam/Assets/BlockSpawner.cs Dosyayı Görüntüle

@@ -5,6 +5,7 @@ using UnityEngine.InputSystem;
5 5
 
6 6
 public class BlockSpawner : MonoBehaviour
7 7
 {
8
+
8 9
     [SerializeField]
9 10
     private GameObject _blockToPlace;
10 11
     public GameObject BlockToPlace
@@ -22,14 +23,18 @@ public class BlockSpawner : MonoBehaviour
22 23
 
23 24
     public float spawnDistance = 3f;
24 25
 
26
+    public Shader previewShader;
25 27
     private GameObject _blockInstance;
26 28
 
29
+
27 30
     private bool _isPreview = false;
31
+    private Shader _initialShader;
28 32
 
29 33
     public void OnPlaceBlock()
30 34
     {
31 35
         if (!_isPreview) return;
32 36
         _blockInstance.transform.SetParent(null);
37
+        SwitchToDefaultRender();
33 38
         _blockInstance = null;
34 39
         DisablePreviewMode();
35 40
     }
@@ -50,6 +55,7 @@ public class BlockSpawner : MonoBehaviour
50 55
         _blockInstance = Instantiate(_blockToPlace, spawnPos, Quaternion.identity);
51 56
         _blockInstance.transform.SetParent(this.transform, false);
52 57
         _isPreview = true;
58
+        SwitchToMeshRender();
53 59
     }
54 60
 
55 61
     private void DisablePreviewMode()
@@ -57,4 +63,19 @@ public class BlockSpawner : MonoBehaviour
57 63
         if (_blockInstance != null) Destroy(_blockInstance);
58 64
         _isPreview = false;
59 65
     }
66
+
67
+    private void SwitchToMeshRender()
68
+    {
69
+        MeshRenderer vRenderer = _blockInstance.GetComponent<MeshRenderer>();
70
+        Material vMaterial = vRenderer.material;
71
+        _initialShader = vMaterial.shader;
72
+        vMaterial.shader = previewShader;
73
+    }
74
+
75
+    private void SwitchToDefaultRender()
76
+    {
77
+        MeshRenderer vRenderer = _blockInstance.GetComponent<MeshRenderer>();
78
+        Material vMaterial = vRenderer.material;
79
+        vMaterial.shader = _initialShader;
80
+    }
60 81
 }

+ 3
- 1
FreeCam/Assets/BlockSpawner.cs.meta Dosyayı Görüntüle

@@ -3,7 +3,9 @@ guid: b78dfde35e58d1e4c858653eaf06ea64
3 3
 MonoImporter:
4 4
   externalObjects: {}
5 5
   serializedVersion: 2
6
-  defaultReferences: []
6
+  defaultReferences:
7
+  - _blockToPlace: {instanceID: 0}
8
+  - previewShader: {fileID: 4800000, guid: 167cdc0b24acc2f449b7fb1756fbc873, type: 3}
7 9
   executionOrder: 0
8 10
   icon: {instanceID: 0}
9 11
   userData: 

+ 8
- 0
FreeCam/Assets/Effects.meta Dosyayı Görüntüle

@@ -0,0 +1,8 @@
1
+fileFormatVersion: 2
2
+guid: 41582cd70db64bd47b6745a4095c0395
3
+folderAsset: yes
4
+DefaultImporter:
5
+  externalObjects: {}
6
+  userData: 
7
+  assetBundleName: 
8
+  assetBundleVariant: 

+ 13
- 0
FreeCam/Assets/Effects/NewShaderVariants.shadervariants Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+%YAML 1.1
2
+%TAG !u! tag:unity3d.com,2011:
3
+--- !u!200 &20000000
4
+ShaderVariantCollection:
5
+  m_ObjectHideFlags: 0
6
+  m_CorrespondingSourceObject: {fileID: 0}
7
+  m_PrefabInstance: {fileID: 0}
8
+  m_PrefabAsset: {fileID: 0}
9
+  m_Name: NewShaderVariants
10
+  m_Shaders:
11
+  - first: {fileID: 10512, guid: 0000000000000000f000000000000000, type: 0}
12
+    second:
13
+      variants: []

+ 8
- 0
FreeCam/Assets/Effects/NewShaderVariants.shadervariants.meta Dosyayı Görüntüle

@@ -0,0 +1,8 @@
1
+fileFormatVersion: 2
2
+guid: 1bac98432915ee94bafd6b815a8663d7
3
+NativeFormatImporter:
4
+  externalObjects: {}
5
+  mainObjectFileID: 0
6
+  userData: 
7
+  assetBundleName: 
8
+  assetBundleVariant: 

+ 53
- 0
FreeCam/Assets/Effects/standardSurfaceShader.shader Dosyayı Görüntüle

@@ -0,0 +1,53 @@
1
+Shader "Custom/standardSurfaceShader"
2
+{
3
+    Properties
4
+    {
5
+        _Color ("Color", Color) = (1,1,1,1)
6
+        _MainTex ("Albedo (RGB)", 2D) = "white" {}
7
+        _Glossiness ("Smoothness", Range(0,1)) = 0.5
8
+        _Metallic ("Metallic", Range(0,1)) = 0.0
9
+    }
10
+    SubShader
11
+    {
12
+        Tags { "RenderType"="Opaque" }
13
+        LOD 200
14
+
15
+        CGPROGRAM
16
+        // Physically based Standard lighting model, and enable shadows on all light types
17
+        #pragma surface surf Standard fullforwardshadows
18
+
19
+        // Use shader model 3.0 target, to get nicer looking lighting
20
+        #pragma target 3.0
21
+
22
+        sampler2D _MainTex;
23
+
24
+        struct Input
25
+        {
26
+            float2 uv_MainTex;
27
+        };
28
+
29
+        half _Glossiness;
30
+        half _Metallic;
31
+        fixed4 _Color;
32
+
33
+        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
34
+        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
35
+        // #pragma instancing_options assumeuniformscaling
36
+        UNITY_INSTANCING_BUFFER_START(Props)
37
+            // put more per-instance properties here
38
+        UNITY_INSTANCING_BUFFER_END(Props)
39
+
40
+        void surf (Input IN, inout SurfaceOutputStandard o)
41
+        {
42
+            // Albedo comes from a texture tinted by color
43
+            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
44
+            o.Albedo = c.rgb;
45
+            // Metallic and smoothness come from slider variables
46
+            o.Metallic = _Metallic;
47
+            o.Smoothness = _Glossiness;
48
+            o.Alpha = c.a;
49
+        }
50
+        ENDCG
51
+    }
52
+    FallBack "Diffuse"
53
+}

+ 9
- 0
FreeCam/Assets/Effects/standardSurfaceShader.shader.meta Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+fileFormatVersion: 2
2
+guid: b0c691a25e854aa488e55c7de961b502
3
+ShaderImporter:
4
+  externalObjects: {}
5
+  defaultTextures: []
6
+  nonModifiableTextures: []
7
+  userData: 
8
+  assetBundleName: 
9
+  assetBundleVariant: 

+ 134
- 0
FreeCam/Assets/Effects/wMaillageShader.shader Dosyayı Görüntüle

@@ -0,0 +1,134 @@
1
+Shader "Custom/wMaillageShader"
2
+{
3
+    Properties
4
+    {
5
+		_MainTex("Texture", 2D) = "white" {}
6
+		_Color("Color", Color) = (1,1,1,1)
7
+		_Threshold("Threshold", float) = 0.01
8
+
9
+		_EdgeColor("Edge color", Color) = (1,0,0,1)
10
+
11
+		_Glossiness("Smoothness", Range(0,1)) = 0.5
12
+		_Metallic("Metallic", Range(0,1)) = 0.0
13
+    }
14
+    SubShader
15
+    {
16
+        Cull Off ZWrite Off ZTest Always
17
+		Tags { "RenderType" = "Opaque" }
18
+        Pass
19
+
20
+		{
21
+
22
+			CGPROGRAM
23
+
24
+			#pragma vertex vert
25
+
26
+			#pragma fragment frag 
27
+			
28
+
29
+			#include "UnityCG.cginc"
30
+
31
+			struct appdata
32
+
33
+			{
34
+
35
+				float4 vertex : POSITION;
36
+
37
+				float2 uv : TEXCOORD0;
38
+
39
+			};
40
+
41
+			struct v2f
42
+
43
+			{
44
+
45
+				float2 uv : TEXCOORD0;
46
+
47
+				float4 vertex : SV_POSITION;
48
+
49
+			};
50
+
51
+			sampler2D _CameraDepthNormalsTexture;
52
+			float4 _MainTex_ST;
53
+
54
+			v2f vert(appdata v)
55
+
56
+			{
57
+
58
+				v2f o;
59
+
60
+				o.vertex = UnityObjectToClipPos(v.vertex);
61
+
62
+				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
63
+
64
+				return o;
65
+
66
+			}
67
+
68
+			sampler2D _MainTex;
69
+
70
+			float4 _MainTex_TexelSize;
71
+
72
+			float _Threshold;
73
+
74
+			fixed4 _EdgeColor;
75
+
76
+			float4 GetPixelValue(in float2 uv) {
77
+
78
+				half3 normal;
79
+
80
+				float depth;
81
+
82
+				DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, uv), depth, normal);
83
+
84
+				return fixed4(normal, depth);
85
+
86
+			}
87
+
88
+			fixed4 frag(v2f i) : SV_Target
89
+
90
+			{
91
+
92
+				fixed4 col = tex2D(_MainTex, i.uv);
93
+
94
+				fixed4 orValue = GetPixelValue(i.uv);
95
+
96
+				float2 offsets[8] = {
97
+
98
+					float2(-1, -1),
99
+
100
+					float2(-1, 0),
101
+
102
+					float2(-1, 1),
103
+
104
+					float2(0, -1),
105
+
106
+					float2(0, 1),
107
+
108
+					float2(1, -1),
109
+
110
+					float2(1, 0),
111
+
112
+					float2(1, 1)
113
+
114
+				};
115
+
116
+				fixed4 sampledValue = fixed4(0,0,0,0);
117
+
118
+				for (int j = 0; j < 8; j++) {
119
+
120
+					sampledValue += GetPixelValue(i.uv + offsets[j] * _MainTex_TexelSize.xy);
121
+
122
+				}
123
+
124
+				sampledValue /= 8;
125
+
126
+				return lerp(col, _EdgeColor, step(_Threshold, length(orValue - sampledValue)));
127
+
128
+			}
129
+
130
+			
131
+			ENDCG
132
+		}
133
+    }
134
+}

+ 10
- 0
FreeCam/Assets/Effects/wMaillageShader.shader.meta Dosyayı Görüntüle

@@ -0,0 +1,10 @@
1
+fileFormatVersion: 2
2
+guid: 167cdc0b24acc2f449b7fb1756fbc873
3
+ShaderImporter:
4
+  externalObjects: {}
5
+  defaultTextures:
6
+  - _MainTex: {fileID: 10300, guid: 0000000000000000f000000000000000, type: 0}
7
+  nonModifiableTextures: []
8
+  userData: 
9
+  assetBundleName: 
10
+  assetBundleVariant: 

+ 1
- 1
FreeCam/Assets/Materials/New Material.mat Dosyayı Görüntüle

@@ -8,7 +8,7 @@ Material:
8 8
   m_PrefabInstance: {fileID: 0}
9 9
   m_PrefabAsset: {fileID: 0}
10 10
   m_Name: New Material
11
-  m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
11
+  m_Shader: {fileID: 4800000, guid: b0c691a25e854aa488e55c7de961b502, type: 3}
12 12
   m_ShaderKeywords: 
13 13
   m_LightmapFlags: 4
14 14
   m_EnableInstancingVariants: 0

+ 4
- 0
FreeCam/Assets/Scenes/SampleScene.unity Dosyayı Görüntüle

@@ -688,5 +688,9 @@ PrefabInstance:
688 688
       propertyPath: _blockToPlace
689 689
       value: 
690 690
       objectReference: {fileID: 3300812737117657924, guid: 7b30a4c90d614f747872471cf43b8e56, type: 3}
691
+    - target: {fileID: 6193258497320629589, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}
692
+      propertyPath: previewShader
693
+      value: 
694
+      objectReference: {fileID: 4800000, guid: 167cdc0b24acc2f449b7fb1756fbc873, type: 3}
691 695
     m_RemovedComponents: []
692 696
   m_SourcePrefab: {fileID: 100100000, guid: 37333bbc22b455449a05fcf8aa6b9a8f, type: 3}

Loading…
İptal
Kaydet