Skip to content
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

Sphere UV improvement #1487

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,6 @@ static __inline__ __device__ bool isBadVector(float3& vector) {
return isBadVector(tmp);
}

static __inline__ __device__ float3 sphereUV(float3 &direction) {

return float3 {
atan2(direction.x, direction.z) / (2.0f*M_PIf) + 0.5f,
direction.y * 0.5f + 0.5f, 0.0f
};
}

extern "C" __global__ void __anyhit__shadow_cutout()
{

Expand Down Expand Up @@ -234,7 +226,7 @@ extern "C" __global__ void __anyhit__shadow_cutout()

attrs.pos = P;
attrs.nrm = N;
attrs.uv = sphereUV(_normal_object_);
attrs.uv = sphereUV(_normal_object_, false);

attrs.clr = {};
attrs.tang = {};
Expand Down Expand Up @@ -505,7 +497,7 @@ extern "C" __global__ void __closesthit__radiance()

attrs.pos = P;
attrs.nrm = N;
attrs.uv = sphereUV(_normal_object_);
attrs.uv = sphereUV(_normal_object_, false);

attrs.clr = {};
attrs.tang = {};
Expand Down
8 changes: 0 additions & 8 deletions zenovis/xinxinoptix/Light.cu
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ static __inline__ __device__ void evalSurface(float4* uniforms) {
//GENERATED_BEGIN_MARK

//GENERATED_END_MARK
}

static __inline__ __device__ float3 sphereUV(float3 &direction) {

return float3 {
atan2(direction.x, direction.z) / (2.0f*M_PIf) + 0.5f,
direction.y * 0.5f + 0.5f, 0.0f
};
}

static __inline__ __device__ bool checkLightGAS(uint instanceId) {
Expand Down
11 changes: 11 additions & 0 deletions zenovis/xinxinoptix/Sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ namespace rtgems {
}
}

static __host__ __device__ __inline__ float3 sphereUV(const float3 &dir, bool internal) {
//https://en.wikipedia.org/wiki/UV_mapping

auto x = internal? dir.x:-dir.x;

auto u = 0.5f + atan2f(dir.z, x) * 0.5f / M_PIf;
auto v = 0.5f + asinf(dir.y) / M_PIf;

return float3 {u, v, 0.0f};
}

// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)

Expand Down
18 changes: 10 additions & 8 deletions zenovis/xinxinoptix/proceduralSky.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "Sampling.h"
#include "zxxglslvec.h"
#include "TraceStuff.h"

Expand Down Expand Up @@ -304,16 +305,16 @@ static __inline__ __device__ vec3 hdrSky2(
.rotX(to_radians(params.sky_rot_x))
.rotZ(to_radians(params.sky_rot_z))
.rotY(to_radians(params.sky_rot));
float u = atan2(dir.z, dir.x) / 3.1415926f * 0.5f + 0.5f;
float v = asin(dir.y) / 3.1415926f + 0.5f;
vec3 uv = sphereUV(dir, true);
vec3 col = vec3(0);
for(int jj=-2;jj<=2;jj++)
{
for(int ii=-2;ii<=2;ii++)
{
float dx = (float)ii / (float)(params.skynx);
float dy = (float)jj / (float)(params.skyny);
col = col + (vec3)texture2D(params.sky_texture, vec2(u + dx, v + dy)) * params.sky_strength;
col = col + (vec3)texture2D(params.sky_texture, vec2(uv[0] + dx, uv[1] + dy)) * params.sky_strength;
}
}

Expand All @@ -328,12 +329,13 @@ static __inline__ __device__ vec3 hdrSky(
.rotX(to_radians(params.sky_rot_x))
.rotZ(to_radians(params.sky_rot_z))
.rotY(to_radians(params.sky_rot));
float u = atan2(dir.z, dir.x) / 3.1415926f * 0.5f + 0.5f;
float v = asin(dir.y) / 3.1415926f + 0.5f;
vec3 col = (vec3)texture2D(params.sky_texture, vec2(u, v)) * params.sky_strength;

vec3 uv = sphereUV(dir, true);

vec3 col = (vec3)texture2D(params.sky_texture, vec2(uv[0], uv[1])) * params.sky_strength;
vec3 col2 = clamp(col, vec3(0.0f), vec3(upperBound));
int i = u * params.skynx;
int j = v * params.skyny;
int i = uv[0] * params.skynx;
int j = uv[1] * params.skyny;
//float p = params.skycdf[params.skynx * params.skyny + j * params.skynx + i];
pdf = luminance(col) / params.envavg / (2.0f * M_PIf * M_PIf);
return mix(col, col2, isclamp);
Expand Down
Loading