Cycles: Change precomputed Sky Texture mapping to prioritize the horizon

Differential Revision: https://developer.blender.org/D8091
This commit is contained in:
Lukas Stockner 2020-07-13 01:51:13 +02:00
parent 41e6f9bd43
commit 192bd2605f
3 changed files with 10 additions and 6 deletions

@ -150,7 +150,7 @@ color sky_radiance_nishita(vector dir, float nishita_data[10], string filename)
/* if ray inside sun disc render it, otherwise render sky */ /* if ray inside sun disc render it, otherwise render sky */
if (sun_dir_angle < half_angular && sun_disc == 1) { if (sun_dir_angle < half_angular && sun_disc == 1) {
/* get 3 pixels data */ /* get 2 pixels data */
color pixel_bottom = color(nishita_data[0], nishita_data[1], nishita_data[2]); color pixel_bottom = color(nishita_data[0], nishita_data[1], nishita_data[2]);
color pixel_top = color(nishita_data[3], nishita_data[4], nishita_data[5]); color pixel_top = color(nishita_data[3], nishita_data[4], nishita_data[5]);
float y; float y;
@ -177,7 +177,8 @@ color sky_radiance_nishita(vector dir, float nishita_data[10], string filename)
else { else {
/* sky interpolation */ /* sky interpolation */
float x = (direction[1] + M_PI + sun_rotation) / M_2PI; float x = (direction[1] + M_PI + sun_rotation) / M_2PI;
float y = 1.0 - (dir_elevation / M_PI_2); /* more pixels toward horizon compensation */
float y = 1.0 - sqrt(dir_elevation / M_PI_2);
if (x > 1.0) { if (x > 1.0) {
x = x - 1.0; x = x - 1.0;
} }

@ -152,7 +152,7 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals *kg,
/* if ray inside sun disc render it, otherwise render sky */ /* if ray inside sun disc render it, otherwise render sky */
if (sun_disc && sun_dir_angle < half_angular) { if (sun_disc && sun_dir_angle < half_angular) {
/* get 3 pixels data */ /* get 2 pixels data */
float3 pixel_bottom = make_float3(nishita_data[0], nishita_data[1], nishita_data[2]); float3 pixel_bottom = make_float3(nishita_data[0], nishita_data[1], nishita_data[2]);
float3 pixel_top = make_float3(nishita_data[3], nishita_data[4], nishita_data[5]); float3 pixel_top = make_float3(nishita_data[3], nishita_data[4], nishita_data[5]);
float y; float y;
@ -179,7 +179,8 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals *kg,
else { else {
/* sky interpolation */ /* sky interpolation */
float x = (direction.y + M_PI_F + sun_rotation) / M_2PI_F; float x = (direction.y + M_PI_F + sun_rotation) / M_2PI_F;
float y = dir_elevation / M_PI_2_F; /* more pixels toward horizon compensation */
float y = safe_sqrtf(dir_elevation / M_PI_2_F);
if (x > 1.0f) { if (x > 1.0f) {
x -= 1.0f; x -= 1.0f;
} }

@ -287,11 +287,13 @@ void SKY_nishita_skymodel_precompute_texture(float *pixels,
float latitude_step = M_PI_2_F / height; float latitude_step = M_PI_2_F / height;
float longitude_step = M_2PI_F / width; float longitude_step = M_2PI_F / width;
float half_lat_step = latitude_step / 2.0f;
for (int y = start_y; y < end_y; y++) { for (int y = start_y; y < end_y; y++) {
float latitude = latitude_step * y; /* sample more pixels toward the horizon */
float latitude = (M_PI_2_F + half_lat_step) * sqr((float)y / height);
float *pixel_row = pixels + (y * width) * stride; float *pixel_row = pixels + (y * width * stride);
for (int x = 0; x < half_width; x++) { for (int x = 0; x < half_width; x++) {
float longitude = longitude_step * x - M_PI_F; float longitude = longitude_step * x - M_PI_F;