Browse Source

Added support for point sampling and affine texturing to the custom Quake shader, both of which can be enabled/disabled through the visual style. Also changes all of the keywords into multi_compile, so they aren't stripped during builds (all of these are controlled through code).

readme
Nico de Poel 5 years ago
parent
commit
fc051df6da
  1. 2
      Assets/Scripts/Game/GameAssets.cs
  2. 1
      Assets/Scripts/UniQuake.cs
  3. 23
      Assets/Scripts/VisualStyle.cs
  4. 11
      Assets/Shaders/Quake.shader
  5. 23
      Assets/Shaders/QuakeForwardPass.hlsl
  6. 2
      Assets/Shaders/QuakeInput.hlsl
  7. 4
      Assets/Styles/GLQuake/GLQuake.asset

2
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);
}

1
Assets/Scripts/UniQuake.cs

@ -211,6 +211,7 @@ public partial class UniQuake: MonoBehaviour
if (CurrentStyle == null)
{
CurrentStyle = style;
CurrentStyle.Activate();
return;
}

23
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");
}
}
}

11
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"

23
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);

2
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)

4
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}
Loading…
Cancel
Save