Description

Shader Template files like MaterialTemplate.ush do not submit previous chunks when encountering a `%` character, unless that `%` character is `%s` or `%

{...}

`.

Because the error is happening during a string processing step, `%` characters inside of comments will also cause the issue.

Callstack contains the Shader Compiler errors.

 

Steps to Reproduce

1. Download the attached test project.
2. Enable Shader Development Mode in ConsoleVariables.ini
3. In MaterialTemplate.ush, add this comment near Line 315. The last two lines below are from the file as a reference point. It is important to place the added code above them:
```
/** This is a comment that uses the % character. */

/** Material declarations */
%

{material_declarations}

```
4. Open the test project (or any other project)
5. Observe the Shader Compiler error. Observe that the error occurs at the `%` before the added code. This is on line 94: `%

{vertex_interpolators_offsets_definition}

`
6. Make the C++ changes suggested by the Licensee, recompile and repeat step 4
7. Observe the Shader Compiler errors have been corrected.

Callstack
10 Shader compiler errors compiling DefaultDeferredDecalMaterial for platform PCD3D_SM6:
Shader debug info dumped to: "D:/Dev/UE540/Default3P/Saved/ShaderDebugInfo/PCD3D_SM6/DefaultDeferredDecalMaterial_6b60f7a3d6395f96/Default/FSplineMeshVertexFactory/FMeshDecalsVS/0_0df5d6bfa70a09a8"
D:/Dev/UE540/Engine/Shaders/Private/MaterialTemplate.ush(94,1): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Generated/Material.ush:94:1: error: expected unqualified-id
	%
	^
D:/Dev/UE540/Engine/Shaders/Private/MaterialTexture.ush(151,9): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Private/MaterialTexture.ush:151:9: error: use of undeclared identifier 'ProcessMaterialColorTextureLookup'; did you mean 'ProcessMaterialVirtualColorTextureLookup'?
	        return ProcessMaterialColorTextureLookup(TextureValue);
	               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/Dev/UE540/Engine/Shaders/Private/MeshDecals.usf(): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	               ProcessMaterialVirtualColorTextureLookup
D:/Dev/UE540/Engine/Shaders/Private/MaterialTexture.ush(149,8): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Private/MaterialTexture.ush:149:8: note: 'ProcessMaterialVirtualColorTextureLookup' declared here
	float4 ProcessMaterialVirtualColorTextureLookup(float4 TextureValue)
	       ^
D:/Dev/UE540/Engine/Shaders/Private/MaterialTexture.ush(159,9): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Private/MaterialTexture.ush:159:9: error: use of undeclared identifier 'ProcessMaterialColorTextureLookup'
	        return ProcessMaterialColorTextureLookup(TextureValue);
	               ^
D:/Dev/UE540/Engine/Shaders/Private/MaterialTexture.ush(211,17): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Private/MaterialTexture.ush:211:17: error: use of undeclared identifier 'ProcessMaterialColorTextureLookup'; did you mean 'ProcessMaterialAlphaTextureLookup'?
	        case 0: return ProcessMaterialColorTextureLookup(Value);
	                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/Dev/UE540/Engine/Shaders/Private/MeshDecals.usf(): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	                       ProcessMaterialAlphaTextureLookup
D:/Dev/UE540/Engine/Shaders/Private/MaterialTexture.ush(198,8): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Private/MaterialTexture.ush:198:8: note: 'ProcessMaterialAlphaTextureLookup' declared here
	float4 ProcessMaterialAlphaTextureLookup(float4 TextureValue)
	       ^
D:/Dev/UE540/Engine/Shaders/Private/MaterialTemplate.ush(3923,18): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	/Engine/Generated/Material.ush:3923:18: error: use of undeclared identifier 'ProcessMaterialColorTextureLookup'; did you mean 'ProcessMaterialAlphaTextureLookup'?
	        float4 Local2 = ProcessMaterialColorTextureLookup(Texture2DSampleBias(Material_Texture2D_0,Material_Texture2D_0Sampler,  Local0 ,View.MaterialTextureMipBias));
	                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:/Dev/UE540/Engine/Shaders/Private/MeshDecals.usf(): Shader FMeshDecalsVS, Permutation 0, VF FSplineMeshVertexFactory:
	                        ProcessMaterialAlphaTextureLookup
\\
\\
Retry compilation? 

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-218797 in the post.

0
Login to Vote

Fixed
ComponentUE - Rendering Architecture - Materials
Affects Versions5.45.4.25.4.1
Target Fix5.5
Fix Commit36566198
CreatedJun 25, 2024
ResolvedSep 25, 2024
UpdatedOct 2, 2024
View Jira Issue