alelievr / HDRP-Custom-Passes

A bunch of custom passes made for HDRP
MIT License
1.31k stars 139 forks source link

Cannot implicitly convert from 'const float3' to 'float4' #9

Closed noncom closed 5 years ago

noncom commented 5 years ago

Trying the much wanted Selection effect in an RTX-enabled project, which implies using the d3d11 renderer, I'm getting:

Shader error in '02_Selection/Fullscreen': cannot implicitly convert from 'const float3' to 'float4' at line 97 (on d3d11)

and if I manually fix this line, turn:

float4 c = LoadCustomColor(posInput.positionSS);

into

float4 c = float4(LoadCustomColor(posInput.positionSS), 1);

then the next place for the same error shows up:

Shader error in '02_Selection/Fullscreen': cannot implicitly convert from 'const float3' to 'float4' at line 111 (on d3d11)

Fixing both places like that gives a broken effect with the white stripes going across the whole screen, and properly colored where they pass over the "selected" object, and also there is totally no outline despite changing any settings. See the screenshot below.

image

My current Unity version is 2019.3.0b6, and HDRP 7.1.1, and I believe that your code is relying on the newest version of HDRP taken hot from its repo, because in the repository: https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl#L319 this function indeed returns float4.

Could you please clarify if this is correct? And would updating to the latest Unity 2019.3.0b8 be the right way to solve this problem?

UPDATE: Changing the LoadCustomColor() and SampleCustomColor() to return float4 instead of float3 and to take the full rgba value inside of them, instead of just rgb, solved the issue and the shaders now work as in the example. This, however, feels hacky, I don't think that modifying that file should be necessary, and, besides, the auto-generated docs in the shaders, including the Selection shaders in this repo, clearly state that those functions return float3. So the question on what would be considered an appropriate solution to this problem still remains.

noncom commented 5 years ago

Fixed by updating to Unity 2019.3.0b8, importing/upgrading the project and then updating to HDRP 7.1.2 from the package manager. The errors are gone.