New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of tweaks! #10

Merged
merged 10 commits into from Apr 12, 2018

Prepare a list of emissive lights once.

Having Scatter() rediscover it multiple times per pixels is
not great.

100 Mrays/s -> 120 Mrays/s
  • Loading branch information...
rygorous committed Apr 12, 2018
commit f9dae06ce3f0cf5396e06532ca386e553f1c6f3d
Copy path View file
@@ -61,6 +61,9 @@ static Material s_SphereMats[kSphereCount] =
#endif
};
static int s_EmissiveSpheres[kSphereCount];
static int s_EmissiveSphereCount;
static Camera s_Cam;
const float kMinT = 0.001f;
@@ -87,11 +90,10 @@ static bool Scatter(const Material& mat, const Ray& r_in, const Hit& rec, float3
// sample lights
#if DO_LIGHT_SAMPLING
for (int i = 0; i < kSphereCount; ++i)
for (int j = 0; j < s_EmissiveSphereCount; ++j)
{
int i = s_EmissiveSpheres[j];
const Material& smat = s_SphereMats[i];
if (smat.emissive.getX() <= 0 && smat.emissive.getY() <= 0 && smat.emissive.getZ() <= 0)
continue; // skip non-emissive
if (&mat == &smat)
continue; // skip self
const Sphere& s = s_Spheres[i];
@@ -304,6 +306,7 @@ void UpdateTest(float time, int frameCount, int screenWidth, int screenHeight)
aperture *= 0.2f;
#endif
s_EmissiveSphereCount = 0;
for (int i = 0; i < kSphereCount; ++i)
{
Sphere& s = s_Spheres[i];
@@ -313,6 +316,14 @@ void UpdateTest(float time, int frameCount, int screenWidth, int screenHeight)
s_SpheresSoA.centerZ[i] = s.center.getZ();
s_SpheresSoA.sqRadius[i] = s.radius * s.radius;
s_SpheresSoA.invRadius[i] = s.invRadius;
// Remember IDs of emissive spheres (light sources)
const Material& smat = s_SphereMats[i];
if (smat.emissive.getX() > 0 || smat.emissive.getY() > 0 || smat.emissive.getZ() > 0)
{
s_EmissiveSpheres[s_EmissiveSphereCount] = i;
s_EmissiveSphereCount++;
}
}
s_Cam = Camera(lookfrom, lookat, float3(0, 1, 0), 60, float(screenWidth) / float(screenHeight), aperture, distToFocus);
ProTip! Use n and p to navigate between commits in a pull request.