Skip to content

Commit 5767301

Browse files
Merge pull request #384 from Gothic-Unity-Project/bugfix/ui-transparency-quest
Bugfix - UI transparency
2 parents 95961a9 + 60bb35d commit 5767301

6 files changed

Lines changed: 126 additions & 9 deletions

File tree

Assets/Gothic-Core/Resources/Prefabs/UI/Menus/LoadingArea.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Canvas:
133133
m_OverrideSorting: 0
134134
m_OverridePixelPerfect: 0
135135
m_SortingBucketNormalizedSize: 0
136-
m_VertexColorAlwaysGammaSpace: 1
136+
m_VertexColorAlwaysGammaSpace: 0
137137
m_AdditionalShaderChannelsFlag: 0
138138
m_UpdateRectTransformForStandalone: 0
139139
m_SortingLayerID: 0

Assets/Gothic-Core/Scripts/Const/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class Animations
1616
// Unity shaders
1717
public static readonly Shader ShaderUnlit = Shader.Find("Universal Render Pipeline/Unlit");
1818
public static readonly Shader ShaderUnlitParticles = Shader.Find("Universal Render Pipeline/Particles/Unlit");
19+
public static readonly Shader ShaderUI = Shader.Find("Gothic/UI");
1920
public static readonly Shader ShaderTMPSprite = Shader.Find("TextMeshPro/Sprite");
2021
public static readonly Shader ShaderDecal = Shader.Find("Shader Graphs/Decal");
2122
public static readonly Shader ShaderStandard = Shader.Find("Standard");

Assets/Gothic-Core/Scripts/Services/Meshes/TextureService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public void Init()
5050
MainMenuTextImageMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Transparent);
5151

5252
// Loading Bars
53-
GothicLoadingMenuMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Opaque);
54-
LoadingBarBackgroundMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Opaque);
55-
LoadingBarMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Opaque);
53+
GothicLoadingMenuMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Fade);
54+
LoadingBarBackgroundMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Fade);
55+
LoadingBarMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Fade);
5656

5757
// Status Bars
5858
StatusBarBackgroundMaterial = GetEmptyMaterial(MaterialExtension.BlendMode.Opaque);
@@ -110,22 +110,22 @@ public void SetTexture(string texture, Material material)
110110

111111
public Material GetEmptyMaterial(MaterialExtension.BlendMode blendMode)
112112
{
113-
var standardShader = Constants.ShaderUnlit;
113+
var standardShader = Constants.ShaderUI;
114114
var material = new Material(standardShader);
115115

116116
switch (blendMode)
117117
{
118118
case MaterialExtension.BlendMode.Opaque:
119119
material.ToOpaqueMode();
120120
break;
121+
case MaterialExtension.BlendMode.Fade:
122+
material.ToFadeMode();
123+
break;
121124
case MaterialExtension.BlendMode.Transparent:
122125
material.ToTransparentMode();
123126
break;
124127
}
125128

126-
// Enable clipping of alpha values.
127-
material.EnableKeyword("_ALPHATEST_ON");
128-
129129
return material;
130130
}
131131

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Shader "Gothic/UI"
2+
{
3+
Properties
4+
{
5+
[MainTexture] _BaseMap("Texture", 2D) = "white" {}
6+
[MainColor] _BaseColor("Color", Color) = (1,1,1,1)
7+
8+
// Obsolete properties for backward compatibility
9+
[HideInInspector] _MainTex("Base Map", 2D) = "white" {}
10+
[HideInInspector] _Color("Base Color", Color) = (1,1,1,1)
11+
12+
// Blending state — driven by MaterialExtension methods
13+
// Defaults match ToOpaqueMode() behavior
14+
[HideInInspector] _SrcBlend("Src Blend", Float) = 1
15+
[HideInInspector] _DstBlend("Dst Blend", Float) = 0
16+
[HideInInspector] _ZWrite("Z Write", Float) = 1
17+
[HideInInspector] _Cull("Cull", Float) = 0
18+
19+
// Alpha cutoff
20+
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
21+
}
22+
23+
SubShader
24+
{
25+
Tags
26+
{
27+
"RenderType" = "Opaque"
28+
"Queue" = "Geometry"
29+
"RenderPipeline" = "UniversalPipeline"
30+
"IgnoreProjector" = "True"
31+
}
32+
33+
Blend [_SrcBlend] [_DstBlend]
34+
ZWrite [_ZWrite]
35+
Cull [_Cull]
36+
37+
Pass
38+
{
39+
Name "Default"
40+
Tags { "LightMode" = "SRPDefaultUnlit" }
41+
42+
HLSLPROGRAM
43+
#pragma vertex vert
44+
#pragma fragment frag
45+
#pragma target 2.0
46+
47+
#pragma shader_feature_local_fragment _ALPHATEST_ON
48+
49+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
50+
51+
struct Attributes
52+
{
53+
float4 positionOS : POSITION;
54+
float2 uv : TEXCOORD0;
55+
float4 color : COLOR;
56+
UNITY_VERTEX_INPUT_INSTANCE_ID
57+
};
58+
59+
struct Varyings
60+
{
61+
float4 positionCS : SV_POSITION;
62+
float2 uv : TEXCOORD0;
63+
float4 color : COLOR;
64+
UNITY_VERTEX_OUTPUT_STEREO
65+
};
66+
67+
TEXTURE2D(_BaseMap);
68+
SAMPLER(sampler_BaseMap);
69+
float4 _BaseMap_ST;
70+
half4 _BaseColor;
71+
half _Cutoff;
72+
73+
// Alias for backward compatibility with code that sets _MainTex
74+
#define _MainTex _BaseMap
75+
#define _Color _BaseColor
76+
77+
Varyings vert(Attributes input)
78+
{
79+
Varyings output;
80+
UNITY_SETUP_INSTANCE_ID(input);
81+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
82+
83+
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
84+
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
85+
output.color = input.color * _BaseColor;
86+
return output;
87+
}
88+
89+
half4 frag(Varyings input) : SV_Target
90+
{
91+
half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv);
92+
half4 color = texColor * input.color;
93+
94+
#if defined(_ALPHATEST_ON)
95+
clip(color.a - _Cutoff);
96+
#endif
97+
98+
return color;
99+
}
100+
ENDHLSL
101+
}
102+
}
103+
104+
FallBack "Hidden/Universal Render Pipeline/FallbackError"
105+
}

Assets/Gothic-Core/Shaders/GothicUI.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.

ProjectSettings/GraphicsSettings.asset

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ GraphicsSettings:
3838
- {fileID: 4800000, guid: 2934cb51602218b448edcb4315625e2a, type: 3}
3939
- {fileID: 4800000, guid: 3c0120062f2bdbd41b55907f82494d88, type: 3}
4040
- {fileID: 4800000, guid: 25dd2ac8db094fa1bf57da112a073017, type: 3}
41-
m_PreloadedShaders: []
41+
- {fileID: 4800000, guid: 02703c9bf67e33063b41c3d6cbc9be01, type: 3}
42+
m_PreloadedShaders:
43+
- {fileID: 0}
4244
m_PreloadShadersBatchTimeLimit: -1
4345
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
4446
m_CustomRenderPipeline: {fileID: 11400000, guid: ff1e1f739462f6446bfdd47f8653ddb3, type: 2}

0 commit comments

Comments
 (0)