diff --git a/Assets/Scripts/Game/GameAssets.cs b/Assets/Scripts/Game/GameAssets.cs index 88eb99d..b0db6dc 100644 --- a/Assets/Scripts/Game/GameAssets.cs +++ b/Assets/Scripts/Game/GameAssets.cs @@ -66,7 +66,7 @@ public class GameAssets { if (!lightmaps.TryGetValue(lightmapNum, out var lightmap)) { - lightmap = new Texture2D(width, height, TextureFormat.RGBA32, false) { name = $"Lightmap_{lightmapNum}" }; + lightmap = new Texture2D(width, height, TextureFormat.RGBA32, false) { name = $"Lightmap_{lightmapNum}", wrapMode = TextureWrapMode.Clamp }; lightmaps.Add(lightmapNum, lightmap); } diff --git a/Assets/Scripts/UniQuake.cs b/Assets/Scripts/UniQuake.cs index 36f8c8b..7e34167 100644 --- a/Assets/Scripts/UniQuake.cs +++ b/Assets/Scripts/UniQuake.cs @@ -211,6 +211,7 @@ public partial class UniQuake: MonoBehaviour if (CurrentStyle == null) { CurrentStyle = style; + CurrentStyle.Activate(); return; } diff --git a/Assets/Scripts/VisualStyle.cs b/Assets/Scripts/VisualStyle.cs index 8cfc0b0..88422b5 100644 --- a/Assets/Scripts/VisualStyle.cs +++ b/Assets/Scripts/VisualStyle.cs @@ -15,6 +15,12 @@ public class VisualStyle : ScriptableObject [SerializeField] protected Material liquidMaterial; + [SerializeField] + protected bool pointSampling; + + [SerializeField] + protected bool affineTexturing; + [SerializeField] protected LiquidProperties liquidProperties = new LiquidProperties(); @@ -22,6 +28,14 @@ public class VisualStyle : ScriptableObject protected ParticleSystems particles = new ParticleSystems(); public ParticleSystems Particles => particles; + public virtual void Activate() + { + if (pointSampling) + Shader.EnableKeyword("_POINT_SAMPLING"); + else + Shader.DisableKeyword("_POINT_SAMPLING"); + } + public virtual Material CreateEntityMaterial() { return new Material(entityMaterial); @@ -86,6 +100,11 @@ public class VisualStyle : ScriptableObject material.EnableKeyword("_EMISSION"); else material.DisableKeyword("_EMISSION"); + + if (affineTexturing) + material.EnableKeyword("_AFFINE_ON"); + else + material.DisableKeyword("_AFFINE_ON"); } public virtual void SetWorldTextures(Material material, Texture2D mainTexture, Texture2D fullBright, Texture2D lightmap) @@ -105,6 +124,10 @@ public class VisualStyle : ScriptableObject material.SetTexture("_LightMap", lightmap); material.EnableKeyword("_QLIGHTMAP_ON"); } + else + { + material.DisableKeyword("_QLIGHTMAP_ON"); + } } } diff --git a/Assets/Shaders/Quake.shader b/Assets/Shaders/Quake.shader index dee7ccc..d6b420f 100644 --- a/Assets/Shaders/Quake.shader +++ b/Assets/Shaders/Quake.shader @@ -44,13 +44,14 @@ Shader "UniQuake/Quake" // ------------------------------------- // Material Keywords - #pragma shader_feature_local_fragment _ALPHATEST_ON - #pragma shader_feature_local_fragment _EMISSION - #pragma shader_feature_local _QLIGHTMAP_ON + #pragma multi_compile_local __ _ALPHATEST_ON + #pragma multi_compile_local __ _EMISSION + #pragma multi_compile_local __ _QLIGHTMAP_ON _AFFINE_ON // Lightmapping and affine texturing are mutually exclusive // ------------------------------------- // Universal Pipeline keywords #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile _ _POINT_SAMPLING // ------------------------------------- // Unity defined keywords @@ -83,7 +84,7 @@ Shader "UniQuake/Quake" // ------------------------------------- // Material Keywords - #pragma shader_feature_local_fragment _ALPHATEST_ON + #pragma multi_compile_local __ _ALPHATEST_ON #include "QuakeInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" @@ -108,7 +109,7 @@ Shader "UniQuake/Quake" // ------------------------------------- // Material Keywords - #pragma shader_feature_local_fragment _ALPHATEST_ON + #pragma multi_compile_local __ _ALPHATEST_ON #include "QuakeInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl" diff --git a/Assets/Shaders/QuakeForwardPass.hlsl b/Assets/Shaders/QuakeForwardPass.hlsl index f92b030..76c1465 100644 --- a/Assets/Shaders/QuakeForwardPass.hlsl +++ b/Assets/Shaders/QuakeForwardPass.hlsl @@ -17,7 +17,11 @@ struct Attributes struct Varyings { +#ifdef _AFFINE_ON + noperspective +#endif float2 uv : TEXCOORD0; + #ifdef _QLIGHTMAP_ON float2 lightmapUV : TEXCOORD1; #else @@ -104,8 +108,15 @@ half4 LitPassFragmentSimple(Varyings input) : SV_Target UNITY_SETUP_INSTANCE_ID(input); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - float2 uv = input.uv; - half4 diffuseAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)); + float2 uv = input.uv.xy; + half4 diffuseAlpha = SampleAlbedoAlpha(uv, + #if _POINT_SAMPLING + TEXTURE2D_ARGS(_BaseMap, point_repeat_sampler_BaseMap) + #else + TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap) + #endif + ); + half3 diffuse = diffuseAlpha.rgb * _BaseColor.rgb; half alpha = diffuseAlpha.a * _BaseColor.a; @@ -126,7 +137,13 @@ half4 LitPassFragmentSimple(Varyings input) : SV_Target #endif #ifdef _EMISSION - finalColor += SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap)); + finalColor += SampleEmission(uv, _EmissionColor.rgb, + #if _POINT_SAMPLING + TEXTURE2D_ARGS(_EmissionMap, point_repeat_sampler_EmissionMap) + #else + TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap) + #endif + ); #endif half4 color = half4(finalColor, alpha); diff --git a/Assets/Shaders/QuakeInput.hlsl b/Assets/Shaders/QuakeInput.hlsl index f8ee631..bec3fce 100644 --- a/Assets/Shaders/QuakeInput.hlsl +++ b/Assets/Shaders/QuakeInput.hlsl @@ -27,6 +27,8 @@ CBUFFER_END #define _Surface UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata__Surface) #endif + SAMPLER(point_repeat_sampler_BaseMap); + SAMPLER(point_repeat_sampler_EmissionMap); TEXTURE2D(_LightMap); SAMPLER(sampler_LightMap); inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) diff --git a/Assets/Styles/GLQuake/GLQuake.asset b/Assets/Styles/GLQuake/GLQuake.asset index eba8ec3..e2a156a 100644 --- a/Assets/Styles/GLQuake/GLQuake.asset +++ b/Assets/Styles/GLQuake/GLQuake.asset @@ -15,10 +15,12 @@ MonoBehaviour: entityMaterial: {fileID: 2100000, guid: 4d7703ac1adf3534f89b4041b779ff5e, type: 2} worldMaterial: {fileID: 2100000, guid: fcbaf32c00bea2344bbb1419c61364b6, type: 2} liquidMaterial: {fileID: 2100000, guid: cd59502a1689c0847a1963c60e347987, type: 2} + pointSampling: 0 + affineTexturing: 0 liquidProperties: waterAlpha: 0.8 slimeAlpha: 0.85 lavaAlpha: 0.9 - teleporterAlpha: 1 + teleAlpha: 1 particles: explosion: {fileID: 0}