This video YouTube without subtitles really hurt, my English is very slag, almost do not understand, there are many documents do not tell the important information (the document is too few things to say).
But after studying you can unlock several poses. This video is mainly to teach you to do Distancefield to write shader, the following is the final effect:
The first step is to pass R.shaderdevelopmentmode 1,r. Dumpshaderdebuginfo 1 Turn on shader development mode (but I don't feel any use, maybe it's more useful to write HLSL with RHI)
For the convenience of everyone, I am here to paste the video and material nodes:
First paragraph of code:
FLOAT3 camvec=normalize (worldpos-view.vieworigin); FLOAT3 curpos=worldpos;float3 Normal=0;int maxsteps=16;float Curdist,accum=0;float minstepsize=0.01;int I=0;while (i<maxsteps) {Curdist=customexpression0 (Parameters,curpos, K,SPERE1,SPERE2,SPERE3,T); if (Curdist<thresh) {return float4 (1.0,1.0,1.0,1.0);} Curpos+=camvec*max (minstepsize,curdist); minstepsize+=0.02;i++;} return 0;
Second Customnode, post code at 37:08
Evaluate the Distancefloat s1=distance (sphere1.xyz,curpos)-sphere1.w;float s2=distance (Sphere2.xyz,curpos)- Sphere2.w;float s3=distance (Sphere3.xyz,curpos)-sphere3.w;float Dot1=dot (Normalize (CURPOS-SPHERE1.XYZ), FLOAT3 ( 0.707,0.707,0)) -1;float Dot2=sin (dot1*2+ (t*2)) *1.5;dot2+=sin (dot1*24+ (t*8)) *0.07;s1-=dot2;float h=saturate (0.5+ 0.5* (S2-S1)/k) s2=lerp (s2,s1,h)-k*h* (1.0-h) h=saturate (0.5+0.5 (S3-S2)/k); float curdf=lerp (s3,s2,h)-k*h (1.0-h); return CURDF;
33:20 look at the Getmaterialemissiveraw in the HLSL code and find that this function writes all the node information connected to the spontaneous light, and then translates the previous node into code.
The complete code until 50:00 (the previous code to facilitate the demonstration, the normal for the density of the partial separation, the following is the last code):
//metaballs simplefloat3 camvec=normalize (worldpos-vieworigin); FLOAT3 curpos= WORLDPOS;FLOAT3 normal=0;int maxsteps=64;float curdist,accum=0;float minstepsize=0.01;int i=0;while (i<maxsteps) { Curdist=customexpression0 (parameters,curpos,k,sphere1,sphere2,sphere3,t); if (Curdist<thresh) {curpos+=CamVec* Curdist;normal.x=customexpression0 (PARAMETERS,CURPOS+FLOAT3 (1,0,0) *o,k,sphere1,sphere2,sphere3,t); normal.y= CustomExpression0 (PARAMETERS,CURPOS+FLOAT3 (0,1,0) *o,k,sphere1,sphere2,sphere3,t); Normal.z=customexpression0 ( PARAMETERS,CURPOS+FLOAT3 (0,0,1) *o,k,sphere1,sphere2,sphere3,t); normal=normalize (normal); Camvec=lerp (camvec,-normal,refraction); int J=0;while (j<16) {Curdist=customexpression0 (Parameters,curpos,k, SPHERE1,SPHERE2,SPHERE3,T); if (Curdist<shadowmult) {Curdist=max (0,curdist); accum+=shadowmult-curdist;} curpos+=camvec*10;j++;} return Float4 (normal,accum);} Curpos+=camvec*max (minstepsize,curdist); minstepsize+=0.02;i++;} return 0;
The following is the final material node connection:
After 50:00, we demonstrate some of the code that was eventually used in the demo (which I haven't tested):
FLOAT3 startpos=curposfloat3 accum=0;float3 normal=0;int i=0;float curdist =customexpression2 (Parameters,curpos,k, sphere1,sphere2,sphere3,sphere4.t); Accum-=curdist*tracevec;curpos-=tracevec*curdist;curdist=customexpression2 ( parameters,curpos,k,sphere1,sphere2,sphere3,sphere4.t); accum-=curdist*tracevec;curpos-=tracevec*curdist; Curdist=customexpression2 (parameters,curpos,k,sphere1,sphere2,sphere3,sphere4.t); accum-=curdist*TraceVec; Curpos-=tracevec*curdist;return Startpos+accum;
Finally, you can make a sphere fusion effect by passing in the Worldpositionoffset.
1:00:00 demonstrates getting the various screen properties
Https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FViewUniformShaderParameters/index.html
Enter View.exposurescale in Customnode, and of course there are a few other Uniformshader entries that can get a lot of properties.
1:08:50 height to DF, a height map to distance field code (also not tested, the picture is in the engine, can be found by expanding the enginecontent search texture):
Heightratio=min (0.2,heightratio); float 2 texsize=0;float levels=0; Tex.getdimensions (0,texsize.x,texsize.y,levels); Texsize.x=min (texsize.x,256*s); Texsize.y=min (texsize.y,256*s); Float Searchlength=max (texsize.x,texsize.y) *heightratio;float mindist=1;float3 startpos=float3 (UV.x,UV.y,1); FLOAT3 sampledpos=0;for (int i=-searchlength;i<=searchlength;i++) {for (int j=-searchlength;j<=searchlength;j+ +) {sampledpos.xy=uv+float2 (i,j)/texsize;float texatray=tex.samplelevel (texsampler,sampledpos.xy,0); sampledpos.z =lerp (1,1-texatray,heightratio); Mindist=min (Mindist,length (Startpos-sampledpos));}} return mindist/heightratio;
Finally recommended this site
Http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
The formula for calculating the distance of several basic shapes is introduced.
How to use the Custom Material node and create Metaballs official video learning note