Facepunch / sbox-issues

175 stars 12 forks source link

Shadergraph update broke `w` usage #2998

Closed timmybo5 closed 1 year ago

timmybo5 commented 1 year ago

Describe the bug

A recent update of Shadergraph broke one of my already working shaders by changing the usage of w in the compiled shader code.

shaders/skins/wb_texturewrap.shader : SM 5.0 (D3D11), Pixel Shader, Non-Zero Combos: ---
shaders/skins/wb_texturewrap.shader(79,20-29): error X3018: invalid subscript 'w'

Old compiled code:

    float4 MainPs( PixelInput i ) : SV_Target0
    {
        Material m;
        m.Albedo = float3( 1, 1, 1 );
        m.Normal = TransformNormal( i, float3( 0, 0, 1 ) );
        m.Roughness = 1;
        m.Metalness = 0;
        m.AmbientOcclusion = 1;
        m.TintMask = 1;
        m.Opacity = 1;
        m.Emission = float3( 0, 0, 0 );
        m.Transmission = 0;

        float local0 = i.vPositionSs.x;
        float local1 = i.vPositionSs.y;
        float4 local2 = float4( local0, local1, local1, local1 );
        float local3 = i.vPositionSs.w;

New compiled code:

    float4 MainPs( PixelInput i ) : SV_Target0
    {
        Material m;
        m.Albedo = float3( 1, 1, 1 );
        m.Normal = TransformNormal( i, float3( 0, 0, 1 ) );
        m.Roughness = 1;
        m.Metalness = 0;
        m.AmbientOcclusion = 1;
        m.TintMask = 1;
        m.Opacity = 1;
        m.Emission = float3( 0, 0, 0 );
        m.Transmission = 0;

        float2 local0 = CalculateViewportUv( i.vPositionSs.xy );
        float local1 = local0.x;
        float local2 = local0.y;
        float4 local3 = float4( local1, local2, 0, 0 );
        float local4 = local0.w; <------------------------------------ line 79

Reproduce with: image

aylaylay commented 1 year ago

This was an obvious typo in the Split node. Someone changed Screen Position to return a float2 so that's why this error has now popped up for you.

Also please note because of the Screen Position change, you'll have to change your shader. I believe you don't need to do the split, combine and divide anymore.. just plug the screenposition into the texture coord input.

timmybo5 commented 1 year ago

The divide by w gives a special effect basically wrapping it around the meshes ignoring the uv's, without that it's just a normal screenspace effect

I need it to create this sort of skins, not sure how it would be possible otherwise. image

aylaylay commented 1 year ago

Yeah sorry, Screen Position node was changed to do something else and I don't know why. I might revert it.

aylaylay commented 1 year ago

Alright, I've reverted ScreenPosition to do what it was doing before and added common accessors so you don't need to bother splitting and combining. sbox_CF52uL9FWW Here's how to do what you were doing before. Hope this helps.

timmybo5 commented 1 year ago

Even better! Works perfectly :)