envenger
(envenger)
November 8, 2014, 11:08am
1
Where can I read the HLSL code of the currently present Material editor functions?
I want to write a few custom nodes but, I don’t have time to learn HLSL as for now. So I just want to check how some pre-exsisting material function codes are written and learn from there.
I tried to find the material function codes but I couldn’t.
envenger
(envenger)
November 8, 2014, 11:27am
3
Already searched, they contain just the header files. I traced the functions to the MaterialExpression.cpp file but couldn’t find anything there.
envenger
(envenger)
November 8, 2014, 5:51pm
5
Thanks, I did find some info on a few functions although I didn’t understand much. I want to add a few custom noise generating functions so I wanted to see its already existing noise function.
But all I found on the existing noise function other than this
virtual int32 Noise(int32 Position, float Scale, int32 Quality, uint8 NoiseFunction, bool bTurbulence, int32 Levels, float OutputMin, float OutputMax, float LevelScale, int32 FilterWidth) override
{
if (ErrorUnlessFeatureLevelSupported(ERHIFeatureLevel::SM4) == INDEX_NONE)
{
return INDEX_NONE;
}
if(Position == INDEX_NONE || FilterWidth == INDEX_NONE)
{
return INDEX_NONE;
}
// to limit performance problems due to values outside reasonable range
Levels = FMath::Clamp(Levels, 1, 10);
int32 ScaleConst = Constant(Scale);
int32 QualityConst = Constant(Quality);
int32 NoiseFunctionConst = Constant(NoiseFunction);
int32 TurbulenceConst = Constant(bTurbulence);
int32 LevelsConst = Constant(Levels);
int32 OutputMinConst = Constant(OutputMin);
int32 OutputMaxConst = Constant(OutputMax);
int32 LevelScaleConst = Constant(LevelScale);
return AddCodeChunk(MCT_Float,
TEXT("MaterialExpressionNoise(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"),
*GetParameterCode(Position),
*GetParameterCode(ScaleConst),
*GetParameterCode(QualityConst),
*GetParameterCode(NoiseFunctionConst),
*GetParameterCode(TurbulenceConst),
*GetParameterCode(LevelsConst),
*GetParameterCode(OutputMinConst),
*GetParameterCode(OutputMaxConst),
*GetParameterCode(LevelScaleConst),
*GetParameterCode(FilterWidth));
}
envenger
(envenger)
November 9, 2014, 12:24am
7
That particular node, is adding a function call in the shader to MaterialExpressionNoise which can be found in Common.usf. So if you wanted to add your own noise functions. You could model off that same Noise function and just add your additional custom noise functions to Common.usf
If you look at MaterialExpressionNoise.h and MaterialExpressions.cpp. You will see that the compile function for that class calls Compiler->Noise. Which is the function your looking at above. So I would base my class off of the UMaterialExpressionNoise class.
Thanks was really helpful… Any advantage of using this method instead of adding a custom material node?