Announcement

Collapse
No announcement yet.

Undeclared identifier Texture2DSample in custom Global Shader for Plugin.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Undeclared identifier Texture2DSample in custom Global Shader for Plugin.

    So far I've succeeded in creating a UE Plugin with a custom Global Shader class that can be used via Blueprint to set a Render Texture Target to a custom color.

    I'm now passing a Texture2D reference to my shader and attempting to just simply sample the texture in the shader.

    Code:
    void MainVS(
    in float4 InPosition : ATTRIBUTE0,
    in float2 InUV : ATTRIBUTE1,
    out float2 OutUV : TEXCOORD0,
    out float4 Output : SV_POSITION
    )
    {
    Output = InPosition;
    OutUV = InUV;
    }
    
    Texture2D MyTex;
    SamplerState MySampler;
    float4 MainPS(  
    in float2 OutUV : TEXCOORD0,
    out float4 OutColor : SV_Target0
    ) 
    {
     OutColor = Texture2DSample(MyTex, MySampler, OutUV);
    }
    However, this fails with

    Code:
    X3004 - Undeclared Identifier "Texture2DSample"
    By which I figure it is missing the definition that is inside "Common.ush" in the Engine shaders folder.

    So I update the shader with:

    Code:
    #include"/Engine/Private/Common.ush"
    But now I get a huge amount of errors about inability to load from /Engine/Generated/... USH files. I can't copy and select the text (that would be too easy), so I have to resort a screenshot.

    Click image for larger version  Name:	error.png Views:	0 Size:	54.7 KB ID:	1741783


    I'm clearly going about this the wrong way, but I'm unable to find any examples online and the UE documentation has been very out of date and finding the information to get this far has been immensely frustrating.

    In my plugin module, I set up the virtual directories for my shader manually in the constructor:
    Code:
    void FCloudModule::StartupModule()
    {
        FString PluginDir = FPaths::Combine(FPaths::ProjectPluginsDir(), TEXT("Cloud"));
        FString PluginShaderDir = FPaths::Combine(PluginDir, TEXT("Shaders"));
        AddShaderSourceDirectoryMapping(TEXT("/Plugin/Cloud"), PluginShaderDir);
    }
    Last edited by Arkiruthis; 04-05-2020, 09:57 AM.

    #2
    As usual... I figure it out 5 mins after posting...

    Turns out I need to include Platform.ush from the Public folder.

    Code:
    #include"/Engine/Public/Platform.ush"
    #include"/Engine/Private/Common.ush"
    (and for bonus points, the observant among you will also realise MainPS should be void, not float4)

    Comment

    Working...
    X