mirror of
https://github.com/stevenrobertson/cuburn.git
synced 2025-02-05 11:40:04 -05:00
fixes related to interpolation of palettes; hsv interpolation now goes
the 'short way' around the hue circle, and the correct palette is now chosen when > 2 palettes are present in the knots.
This commit is contained in:
parent
0f848b8bb8
commit
efd261bd5b
@ -318,7 +318,7 @@ __global__
|
|||||||
void interp_palette_hsv(uchar4 *outs, const float *times, const float4 *sources,
|
void interp_palette_hsv(uchar4 *outs, const float *times, const float4 *sources,
|
||||||
float tstart, float tstep) {
|
float tstart, float tstep) {
|
||||||
float time = tstart + blockIdx.x * tstep;
|
float time = tstart + blockIdx.x * tstep;
|
||||||
int idx = fmaxf(bitwise_binsearch(times, time), 1);
|
int idx = fmaxf(bitwise_binsearch(times, time) + 1, 1);
|
||||||
|
|
||||||
float4 left = sources[blockDim.x * (idx - 1) + threadIdx.x];
|
float4 left = sources[blockDim.x * (idx - 1) + threadIdx.x];
|
||||||
float4 right = sources[blockDim.x * (idx) + threadIdx.x];
|
float4 right = sources[blockDim.x * (idx) + threadIdx.x];
|
||||||
@ -329,10 +329,22 @@ void interp_palette_hsv(uchar4 *outs, const float *times, const float4 *sources,
|
|||||||
float3 lhsv = rgb2hsv(make_float3(left.x, left.y, left.z));
|
float3 lhsv = rgb2hsv(make_float3(left.x, left.y, left.z));
|
||||||
float3 rhsv = rgb2hsv(make_float3(right.x, right.y, right.z));
|
float3 rhsv = rgb2hsv(make_float3(right.x, right.y, right.z));
|
||||||
|
|
||||||
|
if (fabs(lhsv.x - rhsv.x) > 3.0f)
|
||||||
|
if (lhsv.x < rhsv.x)
|
||||||
|
lhsv.x += 6.0f;
|
||||||
|
else
|
||||||
|
rhsv.x += 6.0f;
|
||||||
|
|
||||||
float3 hsv;
|
float3 hsv;
|
||||||
hsv.x = lhsv.x * lf + rhsv.x * rf;
|
hsv.x = lhsv.x * lf + rhsv.x * rf;
|
||||||
hsv.y = lhsv.y * lf + rhsv.y * rf;
|
hsv.y = lhsv.y * lf + rhsv.y * rf;
|
||||||
hsv.z = lhsv.z * lf + rhsv.z * rf;
|
hsv.z = lhsv.z * lf + rhsv.z * rf;
|
||||||
|
|
||||||
|
if (hsv.x > 6.0f)
|
||||||
|
hsv.x -= 6.0f;
|
||||||
|
if (hsv.x < 0.0f)
|
||||||
|
hsv.x += 6.0f;
|
||||||
|
|
||||||
float3 rgb = hsv2rgb(hsv);
|
float3 rgb = hsv2rgb(hsv);
|
||||||
|
|
||||||
uchar4 out;
|
uchar4 out;
|
||||||
|
@ -154,7 +154,7 @@ float3 rgb2hsv(float3 rgb) {
|
|||||||
|
|
||||||
float s = M > 0.0f ? C / M : 0.0f;
|
float s = M > 0.0f ? C / M : 0.0f;
|
||||||
|
|
||||||
float h;
|
float h = 0.0f;
|
||||||
if (s != 0.0f) {
|
if (s != 0.0f) {
|
||||||
C = 1.0f / C;
|
C = 1.0f / C;
|
||||||
float rc = (M - rgb.x) * C;
|
float rc = (M - rgb.x) * C;
|
||||||
@ -165,7 +165,7 @@ float3 rgb2hsv(float3 rgb) {
|
|||||||
else if (rgb.y == M) h = 2 + rc - bc;
|
else if (rgb.y == M) h = 2 + rc - bc;
|
||||||
else h = 4 + gc - rc;
|
else h = 4 + gc - rc;
|
||||||
|
|
||||||
if (h < 0) h += 6;
|
if (h < 0) h += 6.0f;
|
||||||
}
|
}
|
||||||
return make_float3(h, s, M);
|
return make_float3(h, s, M);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user