光线追踪之光照贴图尝试

下载了GitHub:https://github.com/AKGWSB/EzRT

运行代码得到一个 图:

常规opengl程序

第一个图像能不能作为纹理贴到第二个动图上去,这好象叫'光照贴图'。

现在尝试来一下

把图像上的颜色投向物体上

cpp 复制代码
	vector<vec3>vertexs;
	vector<vec4>colors;
	vector<vec3>Normals;

	//把图像上的颜色投向物体上
	{
		double* p = image;
		for (int i = 0; i < HEIGHT; i++)
		{
			for (int j = 0; j < WIDTH; j++)
			{
				// 像素坐标转投影平面坐标
				double x = 2.0 * double(j) / double(WIDTH) - 1.0;
				double y = 2.0 * double(HEIGHT - i) / double(HEIGHT) - 1.0;

				 MSAA
				//x += (randf() - 0.5f) / double(WIDTH);
				//y += (randf() - 0.5f) / double(HEIGHT);

				vec3 coord = vec3(x, y, SCREEN_Z);          // 计算投影平面坐标
				vec3 direction = normalize(coord - EYE);    // 计算光线投射方向

															// 生成光线
				Ray ray;
				ray.startPoint = coord;
				ray.direction = direction;

				// 与场景的交点
				HitResult res = shootTS(ray);
				vec4 color = vec4(0);
				color.x = *p; p++;  // R 通道
				color.y = *p; p++;  // G 通道
				color.z = *p; p++;  // B 通道

				if (res.isHit)
				{
					//命中序号
					if (res.n == s1.Sphere_n) {//triangles[3].Triangle_n
						vertexs.push_back(res.hitPoint);
						colors.push_back(color);
						Normals.push_back(res.material.normal);
					
					}

				}


			}
		}
	}


	//save_PointSN("changts.ply", vertexs, colors, Normals);
	//保存三角形光照贴图("triangle034.png", vertexs, colors, triangles, triangles[3].Triangle_n, "xy");

	保存球贴图("Sphere10.png", vertexs, colors, spheres, s1.Sphere_n);

然后得到一些稀疏点图

邻近插值

这是球上颜色图,有一半是不可见的

其它




贴上纹理

关掉材质色

是不是有点样子了

相关推荐
juebai1234 小时前
密集球光照贴图生成
贴图
WarPigs20 小时前
Blender导出fbx到Unity找不到贴图的问题
unity·blender·贴图
Tiger Z8 天前
R 语言科研绘图 --- 密度图-汇总
开发语言·程序人生·r语言·贴图
ue星空9 天前
Blender插件NodeWrangler导入贴图报错解决方法
blender·贴图
Tiger Z11 天前
R 语言科研绘图第 31 期 --- 韦恩图-基础
开发语言·程序人生·r语言·贴图
Yang-Never14 天前
OpenGL ES ->帧缓冲对象(Frame Buffer Object)离屏渲染获取纹理贴图
android·开发语言·kotlin·android studio·贴图
先生沉默先18 天前
3dsmax烘焙光照贴图然后在unity中使用
unity·3dsmax·贴图
Yang-Never18 天前
OpenGL ES ->多重纹理贴图
android·java·开发语言·kotlin·android studio·贴图
Tiger Z18 天前
R 语言科研绘图第 30 期 --- 密度图-堆叠
开发语言·程序人生·r语言·贴图