Skip to content

Commit c716ef7

Browse files
committed
update readme.md
fix some shader bugs + cleanup fix sky ambient bug
1 parent 2d62999 commit c716ef7

File tree

7 files changed

+52
-48
lines changed

7 files changed

+52
-48
lines changed

Assets/Wm3Util/Editor/LevelTexture.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ public bool Construct(Wm3Texture texture, float ambient, LevelTextureType textur
5555
public bool Has(Wm3Texture texture, float ambient, LevelTextureType textureType)
5656
{
5757
bool ret = false;
58-
ambient = CalculateAmbient(texture, ambient, textureType);
58+
//sky requires special ambient treatment
59+
if (texture.Flags.IsSet(Wm3Flags.Sky))
60+
{
61+
ambient = CalculateAmbient(texture, ambient, LevelTextureType.SKY);
62+
}
63+
else
64+
{
65+
ambient = CalculateAmbient(texture, ambient, textureType);
66+
}
67+
5968
if (
6069
(m_textureReference != null) && (m_textureReference == texture)
6170
&& (Convert.ToInt32((ambient * 100) - (m_ambient * 100)) == 0)
@@ -115,6 +124,8 @@ private bool BuildMaterial(Wm3Texture texture, float ambient)
115124

116125
else if (texture.Flags.IsSet(Wm3Flags.Sky))
117126
{
127+
//recalculate ambient for sky (special treatment necessary)
128+
m_ambient = CalculateAmbient(texture, ambient, LevelTextureType.SKY);
118129
m_material = new Material(TemplateMaterials.GetSky());
119130
albedo = 0;
120131
}
@@ -151,16 +162,29 @@ private bool BuildMaterial(Wm3Texture texture, float ambient)
151162
private float CalculateAmbient(Wm3Texture texture, float ambient, LevelTextureType textureType)
152163
{
153164
float ambient_sum;
154-
if (textureType == LevelTextureType.SPRITE)
155-
{
156-
//WM3 format already merges texture and object ambient (special treatment for A8 engine)
157-
//--> only use object ambient and drop any texture ambient
158-
ambient_sum = (ambient * 0.01f) + 0.5f;
159-
}
160-
else
165+
switch (textureType)
161166
{
162-
//add mesh specific ambient to texture ambient
163-
ambient_sum = ((texture.Ambient + ambient) * 0.01f) + 0.5f;
167+
case LevelTextureType.SPRITE:
168+
{
169+
//WM3 format already merges texture and object ambient (special treatment for A8 engine)
170+
//--> only use object ambient and drop any texture ambient
171+
ambient_sum = (ambient * 0.01f) + 0.5f;
172+
break;
173+
}
174+
175+
case LevelTextureType.SKY:
176+
{
177+
//sky does not receive mesh specific ambient
178+
ambient_sum = (texture.Ambient * 0.01f) + 0.5f;
179+
break;
180+
}
181+
182+
default:
183+
{
184+
//add mesh specific ambient to texture ambient
185+
ambient_sum = ((texture.Ambient + ambient) * 0.01f) + 0.5f;
186+
break;
187+
}
164188
}
165189

166190
return ambient_sum;

Assets/Wm3Util/Editor/LevelTextureType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum LevelTextureType : int
55
{
66
STANDARD = 0,
77
SPRITE = 1,
8-
OVERLAY = 2
8+
OVERLAY = 2,
9+
SKY = 3
910
}
1011
}

Assets/Wm3Util/Shaders/Wm3Overlay.shader

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
float2 tex : TEXCOORD0;
4040
float3 worldPos : TEXCOORD1;
4141
float3 normal : NORMAL;
42-
//float fog : TEXCOORD2;
4342
};
4443

4544
vs_out vert(vs_in IN)
@@ -49,25 +48,14 @@
4948
OUT.worldPos = mul(unity_ObjectToWorld, IN.pos);
5049
OUT.normal = normalize(mul(unity_ObjectToWorld, IN.normal));
5150
OUT.tex = IN.tex;
52-
//OUT.fog = OUT.pos.z;
5351
return OUT;
5452
}
5553

5654
float4 frag(vs_out IN) : COLOR
5755
{
5856
float4 colortex = tex2D(_MainTex, IN.tex);
59-
float trans = (colortex == _TransColor) & (_Overlay > 0);
57+
float trans = all(all(colortex.rgb == _TransColor.rgb)) & (_Overlay > 0);
6058
clip(-trans);
61-
/*float4 diffuse = 0.9 + 0.1 *_Albedo * saturate(dot(_WorldSpaceLightPos0, IN.normal));
62-
diffuse.a = 1;
63-
64-
float viewDistance = distance( _WorldSpaceCameraPos, IN.worldPos);
65-
float fogFactor = saturate((viewDistance - 50) / (100 - 50));
66-
67-
float4 color;
68-
color = saturate(colortex * diffuse * _Color);// *unity_AmbientSky);
69-
color = lerp(color, unity_FogColor, fogFactor);
70-
color.a = _Color.a;*/
7159
float4 color = Wm3Lighting(colortex, IN.normal, IN.worldPos, _Diffuse, _Color);
7260
return color;
7361
}

Assets/Wm3Util/Shaders/Wm3Sky.shader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
vs_out OUT;
4646
OUT.pos = UnityObjectToClipPos(IN.pos);
4747
OUT.normal = normalize(mul(UNITY_MATRIX_M, IN.normal));
48-
OUT.tex = OUT.pos;// mul(UNITY_MATRIX_M, IN.pos);
48+
OUT.tex = OUT.pos;
4949
OUT.dir = mul(unity_CameraToWorld, float3(0, 0, 1));
5050
return OUT;
5151
}
@@ -74,7 +74,7 @@
7474
float4 colortex = tex2D(_MainTex, screenUV);
7575
float4 light = _Color + unity_AmbientSky;
7676
float4 color = saturate(colortex * light);
77-
color.a = 0; //sky is always opaque
77+
color.a = 1; //sky is always opaque
7878
return color;
7979
}
8080
ENDCG

Assets/Wm3Util/Shaders/Wm3Solid.shader

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
SubShader{
99
Tags{ "Queue" = "Geometry" "RenderType" = "Opaque" "IgnoreProjector" = "True"}
1010
Fog { Mode off }
11-
Blend SrcAlpha OneMinusSrcAlpha
1211
ZWrite on
1312

1413
Pass{
@@ -35,7 +34,6 @@
3534
float2 tex : TEXCOORD0;
3635
float3 worldPos : TEXCOORD1;
3736
float3 normal : NORMAL;
38-
//float fog : TEXCOORD2;
3937
};
4038

4139
vs_out vert(vs_in IN)
@@ -45,22 +43,14 @@
4543
OUT.worldPos = mul(unity_ObjectToWorld, IN.pos);
4644
OUT.normal = normalize(mul(unity_ObjectToWorld, IN.normal));
4745
OUT.tex = IN.tex;
48-
//OUT.fog = OUT.pos.z;
4946
return OUT;
5047
}
5148

5249
float4 frag(vs_out IN) : COLOR
5350
{
5451
float4 colortex = tex2D(_MainTex, IN.tex);
5552
float4 color = Wm3Lighting(colortex, IN.normal, IN.worldPos, _Diffuse, _Color);
56-
/*float4 diffuse = _Diffuse * saturate(dot(_WorldSpaceLightPos0, IN.normal));
57-
diffuse.a = 0;
58-
59-
float viewDistance = distance( _WorldSpaceCameraPos, IN.worldPos);
60-
float fogFactor = saturate(viewDistance * unity_FogParams.z + unity_FogParams.w);
61-
float4 light = _Color + diffuse + unity_AmbientSky;
62-
float4 color = saturate(colortex * light);
63-
color = lerp(unity_FogColor, color, fogFactor);*/
53+
color.a = 1;
6454
return color;
6555
}
6656
ENDCG

Assets/Wm3Util/Shaders/Wm3Sprite.shader

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,8 @@
7474
float4 frag(vs_out IN) : COLOR
7575
{
7676
float4 colortex = tex2D(_MainTex, IN.tex);
77-
float trans = (colortex == _TransColor);
77+
float trans = all(colortex.rgb == _TransColor.rgb);
7878
clip(-trans);
79-
/*float4 diffuse = 0.9 + 0.1 *_Albedo * saturate(dot(_WorldSpaceLightPos0, IN.normal));
80-
diffuse.a = 1;
81-
82-
float viewDistance = distance( _WorldSpaceCameraPos, IN.worldPos);
83-
float fogFactor = saturate((viewDistance - 50) / (100 - 50));
84-
85-
float4 color;
86-
color = saturate(colortex * diffuse * _Color);// *unity_AmbientSky);
87-
color = lerp(color, unity_FogColor, fogFactor);*/
8879
float4 color = Wm3Lighting(colortex, IN.normal, IN.worldPos, _Diffuse, _Color);
8980
return color;
9081
}

readme.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ They are built in a way to imitate the Acknex3 look as close as possible. Custom
5858

5959
## Give me Samples!
6060

61-
A sample project will be forked soon.
61+
Kandoria is a sample project with several .wm3 files imported into several scenes.
62+
63+
Some manual changes were done:
64+
* Doors and enemies were made passable
65+
* Pitfalls were covered with invisible planes
66+
* Levels spread over several .wm3 files were merged
67+
* Simple level hub system was added
68+
* Fog and sky shader setup
69+
* FPSController for easy navigation added
70+
71+
Github: [https://github.com/firoball/Wm3Util_sample](https://github.com/firoball/Wm3Util_sample)
6272

6373

6474
## Future Development

0 commit comments

Comments
 (0)