AmplifyCreations / AmplifyShaderEditor-Feedback

4 stars 0 forks source link

New – URP Sample Buffer #112

Open Dawie3565 opened 1 year ago

Dawie3565 commented 1 year ago

URPSampleBufferNode.cs

using Usage = UnityEditor.ShaderGraph.GraphDelta.GraphType.Usage;

namespace UnityEditor.ShaderGraph.Defs { internal class URPSampleBufferNode : IStandardNode { public static string Name => "URPSampleBuffer"; public static int Version => 1;

    public static NodeDescriptor NodeDescriptor => new(
        Version,
        Name,
        functions: new FunctionDescriptor[] {
            new (
                "NormalWorldSpace",
                "Out = SHADERGRAPH_SAMPLE_SCENE_NORMAL(UV);",
                new ParameterDescriptor[]
                {
                    new ParameterDescriptor("UV", TYPE.Vec4, Usage.In, REF.ScreenPosition_Default),
                    new ParameterDescriptor("Out", TYPE.Vec3, Usage.Out)
                }
            ),
            new (
                "MotionVectors",

@"TEXTURE2D(_MotionVectorTexture); uint2 pixelCoords = uint2(UV.xy _ScreenSize.xy); Out = LOAD_TEXTURE2D_X_LOD(_MotionVectorTexture, pixelCoords, 0).xy;", new ParameterDescriptor[] { new ParameterDescriptor("UV", TYPE.Vec4, Usage.In, REF.ScreenPosition_Default), new ParameterDescriptor("Out", TYPE.Vec2, Usage.Out) } ), new ( "BlitSource", @"uint2 pixelCoords = uint2(UV.xy _ScreenSize.xy); Out = LOAD_TEXTURE2D_X_LOD(_BlitTexture, pixelCoords, 0);", new ParameterDescriptor[] { new ParameterDescriptor("UV", TYPE.Vec4, Usage.In, REF.ScreenPosition_Default), new ParameterDescriptor("Out", TYPE.Vec4, Usage.Out) } ), } );

    public static NodeUIDescriptor NodeUIDescriptor => new(
        Version,
        Name,
        displayName: "URP Sample Buffer",
        tooltip: "Return data from the selected buffer.",
        category: "Utility/Input/URP",
        synonyms: new string[0],
        selectableFunctions: new()
        {
            { "NormalWorldSpace", "Normal World Space" },
            { "MotionVectors", "Motion Vectors" },
            { "BlitSource", "Blit Source" }
        },
        functionSelectorLabel: "Source Buffer",
        parameters: new ParameterUIDescriptor[] {
            new ParameterUIDescriptor(
                name: "UV",
                tooltip: "the screen coordinates to use for the sample",
                options: REF.OptionList.ScreenPositions
            ),
            new ParameterUIDescriptor(
                name: "Out",
                tooltip: "the sample of the selected buffer"
            )
        }
    );
}

}

Dawie3565 commented 1 month ago

Source Buffer = Normal World Space image

Source Buffer = Motion Vectors image

Source Buffer = Blit Source image

Dawie3565 commented 1 month ago

https://github.com/Unity-Technologies/Graphics/pull/7693/files#diff-aec2966f435f65c3a2d2eb36f50e72cc53d15c4451cb0d52d8b236e845df208b