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"

c++ "Texture Sample" & "Multiply" Node

I want to recreate this Graph bellow in c++

alt text

I found this question https://answers.unrealengine.com/questions/441986/creating-a-dynamic-material-instance-on-c.html which has some code for creating a material but i cant find anything for doing the color multiplication


I have updated as follows. First I created a new material alt text which takes a texture as an input parameter. I then use this code to load the material file

     static ConstructorHelpers::FObjectFinder<UMaterialInterface> DynamicMaterial(TEXT("Material'/Game/Maps/testDepthMat.testDepthMat'"));
     if (DynamicMaterial.Succeeded())
         MaterialToGet = DynamicMaterial.Object;

and then to draw the material to the hud

 if (MaterialToGet)
     UMaterialInstanceDynamic* DynamicMaterialToUse = UMaterialInstanceDynamic::Create(MaterialToGet, this);
     DynamicMaterialToUse->SetTextureParameterValue(TEXT("depthTexture"), renderTarget);
     DrawMaterialSimple(DynamicMaterialToUse, thisX, thisY, w, h);

This draws just a black square in the HUD. The current material should not do anything to the color since it just multiples it by 1. Not sure whats wrong

Product Version: UE 4.18
depthtext.png (500.1 kB)
more ▼

asked Apr 13 '18 at 10:12 PM in C++ Programming

avatar image

3 1 3 8

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

2 answers: sort voted first

The solution to the edited problem is to set the Material Domain to 'User Interface' in the editor


more ▼

answered Apr 14 '18 at 06:10 PM

avatar image

3 1 3 8

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

In linked you gave there no material creation at all, it just shows how to send parameter to material (which is shader if you didn't realize yet) which requires creating dynamic instance of material, which is not really creating new material. Instance is parameter state in memory which you can applying to multiple meshes on one go durring rendering, saving some performance.

So you need to do exact same things as answer in that question shows and in your material you need to place Scalar Parameter node with a input you gonna do in C++ function and plug it to B pin of Multiply and you ready to do. You do the same with any other parameter type and you can use multiple amount of them and control a lot of aspects of your shader with them. You can also create material instance as a asset in content browser.

more ▼

answered Apr 14 '18 at 12:37 AM

avatar image

35.2k 921 166 1098

avatar image lufthansa747 Apr 14 '18 at 01:22 AM

thanks for the explanation, could you provide any code or references to documentation?

avatar image Shadowriver Apr 14 '18 at 07:52 AM
avatar image lufthansa747 Apr 14 '18 at 05:16 PM

thanks for the pointers, I have updated the question with code and the current problem of getting a black material drawn to HUD

(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