How can I use this shader in UE4?

Hey,

How can I use this shader in UE4 blueprints?

I’ve tried to use Custom node in Material BP, but it seems it doesn’t allow to use functions inside code… %)

Which other ways exist to use custom shaders?

There is no support for this in the UE4 nativly so you have to write a custom shader yourself. You can use the custom node for this. Please refer to this blog for some examples on how it can be done:

You can also refer to this forum thread for reference.:

In short, you need to write a material with the Custom node somewhere in there where you write the shader code.

HTH

You can use the custom node for this.

My question is exactly about how to do this, since Custom node is not supporting functions?

Which is why I showed you the blog post. You can use just the normal nodes and simply call the material function inside the material function to create a recursive loop. Other than that I can only ask you to read the blog posts and the forum thread.

Ok, so the actual answer is to use Material Functions. Not sure why you just can’t write it instead of sending to some blog (even not an exact post…) but thanks.

Ok, it’s possible to create Material Functions which seems is the way to split up the whole shader code to blueprints.

Still not sure why I can’t just put the whole code to somewhere and call it as a single function.

Hey, lucky you, I wrote that a version of shader into the engine a year ago. You’ll want to scale down the volume that it raymarches though, I was pushing performance limits. Here’s how it’s done:

Use the code below in it’s corresponding custom node.

//TraceScene -CMOT Float 3:
float muS = 0.0;
float3 lightPos = float3( 20.0+15.0*sin(t), 15.0+12.0*sin(t),-20.0); 
float3 lightCol = (6000.0*float3( 1.0, 0.9, 0.5));
float transmittance = 1.0;
float3 scatteredLight = float3(0.0, 0.0, 0.0);
float d = 1.0; 
float material = 0.0;
float3 p = float3(0.0, 0.0, 0.0);
float phfu =1.0/(4.0*3.14);
float dd = 0.01;
for(int i=0; i<numIter;++i)
{
float3 p = rO + d*rD;
float mu=CustomExpression1(Parameters,p,t); 
float3 S = CustomExpression0(Parameters,p,t) * mu * phfu* CustomExpression2(Parameters,p,lightPos,t);
float3 Sint = (S - S * exp(-mu * dd)) / mu;
scatteredLight += transmittance * Sint;
transmittance *= exp(-mu * dd);
d += dd;
dd=dd*1.015;
if(transmittance<0.001)
break;
}
return scatteredLight;

//EvaluateLight -CMOT Float 3:
float3 lightPos = float3( 20.0+15.0*sin(t), 15.0+12.0*sin(t),-20.0);
float3 lightCol = (6000.0*float3( 1.0, 0.9, 0.5));
float3 L = lightPos-pos;
float distanceToL = length(L);
return lightCol * 1.0/(distanceToL*distanceToL);

//ParticipatingMedia -CMOT Float 1:
float geoFog = clamp(clamp((sin(pos.x)+sin(pos.y)+sin(pos.z))/3,0,1)-(-pos.z/10),0,1)*10;
float constantFog = 0.041;
float muS = constantFog + geoFog;
return muS;

//VolumetricShadow -CMOT Float 1:
const float numStep = 30.0;
float shadow = 1.0;
float muS = 0.0;
float dd = length(to-from) / numStep;
for(float s=0.5; s<(numStep-0.1); s+=1.0)
{
float3 pos = from + (to-from)*(s/(numStep));
float mu = CustomExpression1(Parameters,pos,t);
shadow *= exp(-mu * dd);
if(shadow<0.001)
break;
}
return shadow;

[Here’s what it looks like.][2]

Thanks a lot!!!