Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit 653164b

Browse files
authored
Merge pull request #2 from Netherlands3D/feature/supporting-receive-shadows-tile-shader
replacing the basic unlit shader with a custom 3d tiles shader for fotorealistic mesh to support receiving shadows
2 parents 689309b + 3064bb5 commit 653164b

File tree

4 files changed

+119
-4
lines changed

4 files changed

+119
-4
lines changed

Runtime/Scripts/Export/GltfWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public bool AddLight(Light uLight, out int lightId)
276276
case LightType.Point:
277277
light.SetLightType(LightPunctual.Type.Point);
278278
break;
279-
case LightType.Area:
279+
case LightType.Rectangle:
280280
case LightType.Disc:
281281
default:
282282
light.SetLightType(LightPunctual.Type.Spot);

Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected enum UnlitShaderFeatures {
8585
/// <summary>Name of the shader graph used for PBR metallic/roughness materials</summary>
8686
public const string MetallicShader = "glTF-pbrMetallicRoughness";
8787
/// <summary>Name of the shader graph used for unlit materials</summary>
88-
public const string UnlitShader = "glTF-unlit";
88+
public const string UnlitShader = "3dTilesShader";
8989
/// <summary>Name of the shader graph used for PBR specular/glossiness materials</summary>
9090
public const string SpecularShader = "glTF-pbrSpecularGlossiness";
9191

@@ -498,8 +498,13 @@ Shader LoadShaderByName(string shaderName) {
498498
var shaderPath = $"{k_ShaderPathPrefix}{shaderName}.shadergraph";
499499
Debug.Log(shaderPath);
500500
var shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderPath);
501-
if (shader == null) {
502-
Logger?.Error($"Cannot load shader at path {shaderPath}");
501+
if (shader == null)
502+
{
503+
shaderPath = $"{k_ShaderPathPrefix}{shaderName}.shader";
504+
shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderPath);
505+
if (shader == null) {
506+
Logger?.Error($"Cannot load shader at path {shaderPath}");
507+
}
503508
}
504509
return shader;
505510
#else
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Shader "Custom/Tiles3D"
2+
{
3+
Properties
4+
{
5+
_Color ("Color", Color) = (1,1,1,1)
6+
baseColorTexture ("Base Color Texture", 2D) = "white" {}
7+
}
8+
SubShader
9+
{
10+
Tags {
11+
"RenderPipeline" = "UniversalPipeline"
12+
"IgnoreProjector" = "True"
13+
"Queue" = "Geometry"
14+
"RenderType" = "Opaque"
15+
}
16+
LOD 100
17+
Blend SrcAlpha OneMinusSrcAlpha
18+
19+
Pass
20+
{
21+
Name "ForwardLit"
22+
Tags { "LightMode" = "UniversalForward" }
23+
24+
HLSLPROGRAM
25+
#pragma vertex vert
26+
#pragma fragment frag
27+
28+
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
29+
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
30+
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
31+
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
32+
#pragma multi_compile _ _SHADOWS_SOFT
33+
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
34+
35+
#pragma multi_compile_instancing
36+
37+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
38+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
39+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
40+
41+
struct appdata
42+
{
43+
float4 vertex : POSITION;
44+
float3 normal : NORMAL;
45+
float2 uv : TEXCOORD0;
46+
};
47+
48+
struct v2f
49+
{
50+
float4 vertex : SV_POSITION;
51+
float3 normal : TEXCOORD0;
52+
float3 worldPos : TEXCOORD1;
53+
float2 uv : TEXCOORD2;
54+
float4 shadowCoord : TEXCOORD3;
55+
};
56+
57+
sampler2D baseColorTexture;
58+
float4 _Color;
59+
60+
v2f vert (appdata v)
61+
{
62+
v2f o;
63+
o.vertex = TransformObjectToHClip(v.vertex);
64+
o.worldPos = TransformObjectToWorld(v.vertex);
65+
o.normal = TransformObjectToWorldNormal(v.normal);
66+
o.uv = v.uv;
67+
68+
VertexPositionInputs posInputs = GetVertexPositionInputs(v.vertex.xyz);
69+
o.shadowCoord = TransformWorldToShadowCoord(o.worldPos);
70+
71+
return o;
72+
}
73+
74+
float3 Lambert(float3 lightColor, float3 lightDir, float3 normal)
75+
{
76+
float NdotL = saturate(dot(normal, lightDir));
77+
return lightColor * NdotL;
78+
}
79+
80+
float4 frag (v2f i) : SV_Target
81+
{
82+
float4 texColor = tex2D(baseColorTexture, i.uv);
83+
float4 color = texColor * _Color;
84+
85+
Light mainLight = GetMainLight(i.shadowCoord); //get dir light
86+
float3 lightCol = Lambert(mainLight.color * mainLight.shadowAttenuation, mainLight.direction, float3(0,1,0)); //lets keep up normal always
87+
88+
// uint lightsCount = GetAdditionalLightsCount();
89+
// for (int j = 0; j < lightsCount; j++)
90+
// {
91+
// Light light = GetAdditionalLight(j, i.worldPos);
92+
// lightCol += Lambert(light.color * (light.distanceAttenuation * light.shadowAttenuation), light.direction, i.normal);
93+
// }
94+
95+
color.rgb *= lightCol + 1;
96+
return color;
97+
}
98+
ENDHLSL
99+
}
100+
}
101+
}

Runtime/Shader/3dTilesShader.shader.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)