From fcc41b0154a2e9f1df61b12b9de7a2f83aad3904 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Wed, 28 Jul 2021 15:06:51 +0200 Subject: [PATCH] Replaced previous Lightmapped shader with a generic Quake uber-shader, which is based on the Simple Unlit shader and allows choosing between lightmapped or blinn/phong lit, as well as emissive properties. Applied this to both the Entity and World materials, which is another step towards creating a unified and authentic look. --- Assets/Scripts/VisualStyle.cs | 9 +- Assets/Shaders/Lightmapped.shader | 303 ------------------ Assets/Shaders/LightmappedInput.hlsl | 28 -- Assets/Shaders/Quake.shader | 121 +++++++ ...htmapped.shader.meta => Quake.shader.meta} | 2 +- Assets/Shaders/QuakeForwardPass.hlsl | 140 ++++++++ ...t.hlsl.meta => QuakeForwardPass.hlsl.meta} | 2 +- Assets/Shaders/QuakeInput.hlsl | 50 +++ Assets/Shaders/QuakeInput.hlsl.meta | 10 + .../GLQuake/Materials/GLQuake_Entity.mat | 13 +- .../GLQuake/Materials/GLQuake_World.mat | 4 +- 11 files changed, 339 insertions(+), 343 deletions(-) delete mode 100644 Assets/Shaders/Lightmapped.shader delete mode 100644 Assets/Shaders/LightmappedInput.hlsl create mode 100644 Assets/Shaders/Quake.shader rename Assets/Shaders/{Lightmapped.shader.meta => Quake.shader.meta} (83%) create mode 100644 Assets/Shaders/QuakeForwardPass.hlsl rename Assets/Shaders/{LightmappedInput.hlsl.meta => QuakeForwardPass.hlsl.meta} (83%) create mode 100644 Assets/Shaders/QuakeInput.hlsl create mode 100644 Assets/Shaders/QuakeInput.hlsl.meta diff --git a/Assets/Scripts/VisualStyle.cs b/Assets/Scripts/VisualStyle.cs index d5a46f2..8cfc0b0 100644 --- a/Assets/Scripts/VisualStyle.cs +++ b/Assets/Scripts/VisualStyle.cs @@ -39,13 +39,15 @@ public class VisualStyle : ScriptableObject else if (surfaceFlags.HasFlag(QSurfaceFlags.DrawLava)) alpha = liquidProperties.lavaAlpha; else if (surfaceFlags.HasFlag(QSurfaceFlags.DrawTeleporter)) - alpha = liquidProperties.teleporterAlpha; + alpha = liquidProperties.teleAlpha; var material = new Material(liquidMaterial); material.SetColor("_BaseColor", new Color(1, 1, 1, alpha)); return material; } + // TODO: enable alpha test for DrawFence flag + return new Material(worldMaterial); } @@ -101,11 +103,12 @@ public class VisualStyle : ScriptableObject if (lightmap != null) { material.SetTexture("_LightMap", lightmap); - // TODO enable keyword (shader is still very specific) + material.EnableKeyword("_QLIGHTMAP_ON"); } } } +// TODO: should probably just use the cvars for this (r_wateralpha and such) [System.Serializable] public class LiquidProperties { @@ -114,7 +117,7 @@ public class LiquidProperties waterAlpha = 0.85f, slimeAlpha = 0.9f, lavaAlpha = 0.95f, - teleporterAlpha = 1.0f; + teleAlpha = 1.0f; } [System.Serializable] diff --git a/Assets/Shaders/Lightmapped.shader b/Assets/Shaders/Lightmapped.shader deleted file mode 100644 index eb64fd2..0000000 --- a/Assets/Shaders/Lightmapped.shader +++ /dev/null @@ -1,303 +0,0 @@ -Shader "UniQuake/Lightmapped" -{ - Properties - { - [MainTexture] _BaseMap("Texture", 2D) = "white" {} - [MainColor] _BaseColor("Color", Color) = (1, 1, 1, 1) - _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5 - - [NoScaleOffset] _LightMap("Lightmap", 2D) = "white" {} - - // BlendMode - [HideInInspector] _Surface("__surface", Float) = 0.0 - [HideInInspector] _Blend("__blend", Float) = 0.0 - [HideInInspector] _AlphaClip("__clip", Float) = 0.0 - [HideInInspector] _SrcBlend("Src", Float) = 1.0 - [HideInInspector] _DstBlend("Dst", Float) = 0.0 - [HideInInspector] _ZWrite("ZWrite", Float) = 1.0 - [HideInInspector] _Cull("__cull", Float) = 2.0 - - // Editmode props - [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0 - - // ObsoleteProperties - [HideInInspector] _MainTex("BaseMap", 2D) = "white" {} - [HideInInspector] _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1) - [HideInInspector] _SampleGI("SampleGI", float) = 0.0 // needed from bakedlit - } - SubShader - { - Tags {"RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" "ShaderModel"="4.5"} - LOD 100 - - Blend [_SrcBlend][_DstBlend] - ZWrite [_ZWrite] - Cull [_Cull] - - Pass - { - Name "Lightmapped" - - HLSLPROGRAM - #pragma exclude_renderers gles gles3 glcore - #pragma target 4.5 - - #pragma vertex vert - #pragma fragment frag - #pragma shader_feature_local_fragment _ALPHATEST_ON - #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON - - // ------------------------------------- - // Unity defined keywords - #pragma multi_compile_fog - #pragma multi_compile_instancing - #pragma multi_compile _ DOTS_INSTANCING_ON - - #include "LightmappedInput.hlsl" - - struct Attributes - { - float4 positionOS : POSITION; - float2 uv : TEXCOORD0; - float2 uv2 : TEXCOORD1; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Varyings - { - float2 uv : TEXCOORD0; - float2 uv2 : TEXCOORD1; - float4 vertex : SV_POSITION; - - UNITY_VERTEX_INPUT_INSTANCE_ID - UNITY_VERTEX_OUTPUT_STEREO - }; - - Varyings vert(Attributes input) - { - Varyings output = (Varyings)0; - - UNITY_SETUP_INSTANCE_ID(input); - UNITY_TRANSFER_INSTANCE_ID(input, output); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); - - VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); - output.vertex = vertexInput.positionCS; - output.uv = TRANSFORM_TEX(input.uv, _BaseMap); - output.uv2 = TRANSFORM_TEX(input.uv2, _LightMap); - //output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z); - - return output; - } - - half4 frag(Varyings input) : SV_Target - { - UNITY_SETUP_INSTANCE_ID(input); - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - - half2 uv = input.uv; - half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv); - half3 color = texColor.rgb * _BaseColor.rgb; - half alpha = texColor.a * _BaseColor.a; - AlphaDiscard(alpha, _Cutoff); - - half4 lightmapColor = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv2); - color.rgb = color.rgb * lightmapColor.rgb * 2.0f; - //color.rgb = lightmapColor.rgb; - -#ifdef _ALPHAPREMULTIPLY_ON - color *= alpha; -#endif - - //color = MixFog(color, input.fogCoord); - - return half4(color, alpha); - } - ENDHLSL - } - Pass - { - Name "DepthOnly" - Tags{"LightMode" = "DepthOnly"} - - ZWrite On - ColorMask 0 - - HLSLPROGRAM - #pragma exclude_renderers gles gles3 glcore - #pragma target 4.5 - - #pragma vertex DepthOnlyVertex - #pragma fragment DepthOnlyFragment - - // ------------------------------------- - // Material Keywords - #pragma shader_feature_local_fragment _ALPHATEST_ON - - //-------------------------------------- - // GPU Instancing - #pragma multi_compile_instancing - #pragma multi_compile _ DOTS_INSTANCING_ON - - #include "LightmappedInput.hlsl" - #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" - ENDHLSL - } - - // This pass it not used during regular rendering, only for lightmap baking. - Pass - { - Name "Meta" - Tags{"LightMode" = "Meta"} - - Cull Off - - HLSLPROGRAM - #pragma exclude_renderers gles gles3 glcore - #pragma target 4.5 - - #pragma vertex UniversalVertexMeta - #pragma fragment UniversalFragmentMetaUnlit - - #include "LightmappedInput.hlsl" - #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl" - - ENDHLSL - } - } - - SubShader - { - Tags {"RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" "ShaderModel"="2.0"} - LOD 100 - - Blend [_SrcBlend][_DstBlend] - ZWrite [_ZWrite] - Cull [_Cull] - - Pass - { - Name "Lightmapped" - HLSLPROGRAM - #pragma only_renderers gles gles3 glcore d3d11 - #pragma target 2.0 - - #pragma vertex vert - #pragma fragment frag - #pragma shader_feature_local_fragment _ALPHATEST_ON - #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON - - // ------------------------------------- - // Unity defined keywords - #pragma multi_compile_fog - #pragma multi_compile_instancing - - #include "LightmappedInput.hlsl" - - struct Attributes - { - float4 positionOS : POSITION; - float2 uv : TEXCOORD0; - UNITY_VERTEX_INPUT_INSTANCE_ID - }; - - struct Varyings - { - float2 uv : TEXCOORD0; - float fogCoord : TEXCOORD1; - float4 vertex : SV_POSITION; - - UNITY_VERTEX_INPUT_INSTANCE_ID - UNITY_VERTEX_OUTPUT_STEREO - }; - - Varyings vert(Attributes input) - { - Varyings output = (Varyings)0; - - UNITY_SETUP_INSTANCE_ID(input); - UNITY_TRANSFER_INSTANCE_ID(input, output); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); - - VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); - output.vertex = vertexInput.positionCS; - output.uv = TRANSFORM_TEX(input.uv, _BaseMap); - output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z); - - return output; - } - - half4 frag(Varyings input) : SV_Target - { - UNITY_SETUP_INSTANCE_ID(input); - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - - half2 uv = input.uv; - half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv); - half3 color = texColor.rgb * _BaseColor.rgb; - half alpha = texColor.a * _BaseColor.a; - AlphaDiscard(alpha, _Cutoff); - -#ifdef _ALPHAPREMULTIPLY_ON - color *= alpha; -#endif - - color = MixFog(color, input.fogCoord); - alpha = OutputAlpha(alpha, _Surface); - - return half4(color, alpha); - } - ENDHLSL - } - Pass - { - Name "DepthOnly" - Tags{"LightMode" = "DepthOnly"} - - ZWrite On - ColorMask 0 - - HLSLPROGRAM - #pragma only_renderers gles gles3 glcore d3d11 - #pragma target 2.0 - - #pragma vertex DepthOnlyVertex - #pragma fragment DepthOnlyFragment - - // ------------------------------------- - // Material Keywords - #pragma shader_feature_local_fragment _ALPHATEST_ON - - //-------------------------------------- - // GPU Instancing - #pragma multi_compile_instancing - - #include "LightmappedInput.hlsl" - #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" - ENDHLSL - } - - // This pass it not used during regular rendering, only for lightmap baking. - Pass - { - Name "Meta" - Tags{"LightMode" = "Meta"} - - Cull Off - - HLSLPROGRAM - #pragma only_renderers gles gles3 glcore d3d11 - #pragma target 2.0 - - #pragma vertex UniversalVertexMeta - #pragma fragment UniversalFragmentMetaUnlit - - #include "LightmappedInput.hlsl" - #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl" - - ENDHLSL - } - } - FallBack "Hidden/Universal Render Pipeline/FallbackError" - //CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.UnlitShader" -} diff --git a/Assets/Shaders/LightmappedInput.hlsl b/Assets/Shaders/LightmappedInput.hlsl deleted file mode 100644 index b4cddf4..0000000 --- a/Assets/Shaders/LightmappedInput.hlsl +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef UNIVERSAL_UNLIT_INPUT_INCLUDED -#define UNIVERSAL_UNLIT_INPUT_INCLUDED - -#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl" - -TEXTURE2D(_LightMap); SAMPLER(sampler_LightMap); - -CBUFFER_START(UnityPerMaterial) - float4 _BaseMap_ST; - float4 _LightMap_ST; - half4 _BaseColor; - half _Cutoff; - half _Surface; -CBUFFER_END - -#ifdef UNITY_DOTS_INSTANCING_ENABLED -UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata) - UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor) - UNITY_DOTS_INSTANCED_PROP(float , _Cutoff) - UNITY_DOTS_INSTANCED_PROP(float , _Surface) -UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata) - -#define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata__BaseColor) -#define _Cutoff UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata__Cutoff) -#define _Surface UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata__Surface) -#endif - -#endif diff --git a/Assets/Shaders/Quake.shader b/Assets/Shaders/Quake.shader new file mode 100644 index 0000000..dee7ccc --- /dev/null +++ b/Assets/Shaders/Quake.shader @@ -0,0 +1,121 @@ +// Shader targeted for low end devices. Single Pass Forward Rendering. +Shader "UniQuake/Quake" +{ + Properties + { + [MainTexture] _BaseMap("Base Map (RGB) Alpha (A)", 2D) = "white" {} + [MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1) + + [NoScaleOffset] _LightMap("Lightmap (RGBA)", 2D) = "white" {} + + _Cutoff("Alpha Clipping", Range(0.0, 1.0)) = 0.666 + + [HDR] _EmissionColor("Emission Color", Color) = (0,0,0) + [NoScaleOffset]_EmissionMap("Emission Map", 2D) = "white" {} + + // Blending state + [HideInInspector] _Surface("__surface", Float) = 0.0 + [HideInInspector] _Blend("__blend", Float) = 0.0 + [HideInInspector] _AlphaClip("__clip", Float) = 0.0 + [HideInInspector] _SrcBlend("__src", Float) = 1.0 + [HideInInspector] _DstBlend("__dst", Float) = 0.0 + [HideInInspector] _ZWrite("__zw", Float) = 1.0 + [HideInInspector] _Cull("__cull", Float) = 2.0 + } + + SubShader + { + Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "SimpleLit" "IgnoreProjector" = "True" "ShaderModel"="4.5"} + LOD 300 + + Pass + { + Name "ForwardLit" + Tags { "LightMode" = "UniversalForward" } + + // Use same blending / depth states as Standard shader + Blend[_SrcBlend][_DstBlend] + ZWrite[_ZWrite] + Cull[_Cull] + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #pragma target 4.5 + + // ------------------------------------- + // Material Keywords + #pragma shader_feature_local_fragment _ALPHATEST_ON + #pragma shader_feature_local_fragment _EMISSION + #pragma shader_feature_local _QLIGHTMAP_ON + + // ------------------------------------- + // Universal Pipeline keywords + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + + // ------------------------------------- + // Unity defined keywords + #pragma multi_compile_fog + + #pragma vertex LitPassVertexSimple + #pragma fragment LitPassFragmentSimple + #define BUMP_SCALE_NOT_SUPPORTED 1 + + #include "QuakeInput.hlsl" + #include "QuakeForwardPass.hlsl" + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags{"LightMode" = "DepthOnly"} + + ZWrite On + ColorMask 0 + Cull[_Cull] + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #pragma target 4.5 + + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + // ------------------------------------- + // Material Keywords + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #include "QuakeInput.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" + ENDHLSL + } + + // This pass is used when drawing to a _CameraNormalsTexture texture + Pass + { + Name "DepthNormals" + Tags{"LightMode" = "DepthNormals"} + + ZWrite On + Cull[_Cull] + + HLSLPROGRAM + #pragma exclude_renderers gles gles3 glcore + #pragma target 4.5 + + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + // ------------------------------------- + // Material Keywords + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #include "QuakeInput.hlsl" + #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl" + ENDHLSL + } + } + + Fallback "Hidden/Universal Render Pipeline/FallbackError" + //CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.SimpleLitShader" +} diff --git a/Assets/Shaders/Lightmapped.shader.meta b/Assets/Shaders/Quake.shader.meta similarity index 83% rename from Assets/Shaders/Lightmapped.shader.meta rename to Assets/Shaders/Quake.shader.meta index 9471dee..8e8a082 100644 --- a/Assets/Shaders/Lightmapped.shader.meta +++ b/Assets/Shaders/Quake.shader.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 91d80b5043d41db478595fab96d6e2c2 +guid: eb7abeca30cd4fb4cb8be05eca69f850 ShaderImporter: externalObjects: {} defaultTextures: [] diff --git a/Assets/Shaders/QuakeForwardPass.hlsl b/Assets/Shaders/QuakeForwardPass.hlsl new file mode 100644 index 0000000..f92b030 --- /dev/null +++ b/Assets/Shaders/QuakeForwardPass.hlsl @@ -0,0 +1,140 @@ +#ifndef UNIVERSAL_SIMPLE_LIT_PASS_INCLUDED +#define UNIVERSAL_SIMPLE_LIT_PASS_INCLUDED + +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + +struct Attributes +{ + float4 positionOS : POSITION; + float3 normalOS : NORMAL; + float4 tangentOS : TANGENT; + float2 texcoord : TEXCOORD0; +#ifdef _QLIGHTMAP_ON + float2 lightmapUV : TEXCOORD1; +#endif + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct Varyings +{ + float2 uv : TEXCOORD0; +#ifdef _QLIGHTMAP_ON + float2 lightmapUV : TEXCOORD1; +#else + half3 vertexSH : TEXCOORD1; +#endif + + float3 posWS : TEXCOORD2; // xyz: posWS + + float3 normal : TEXCOORD3; + float3 viewDir : TEXCOORD4; + + half4 fogFactorAndVertexLight : TEXCOORD6; // x: fogFactor, yzw: vertex light + + float4 positionCS : SV_POSITION; + UNITY_VERTEX_INPUT_INSTANCE_ID + UNITY_VERTEX_OUTPUT_STEREO +}; + +void InitializeInputData(Varyings input, out InputData inputData) +{ + inputData.positionWS = input.posWS; + + half3 viewDirWS = input.viewDir; + inputData.normalWS = input.normal; + + inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); + viewDirWS = SafeNormalize(viewDirWS); + + inputData.viewDirectionWS = viewDirWS; + + inputData.shadowCoord = float4(0, 0, 0, 0); + + inputData.fogCoord = input.fogFactorAndVertexLight.x; + inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; +#ifdef _QLIGHTMAP_ON + inputData.bakedGI = 0.0; +#else + inputData.bakedGI = SampleSHPixel(input.vertexSH, inputData.normalWS); +#endif + inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS); + inputData.shadowMask = 0.0; +} + +/////////////////////////////////////////////////////////////////////////////// +// Vertex and Fragment functions // +/////////////////////////////////////////////////////////////////////////////// + +// Used in Standard (Simple Lighting) shader +Varyings LitPassVertexSimple(Attributes input) +{ + Varyings output = (Varyings)0; + + UNITY_SETUP_INSTANCE_ID(input); + UNITY_TRANSFER_INSTANCE_ID(input, output); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); + + VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); + VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); + half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS); + half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS); + half fogFactor = ComputeFogFactor(vertexInput.positionCS.z); + + output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); + output.posWS.xyz = vertexInput.positionWS; + output.positionCS = vertexInput.positionCS; + + output.normal = NormalizeNormalPerVertex(normalInput.normalWS); + output.viewDir = viewDirWS; + +#ifdef _QLIGHTMAP_ON + output.lightmapUV.xy = input.lightmapUV.xy; +#else + output.vertexSH.xyz = SampleSHVertex(output.normal.xyz); +#endif + + output.fogFactorAndVertexLight = half4(fogFactor, vertexLight); + + return output; +} + +// Used for StandardSimpleLighting shader +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)); + half3 diffuse = diffuseAlpha.rgb * _BaseColor.rgb; + + half alpha = diffuseAlpha.a * _BaseColor.a; + AlphaDiscard(alpha, _Cutoff); + + InputData inputData; + InitializeInputData(input, inputData); + +#ifdef _QLIGHTMAP_ON + half4 lightmapColor = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.lightmapUV); + half3 finalColor = diffuse * lightmapColor.rgb * 2.0f; +#else + // Specular and smoothness are some bogus values just to make models not appear completely black on one side + half3 finalColor = UniversalFragmentBlinnPhong(inputData, diffuse, half4(0.2, 0.2, 0.2, 1), 0.5, 0.0, alpha).rgb; + // Light light = GetMainLight(); + // half3 diffuseColor = LightingLambert(light.color, light.direction, inputData.normalWS); + // half3 finalColor = diffuse * diffuseColor; +#endif + +#ifdef _EMISSION + finalColor += SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap)); +#endif + + half4 color = half4(finalColor, alpha); + + color.rgb = MixFog(color.rgb, inputData.fogCoord); + color.a = OutputAlpha(color.a, _Surface); + + return color; +} + +#endif diff --git a/Assets/Shaders/LightmappedInput.hlsl.meta b/Assets/Shaders/QuakeForwardPass.hlsl.meta similarity index 83% rename from Assets/Shaders/LightmappedInput.hlsl.meta rename to Assets/Shaders/QuakeForwardPass.hlsl.meta index de4f011..536b92b 100644 --- a/Assets/Shaders/LightmappedInput.hlsl.meta +++ b/Assets/Shaders/QuakeForwardPass.hlsl.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fe2f7d54113588c42925192dff3809e9 +guid: 6aa574d369884d24e8f28b300a86fcb3 ShaderImporter: externalObjects: {} defaultTextures: [] diff --git a/Assets/Shaders/QuakeInput.hlsl b/Assets/Shaders/QuakeInput.hlsl new file mode 100644 index 0000000..f8ee631 --- /dev/null +++ b/Assets/Shaders/QuakeInput.hlsl @@ -0,0 +1,50 @@ +#ifndef UNIVERSAL_SIMPLE_LIT_INPUT_INCLUDED +#define UNIVERSAL_SIMPLE_LIT_INPUT_INCLUDED + +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" +#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl" + +CBUFFER_START(UnityPerMaterial) + float4 _BaseMap_ST; + float4 _LightMap_ST; + half4 _BaseColor; + half4 _EmissionColor; + half _Cutoff; + half _Surface; +CBUFFER_END + +#ifdef UNITY_DOTS_INSTANCING_ENABLED + UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata) + UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor) + UNITY_DOTS_INSTANCED_PROP(float4, _EmissionColor) + UNITY_DOTS_INSTANCED_PROP(float , _Cutoff) + UNITY_DOTS_INSTANCED_PROP(float , _Surface) + UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata) + + #define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata__BaseColor) + #define _EmissionColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata__EmissionColor) + #define _Cutoff UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata__Cutoff) + #define _Surface UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata__Surface) +#endif + +TEXTURE2D(_LightMap); SAMPLER(sampler_LightMap); + +inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) +{ + outSurfaceData = (SurfaceData)0; + + half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)); + outSurfaceData.alpha = albedoAlpha.a * _BaseColor.a; + AlphaDiscard(outSurfaceData.alpha, _Cutoff); + + outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb; + + outSurfaceData.metallic = 0.0; // unused + outSurfaceData.specular = 0.0; // unused + outSurfaceData.smoothness = 0.0; // unused + //outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap)); + outSurfaceData.occlusion = 1.0; // unused + outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap)); +} + +#endif diff --git a/Assets/Shaders/QuakeInput.hlsl.meta b/Assets/Shaders/QuakeInput.hlsl.meta new file mode 100644 index 0000000..2101089 --- /dev/null +++ b/Assets/Shaders/QuakeInput.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 209b8f66e5d711946ba4c4ccb9e0a9b4 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Styles/GLQuake/Materials/GLQuake_Entity.mat b/Assets/Styles/GLQuake/Materials/GLQuake_Entity.mat index 35a8d74..5d29c93 100644 --- a/Assets/Styles/GLQuake/Materials/GLQuake_Entity.mat +++ b/Assets/Styles/GLQuake/Materials/GLQuake_Entity.mat @@ -8,14 +8,13 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: GLQuake_Entity - m_Shader: {fileID: 4800000, guid: 8d2bb70cbf9db8d4da26e15b26e74248, type: 3} + m_Shader: {fileID: 4800000, guid: eb7abeca30cd4fb4cb8be05eca69f850, type: 3} m_ShaderKeywords: _EMISSION _RECEIVE_SHADOWS_OFF m_LightmapFlags: 2 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 2000 - stringTagMap: - RenderType: Opaque + m_CustomRenderQueue: -1 + stringTagMap: {} disabledShaderPasses: [] m_SavedProperties: serializedVersion: 3 @@ -44,6 +43,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _LightMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -83,7 +86,7 @@ Material: - _ClearCoatMask: 0 - _ClearCoatSmoothness: 0 - _Cull: 2 - - _Cutoff: 0.5 + - _Cutoff: 0.666 - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - _DstBlend: 0 diff --git a/Assets/Styles/GLQuake/Materials/GLQuake_World.mat b/Assets/Styles/GLQuake/Materials/GLQuake_World.mat index d2ba49e..e0159f7 100644 --- a/Assets/Styles/GLQuake/Materials/GLQuake_World.mat +++ b/Assets/Styles/GLQuake/Materials/GLQuake_World.mat @@ -21,7 +21,7 @@ Material: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: GLQuake_World - m_Shader: {fileID: 4800000, guid: 91d80b5043d41db478595fab96d6e2c2, type: 3} + m_Shader: {fileID: 4800000, guid: eb7abeca30cd4fb4cb8be05eca69f850, type: 3} m_ShaderKeywords: _EMISSION _RECEIVE_SHADOWS_OFF m_LightmapFlags: 2 m_EnableInstancingVariants: 0 @@ -104,7 +104,7 @@ Material: - _ClearCoatMask: 0 - _ClearCoatSmoothness: 0 - _Cull: 2 - - _Cutoff: 0.5 + - _Cutoff: 0.666 - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - _DstBlend: 0