#URP Deferred HLSL shader basic output

1 messages · Page 1 of 1 (latest)

topaz island
#

Hello, i am trying to learn how to make a simple object shader for the URP Deferred pipeline, The basics i would get started with is making the shader get lit by all the lights and show the texture correctly. I uploaded a photo of one experiment where i tried to get it working. the shader for some reason has this black part covering it depending on how i move the camera. i think if i look downwards it covers it more and if i look upwards i see more of the correct texture. I also tried to look at the provided standard shaders from Unity. I can't however make out of it what the minimum is that it requires to correctly color and light up an object.

#

the .shader file below

Shader "Custom/ExamplePassFlag"
{
    Properties
    {
        _BaseMap ("Base Texture", 2D) = "white" {}
        _BaseColor ("Base Color", Color) = (1, 1, 1, 1)
    }
    SubShader
    {
        Tags
        {
            "RenderPipeline" = "UniversalPipeline"
            "LightMode" = "UniversalGBuffer"
            "UniversalMaterialType" = "Lit"
            "RenderType" = "Opaque"
            "Queue" = "Geometry"
        }

        Pass
        {
            Name "GBufferPass"

            Blend Off
            ZWrite On

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 4.5

            #include "ExamplePassFlag.hlsl"
            ENDHLSL
        }
    }
    FallBack "Hidden/Universal Render Pipeline/FallbackError"
}
#

the .hlsl file below

#ifndef EXAMPLE_PASS_FLAG_INCLUDED
#define EXAMPLE_PASS_FLAG_INCLUDED

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"

TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);

CBUFFER_START(UnityPerMaterial)
    float4 _BaseColor;
CBUFFER_END

struct Attributes
{
    float4 positionOS : POSITION;
    float2 uv : TEXCOORD0;
};

struct Varyings
{
    float4 positionHCS : SV_POSITION;
    float2 uv : TEXCOORD0;
};

Varyings vert(Attributes input)
{
    Varyings output;
    output.positionHCS = TransformObjectToHClip(input.positionOS.xyz);
    output.uv = input.uv;
    return output;
}

void frag(Varyings IN,
           out float4 outGBuffer0 : SV_Target0,
           out float4 outGBuffer1 : SV_Target1,
           out float4 outGBuffer2 : SV_Target2,
           out float4 outGBuffer3 : SV_Target3)
{
    float3 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv).rgb;
    float3 albedo = texColor * _BaseColor.rgb;
    outGBuffer0 = float4(albedo, 1.0); // Albedo + alpha
    
    float3 normalWS = normalize(mul((float3x3) unity_ObjectToWorld, float3(0, 0, 1)));
    float2 oct = PackNormalOctQuadEncode(normalWS);
    float2 oct01 = oct * 0.5 + 0.5;
    outGBuffer1 = float4(oct01, 0, 1);
    
    float metallic = 0.0;
    float occlusion = 1.0;
    float smoothness = 0.5;
    outGBuffer2 = float4(metallic, occlusion, 0.0, smoothness);
    
    outGBuffer3 = float4(0.0, 0.0, 0.0, 1.0);
}

#endif // EXAMPLE_PASS_FLAG_INCLUDED
long tartan
#

Did you ever get this to work?