首发于狸猫居
RayMarch in UE4[第三章-more operate 体积材质01](搬运工不定时更新)

RayMarch in UE4[第三章-more operate 体积材质01](搬运工不定时更新)

我不是知识的创造者,我只是从源头打一桶水的搬运工,卑劣的抄袭者,所有的荣誉应该给参考列表中的创作者。:P

前方再次高能预警,涉及大量大佬的知识被我搬运整合。

  • raymarch体积
  • 分形图形代入
  • 伪体积材质

一、raymarch体积材质准备

在之前的两章中我们都是在ray实体模型,采用sphere tracing的方式。这样的方式问题是不能采样半透明物体。

采样半透明物体就不能停止march,要让每根射线走完采样范围,把采样的值累加起来。

先看一下如何生成自己的volume texture。或者官方现在的体积贴图生成文档生成案例

Ryan的ShaderbitGDCpack在4.22以上的ue中会因为Api的更新有一个错误的地方,就是报错行。

[SM5] Shader attempted to bind the Primitive uniform buffer even though Vertex Factory FLocalVertexFactory computes a PrimitiveId per-instance. This will break auto-instancing. Shaders should use GetPrimitiveData(Parameters.PrimitiveId).Member instead of Primitive.Member.

这里提示我们should use GetPrimitiveData(Parameters.PrimitiveId).Member instead of Primitive.Member.。这里主要的作用是读取物体的信息来进行一下矩阵操作,我们搜索以Primitive.开头的代码全部换成GetPrimitiveData(Parameters.PrimitiveId).就好了,后面的信息是不需要改变的。

两个custom中都是用了老式Primitive.的读取方式
查找出所有的Primitive.全部进行替换
替换为4.22的api,后缀读取信息与之前的是一样的就可以

这样就可以正常使用Ryan大佬的插件包啦~

二、分形

在我们常见的定义sdf模型函数外,还可以使用分形公式来制作raymarch。

float DE(vec3 pos) {
	vec3 z = pos;
	float dr = 1.0;
	float r = 0.0;
	for (int i = 0; i < Iterations ; i++) {
		r = length(z);
		if (r>Bailout) break;
		
		// convert to polar coordinates
		float theta = acos(z.z/r);
		float phi = atan(z.y,z.x);
		dr =  pow( r, Power-1.0)*Power*dr + 1.0;
		
		// scale and rotate the point
		float zr = pow( r,Power);
		theta = theta*Power;
		phi = phi*Power;
		
		// convert back to cartesian coordinates
		z = zr*vec3(sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta));
		z+=pos;
	}
	return 0.5*log(r)*r/dr;
}

未完待续...



reference:

发布于 2020-02-22 22:55