当一个物体存在于视线当中发一定的时间,人眼就会减少对它的观察,根据这个原理来渲染物体。
首先在第一帧检测物体是否可见,然后当物体存在的帧数大于6秒,就对他进行一半的渲染,也就是投射一半的光线。当物体消失在视野之后,再次见到,就对他进行16个射线追踪,根据时间依次递减。
主要的操作就是,在host端的一帧结束之后,给每个物体标号,依次判断物体可见性,依次叠加每个物体存在的帧数(也就是时间)。建立了一个buffer(用于gpu和cpu的数据交互),只要在cu端(也就是gpu)执行了添加纹理的函数,(也就是对某个物体添加纹理了-所以这个物体肯定是可见的),那么对buffer修改,返回到cpu,加帧数,修改在该物体的射线数,再将buffer恢复为0(clear缓冲区)。如果没有执行添加纹理的函数,说明不可见,那么buffer肯定还是0,则将射线恢复为16。这里再cu文件的phonle针孔相机里面执行射线数的操作,首先要做的就是检测这条射线是否是相交于该物体。
c++文件:
double t1,t2 ;
//int Z;
//int E = 0;//重要性
void glutDisplay()
{
clock_t start_time = clock();
updateCamera();
context->launch(0, width, height);
// glGenQueries(GLsizei n, GLuint * ids);
Buffer buffer = getOutputBuffer();
//clock_t start_time = clock();
Buffer erzhi_buffer = getOutputBuffer1();
//Buffer new_buffer = context["erzhi_buffer"]->getBuffer();
sutil::displayBufferGL(getOutputBuffer());
clock_t end_time = clock();
//cout << t << endl;
GLvoid * abc;
abc = erzhi_buffer->map(0, RT_BUFFER_MAP_READ_WRITE);
int* result = (int *)abc;
erzhi_buffer->unmap();
if (*result == 88888)
{
t1 += (double)(end_time - start_time) / CLOCKS_PER_SEC;
zhen = zhen + 1;
E = max(int((((exp)(-t1 * t1 / 8 / 8)) * 20 / 8 / (sqrt(2 * 3.1415))) * 16), 8);
cout << E << endl;
}
else {
zhen = 0;
E = 16;
t1 = 0;
}
if (*(result + 1) == 77777)
{
t2 += (double)(end_time - start_time) / CLOCKS_PER_SEC;
zhen1 = zhen1 + 1;
E1 = max(int((((exp)(-t2 * t2 / 8 / 8)) * 20 / 8 / (sqrt(2 * 3.1415)))*16), 8);
}
else {
zhen1 = 0;
E1 = 16;
t2 = 0;
}
//cout<<zhen<<" " << E<<" " <<E1<< endl;
*result = 11;
*(result + 1) = 0;
*(result + 2) = 0;
*(result + 3) = 0;
memcpy(erzhi_buffer->map(), result, sizeof(int) * 4);
erzhi_buffer->unmap();
GLvoid * abcd;
abcd = erzhi_buffer->map(0, RT_BUFFER_MAP_READ_WRITE);
int* result1 = (int *)abcd;
erzhi_buffer->unmap();
context["E"]->setInt(E);
context["E1"]->setInt(E1);
{static unsigned frame_count = 0;
sutil::displayFps(frame_count++);
//Z = frame_count++;
}
glutSwapBuffers();
}
cu文件:
/*
* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the follo