Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Werner <stefan.werner@tangent-animation.com>2018-07-05 13:37:52 +0300
committerStefan Werner <stefan.werner@tangent-animation.com>2018-07-05 14:53:34 +0300
commit4d00e95ee3ed91f86262bb218f1c5df901da724c (patch)
tree5d9af704609b38cca76a5786189c126ac7072332 /intern/cycles/kernel/kernels
parentcd17b3258327522b8c6f56a3ee7239a91f2be149 (diff)
Cycles: Adding native support for UINT16 textures.
Textures in 16 bit integer format are sometimes used for displacement, bump and normal maps and can be exported by tools like Substance Painter. Without this patch, Cycles would promote those textures to single precision floating point, causing them to take up twice as much memory as needed. Reviewers: #cycles, brecht, sergey Reviewed By: #cycles, brecht, sergey Subscribers: sergey, dingto, #cycles Tags: #cycles Differential Revision: https://developer.blender.org/D3523
Diffstat (limited to 'intern/cycles/kernel/kernels')
-rw-r--r--intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h32
-rw-r--r--intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h8
-rw-r--r--intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h12
3 files changed, 45 insertions, 7 deletions
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
index 7bf833eadbc..b77b7350d86 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
@@ -35,13 +35,13 @@ template<typename T> struct TextureInterpolator {
static ccl_always_inline float4 read(uchar4 r)
{
- float f = 1.0f/255.0f;
+ float f = 1.0f / 255.0f;
return make_float4(r.x*f, r.y*f, r.z*f, r.w*f);
}
static ccl_always_inline float4 read(uchar r)
{
- float f = r*(1.0f/255.0f);
+ float f = r * (1.0f / 255.0f);
return make_float4(f, f, f, 1.0f);
}
@@ -63,6 +63,18 @@ template<typename T> struct TextureInterpolator {
return make_float4(f, f, f, 1.0f);
}
+ static ccl_always_inline float4 read(uint16_t r)
+ {
+ float f = r*(1.0f/65535.0f);
+ return make_float4(f, f, f, 1.0f);
+ }
+
+ static ccl_always_inline float4 read(ushort4 r)
+ {
+ float f = 1.0f/65535.0f;
+ return make_float4(r.x*f, r.y*f, r.z*f, r.w*f);
+ }
+
static ccl_always_inline float4 read(const T *data,
int x, int y,
int width, int height)
@@ -481,15 +493,21 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, fl
return TextureInterpolator<half>::interp(info, x, y);
case IMAGE_DATA_TYPE_BYTE:
return TextureInterpolator<uchar>::interp(info, x, y);
+ case IMAGE_DATA_TYPE_USHORT:
+ return TextureInterpolator<uint16_t>::interp(info, x, y);
case IMAGE_DATA_TYPE_FLOAT:
return TextureInterpolator<float>::interp(info, x, y);
case IMAGE_DATA_TYPE_HALF4:
return TextureInterpolator<half4>::interp(info, x, y);
case IMAGE_DATA_TYPE_BYTE4:
return TextureInterpolator<uchar4>::interp(info, x, y);
+ case IMAGE_DATA_TYPE_USHORT4:
+ return TextureInterpolator<ushort4>::interp(info, x, y);
case IMAGE_DATA_TYPE_FLOAT4:
- default:
return TextureInterpolator<float4>::interp(info, x, y);
+ default:
+ assert(0);
+ return make_float4(TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B, TEX_IMAGE_MISSING_A);
}
}
@@ -502,15 +520,21 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float x,
return TextureInterpolator<half>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_BYTE:
return TextureInterpolator<uchar>::interp_3d(info, x, y, z, interp);
+ case IMAGE_DATA_TYPE_USHORT:
+ return TextureInterpolator<uint16_t>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_FLOAT:
return TextureInterpolator<float>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_HALF4:
return TextureInterpolator<half4>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_BYTE4:
return TextureInterpolator<uchar4>::interp_3d(info, x, y, z, interp);
+ case IMAGE_DATA_TYPE_USHORT4:
+ return TextureInterpolator<ushort4>::interp_3d(info, x, y, z, interp);
case IMAGE_DATA_TYPE_FLOAT4:
- default:
return TextureInterpolator<float4>::interp_3d(info, x, y, z, interp);
+ default:
+ assert(0);
+ return make_float4(TEX_IMAGE_MISSING_R, TEX_IMAGE_MISSING_G, TEX_IMAGE_MISSING_B, TEX_IMAGE_MISSING_A);
}
}
diff --git a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
index 91ad289a858..a72fae5e1b1 100644
--- a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
+++ b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
@@ -127,11 +127,12 @@ ccl_device float4 kernel_tex_image_interp(KernelGlobals *kg, int id, float x, fl
const TextureInfo& info = kernel_tex_fetch(__texture_info, id);
CUtexObject tex = (CUtexObject)info.data;
- /* float4, byte4 and half4 */
+ /* float4, byte4, ushort4 and half4 */
const int texture_type = kernel_tex_type(id);
if(texture_type == IMAGE_DATA_TYPE_FLOAT4 ||
texture_type == IMAGE_DATA_TYPE_BYTE4 ||
- texture_type == IMAGE_DATA_TYPE_HALF4)
+ texture_type == IMAGE_DATA_TYPE_HALF4 ||
+ texture_type == IMAGE_DATA_TYPE_USHORT4)
{
if(info.interpolation == INTERPOLATION_CUBIC) {
return kernel_tex_image_interp_bicubic<float4>(info, tex, x, y);
@@ -164,7 +165,8 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float x,
const int texture_type = kernel_tex_type(id);
if(texture_type == IMAGE_DATA_TYPE_FLOAT4 ||
texture_type == IMAGE_DATA_TYPE_BYTE4 ||
- texture_type == IMAGE_DATA_TYPE_HALF4)
+ texture_type == IMAGE_DATA_TYPE_HALF4 ||
+ texture_type == IMAGE_DATA_TYPE_USHORT4)
{
if(interpolation == INTERPOLATION_CUBIC) {
return kernel_tex_image_interp_bicubic_3d<float4>(info, tex, x, y, z);
diff --git a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
index faa9dd66d0e..011623130eb 100644
--- a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
+++ b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
@@ -54,11 +54,23 @@ ccl_device_inline float4 svm_image_texture_read(KernelGlobals *kg, const ccl_glo
float f = 1.0f/255.0f;
return make_float4(r.x*f, r.y*f, r.z*f, r.w*f);
}
+ /* Ushort4 */
+ else if(texture_type == IMAGE_DATA_TYPE_USHORT4) {
+ ushort4 r = tex_fetch(ushort4, info, offset);
+ float f = 1.0f/65535.f;
+ return make_float4(r.x*f, r.y*f, r.z*f, r.w*f);
+ }
/* Float */
else if(texture_type == IMAGE_DATA_TYPE_FLOAT) {
float f = tex_fetch(float, info, offset);
return make_float4(f, f, f, 1.0f);
}
+ /* UShort */
+ else if(texture_type == IMAGE_DATA_TYPE_USHORT) {
+ ushort r = tex_fetch(ushort, info, offset);
+ float f = r * (1.0f / 65535.0f);
+ return make_float4(f, f, f, 1.0f);
+ }
/* Byte */
else {
uchar r = tex_fetch(uchar, info, offset);