x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Shader in C++ with 4.19

I try to make VERY SIMPLE sample project on using HLSL files with C++. I follow this link: https://www.unrealengine.com/en-US/blog/how-to-add-global-shaders-to-ue4

and make everything sorted, but got compiler issue:

 3>D:\18T2\GPG\week 08\Sh01\Source\Sh01\Private\Shader01.cpp(11): error C2039: 'ShouldCompilePermutation': is not a member of 'AShader01::FMyTestVS'

Please if you can fix this, please help ….

I made an empty project in editor, then copy HlSL file as tut said in folders, and here is my class:

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "Runtime/ShaderCore/Public/GlobalShader.h"
 #include "Shader01.generated.h"
 
 UCLASS()
 class SH01_API AShader01 : public AActor
 {
     GENERATED_BODY()
     
 public:    
     AShader01();
 
 protected:
     virtual void BeginPlay() override;
 
 public:    
     virtual void Tick(float DeltaTime) override;
 
 class FMyTestVS : public FGlobalShader
 {
     DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);
 
     FMyTestVS() { }
     FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) {
     }
     static bool ShouldCache(EShaderPlatform Platform)
     {
         return true;
     }
 };

.cpp file

 #include "Shader01.h"

 AShader01::AShader01()
 {
     PrimaryActorTick.bCanEverTick = true;
     IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);
 
 }
 
 void AShader01::BeginPlay()
 {
     Super::BeginPlay();
 }
 
 void AShader01::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }

....not sure how to fix this ... please help if you can ...

Cheers

Product Version: UE 4.19
Tags:
more ▼

asked Jul 13 '18 at 06:50 AM in C++ Programming

avatar image

emperor_katax
57 4 8 14

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

You paste it wrong

-First of all you don't need actor class for this.

-You declered FMyTestVS inside AShader01 which is probably main cause of a error, move it outside of that class

-You need to place IMPLEMENT_SHADER_TYPE outside of the constructor or any other function

more ▼

answered Jul 13 '18 at 08:39 AM

avatar image

Shadowriver
34.6k 917 164 1095

avatar image emperor_katax Jul 13 '18 at 10:01 AM

Many thanks for your message .... ; ] ,,, . I change my .h class to this

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "Runtime/ShaderCore/Public/GlobalShader.h"
 #include "Shader01.generated.h"
 
 UCLASS()
 class SH01_API AShader01 : public AActor
 {
     GENERATED_BODY()
     
 public:    
     AShader01();
 
 protected:
     virtual void BeginPlay() override;
 
 public:    
     virtual void Tick(float DeltaTime) override;
     
 };
 
 class FMyTestVS : public FGlobalShader
 {
     DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);
 
     FMyTestVS() { }
     FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) {
     }
 
     static bool ShouldCache(EShaderPlatform Platform)
     {
         return true;
     }
 
 };


and then comment this l,line on .cpp file

 IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);
avatar image emperor_katax Jul 13 '18 at 10:01 AM

And when i compile, i have NO issue. Then I try it this way, as you pointed to , and it is NOT working ...

 #include "Shader01.h"
  
 IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);
 // Sets default values
 AShader01::AShader01()
 {
     PrimaryActorTick.bCanEverTick = true;

 }

….

and also typed at the end of this file ... but no luck

error message:

 3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Private\Shader01.cpp(5): error C2039: 'ShouldCompilePermutation': is not a member of 'FMyTestVS'
 3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Public\Shader01.h(29): note: see declaration of 'FMyTestVS'
 3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Private\Shader01.cpp(5): error C2065: 'ShouldCompilePermutation': undeclared identifier



... what is wrong here? ....

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question