From cbe9b5db00b91e08bb7e8d0afb8a7143df45d1fe Mon Sep 17 00:00:00 2001 From: Richard Horton Date: Mon, 12 Feb 2024 23:50:50 +0000 Subject: [PATCH 1/3] [2021.3] Fixed highlighting on HLSL code samples in URP Docs Fixes highlighting on HLSL code samples in URP Docs --- .../birp-urp-custom-shader-upgrade-guide.md | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Documentation~/urp-shaders/birp-urp-custom-shader-upgrade-guide.md b/Packages/com.unity.render-pipelines.universal/Documentation~/urp-shaders/birp-urp-custom-shader-upgrade-guide.md index 40cc91a2174..eea5c33ead7 100644 --- a/Packages/com.unity.render-pipelines.universal/Documentation~/urp-shaders/birp-urp-custom-shader-upgrade-guide.md +++ b/Packages/com.unity.render-pipelines.universal/Documentation~/urp-shaders/birp-urp-custom-shader-upgrade-guide.md @@ -17,7 +17,7 @@ This guide demonstrates how to upgrade a custom unlit shader from Built-In Rende The following shader is a simple unlit shader that works with the Built-In Render Pipeline. This guide demonstrates how to upgrade this shader to be compatible with URP. -```hlsl +```c++ Shader "Custom/UnlitShader" { Properties @@ -81,7 +81,7 @@ The following steps show how to solve these issues and make a shader compatible 1. Change `CGPROGRAM` and `ENDCG` to `HLSLPROGRAM` and `ENDHLSL`. 2. Update the include statement to reference the `Core.hlsl` file. - ```hlsl + ```c++ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" ``` @@ -89,7 +89,7 @@ The following steps show how to solve these issues and make a shader compatible 3. Add `"RenderPipeline" = "UniversalPipeline"` to the shader tags. - ```hlsl + ```c++ Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" } ``` @@ -97,7 +97,7 @@ The following steps show how to solve these issues and make a shader compatible 4. Replace the `struct v2f` code block with the following `struct Varyings` code block. This changes the struct to use the URP naming convention of `Varyings` instead of `v2f`, and updates the shader to use the correct variables for URP. - ```hlsl + ```c++ struct Varyings { // The positions in this struct must have the SV_POSITION semantic. @@ -109,7 +109,7 @@ The following steps show how to solve these issues and make a shader compatible 5. Beneath the include statement and above the `Varyings` struct, define a new struct with the name `Attributes`. This is equivalent to the Built-In Render Pipeline's appdata structs but with the new URP naming conventions. 6. Add the variables shown below to the `Attributes` struct. - ```hlsl + ```c++ struct Attributes { float4 positionOS : POSITION; @@ -119,13 +119,13 @@ The following steps show how to solve these issues and make a shader compatible 7. Update the `v2f vert` function definition to use the new `Varyings` struct and take an instance of the `Attributes` struct as an input, as shown below. - ```hlsl + ```c++ Varyings vert(Attributes IN) ``` 8. Update the vert function to output an instance of the `Varyings` struct and use the `TransformObjectToHClip` function to convert from object space to clip space. The function also needs to take the input `Attributes` UV and pass it to the output `Varyings` UV. - ```hlsl + ```c++ Varyings vert(Attributes IN) { Varyings OUT; @@ -141,7 +141,7 @@ The following steps show how to solve these issues and make a shader compatible 9. Place a `CBUFFER` code block around the properties the shader uses, along with the `UnityPerMaterial` parameter. - ```hlsl + ```c++ CBUFFER_START(UnityPerMaterial) float4 _Color; sampler2D _MainTex; @@ -152,7 +152,7 @@ The following steps show how to solve these issues and make a shader compatible 10. Update the `frag` function to use the `Varyings` input and the type `half4`, as shown below. The `frag` function must now use this type, as URP shaders do not support fixed types. - ```hlsl + ```c++ half4 frag(Varyings IN) : SV_Target { half4 texel = tex2D(_MainTex, IN.uv); @@ -173,7 +173,7 @@ Although the shader is now compatible with URP and the SRP Batcher, you can't us 2. Remove the `[NoScaleOffset]` ShaderLab attribute from the `_BaseMap` property. You can now see **Tiling** and **Offset** properties in the shader's Inspector window. 3. Add the `[MainTexture]` ShaderLab attribute to the `_BaseMap` property and the `[MainColor]` attribute to the `_Color` property. This tells the Editor which property to return when you request the main texture or main color from another part of your project or in the Editor. The `Properties` section of your shader should now look as follows: - ```hlsl + ```c++ Properties { [MainTexture] _BaseMap("Main Texture", 2D) = "white" {} @@ -183,14 +183,14 @@ Although the shader is now compatible with URP and the SRP Batcher, you can't us 4. Add the `TEXTURE2D(_BaseMap)` and `SAMPLER(sampler_BaseMap)` macros above the `CBUFFER` block. These macros define the texture and sampler state variables for use later. For more information on sampler states, refer to [Using sampler states](xref:SL-SamplerStates). - ```hlsl + ```c++ TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap); ``` 5. Change the `sampler2D _BaseMap` variable inside the `CBUFFER` block to `float4 _BaseMap_ST`. This variable now stores the tiling and offset values set in the Inspector. - ```hlsl + ```c++ CBUFFER_START(UnityPerMaterial) float4 _Color; float4 _BaseMap_ST; @@ -199,7 +199,7 @@ Although the shader is now compatible with URP and the SRP Batcher, you can't us 6. Change the `frag` function to access the texture with a macro instead of `tex2D` directly. To do this, replace `tex2D` with the `SAMPLE_TEXTURE2D` macro and add `sampler_BaseMap` as an additional parameter, as shown below: - ```hlsl + ```c++ half4 frag(Varyings IN) : SV_Target { half4 texel = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv); @@ -209,7 +209,7 @@ Although the shader is now compatible with URP and the SRP Batcher, you can't us 7. In the `vert` function, change `OUT.uv` to use a macro instead of passing the texture coordinates as `IN.uv` directly. To do this, replace `IN.uv` with `TRANSFORM_TEX(IN.uv, _BaseMap)`. Your `vert` function should now look like the following example: - ```hlsl + ```c++ Varyings vert(Attributes IN) { Varyings OUT; @@ -229,7 +229,7 @@ To see an example of the complete shader code, refer to the [Complete shader cod ## Complete shader code -```hlsl +```c++ Shader "Custom/UnlitShader" { Properties From 0fd93d18e90d1612c07cb949bb3b231e0aa9b0e9 Mon Sep 17 00:00:00 2001 From: Mark Green Date: Thu, 15 Feb 2024 21:30:16 +0000 Subject: [PATCH 2/3] [Port] [2021.3] Add link from URP to error shader page and back Add a link from the URP upgrade page back to the main manual error shader page, and back. Jira ticket: https://jira.unity3d.com/browse/DOCG-1012 --- .../Documentation~/upgrading-your-shaders.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Documentation~/upgrading-your-shaders.md b/Packages/com.unity.render-pipelines.universal/Documentation~/upgrading-your-shaders.md index dc704c12020..b32a3809304 100644 --- a/Packages/com.unity.render-pipelines.universal/Documentation~/upgrading-your-shaders.md +++ b/Packages/com.unity.render-pipelines.universal/Documentation~/upgrading-your-shaders.md @@ -1,10 +1,8 @@ # Converting your shaders -Shaders written for the Built-in Render Pipeline are not compatible with the URP shaders. +Shaders written for the Built-in Render Pipeline are not compatible with Universal Render Pipeline (URP) shaders. Unity renders objects with the [default magenta error shader](https://docs.unity3d.com/Manual/shader-error.html) if they use Built-In Render Pipeline shaders. -For an overview of the mapping between built-in shaders and URP shaders, see [Shader mappings](#shader-mappings). - -Use the [Render Pipeline Converter](features/rp-converter.md) to apply the shader mappings automatically. +Use the [Render Pipeline Converter](features/rp-converter.md) to convert any of Unity's built-in Built-In Render Pipeline materials and shaders to a URP material and shader. Refer to [Shader mappings](#shader-mappings) for more information. **Note**: The Render Pipeline Converter makes irreversible changes to the project. Back up your project before the conversion. From 8b034887ea6ba3aea8e85daee9760ab98a3e64e0 Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Fri, 16 Feb 2024 20:20:18 +0000 Subject: [PATCH 3/3] [VFX] Fix HLSL 2021 Incompatibility (to 2021.3) Equivalent issue with those fixed in https://github.cds.internal.unity3d.com/unity/unity/pull/39775/ and needed for this PR: https://github.cds.internal.unity3d.com/unity/unity/pull/38459/ Relative to https://devblogs.microsoft.com/directx/hlsl-2021-migration-guide/ --- .../Shaders/VFXOutputUpdate.template | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.visualeffectgraph/Shaders/VFXOutputUpdate.template b/Packages/com.unity.visualeffectgraph/Shaders/VFXOutputUpdate.template index d418a998cbd..94a629f9372 100644 --- a/Packages/com.unity.visualeffectgraph/Shaders/VFXOutputUpdate.template +++ b/Packages/com.unity.visualeffectgraph/Shaders/VFXOutputUpdate.template @@ -100,7 +100,11 @@ void CSMain(uint3 groupId : SV_GroupID, { ${VFXLoadSize} #if HAS_STRIPS - size3 += size3 < 0.0f ? -VFX_EPSILON : VFX_EPSILON; // Add an epsilon so that size is never 0 for strips + // Add an epsilon so that size is never 0 for strips + size3.x += size3.x < 0.0f ? -VFX_EPSILON : VFX_EPSILON; + size3.y += size3.y < 0.0f ? -VFX_EPSILON : VFX_EPSILON; + size3.z += size3.z < 0.0f ? -VFX_EPSILON : VFX_EPSILON; + #endif float4x4 elementToVFX = GetElementToVFXMatrix( attributes.axisX,