[Bf-blender-cvs] [153e1dc31a5] master: Fix T103513: Images lose their alpha channel when OSL is enabled for GPU Compute
Patrick Mours
noreply at git.blender.org
Mon Jan 2 14:16:36 CET 2023
Commit: 153e1dc31a518fc307c7d87bb5bd700688e438f9
Author: Patrick Mours
Date: Mon Jan 2 13:52:59 2023 +0100
Branches: master
https://developer.blender.org/rB153e1dc31a518fc307c7d87bb5bd700688e438f9
Fix T103513: Images lose their alpha channel when OSL is enabled for GPU Compute
The "osl_texture" intrinsic was not implemented correctly. It should handle alpha
separately from color, the number of channels input parameter only counts color
channels.
===================================================================
M intern/cycles/kernel/osl/services_gpu.h
===================================================================
diff --git a/intern/cycles/kernel/osl/services_gpu.h b/intern/cycles/kernel/osl/services_gpu.h
index 744c7103b28..b9ffd959f1a 100644
--- a/intern/cycles/kernel/osl/services_gpu.h
+++ b/intern/cycles/kernel/osl/services_gpu.h
@@ -1532,7 +1532,7 @@ ccl_device_extern void osl_texture_set_missingcolor_alpha(ccl_private OSLTexture
ccl_device_extern bool osl_texture(ccl_private ShaderGlobals *sg,
DeviceString filename,
ccl_private void *texture_handle,
- OSLTextureOptions *opt,
+ ccl_private OSLTextureOptions *opt,
float s,
float t,
float dsdx,
@@ -1557,13 +1557,14 @@ ccl_device_extern bool osl_texture(ccl_private ShaderGlobals *sg,
const float4 rgba = kernel_tex_image_interp(nullptr, id, s, 1.0f - t);
- result[0] = rgba.x;
+ if (nchannels > 0)
+ result[0] = rgba.x;
if (nchannels > 1)
result[1] = rgba.y;
if (nchannels > 2)
result[2] = rgba.z;
- if (nchannels > 3)
- result[3] = rgba.w;
+ if (alpha)
+ *alpha = rgba.w;
return true;
}
@@ -1571,7 +1572,7 @@ ccl_device_extern bool osl_texture(ccl_private ShaderGlobals *sg,
ccl_device_extern bool osl_texture3d(ccl_private ShaderGlobals *sg,
DeviceString filename,
ccl_private void *texture_handle,
- OSLTextureOptions *opt,
+ ccl_private OSLTextureOptions *opt,
ccl_private const float3 *P,
ccl_private const float3 *dPdx,
ccl_private const float3 *dPdy,
@@ -1594,13 +1595,14 @@ ccl_device_extern bool osl_texture3d(ccl_private ShaderGlobals *sg,
const float4 rgba = kernel_tex_image_interp_3d(nullptr, id, *P, INTERPOLATION_NONE);
- result[0] = rgba.x;
+ if (nchannels > 0)
+ result[0] = rgba.x;
if (nchannels > 1)
result[1] = rgba.y;
if (nchannels > 2)
result[2] = rgba.z;
- if (nchannels > 3)
- result[3] = rgba.w;
+ if (alpha)
+ *alpha = rgba.w;
return true;
}
@@ -1608,7 +1610,7 @@ ccl_device_extern bool osl_texture3d(ccl_private ShaderGlobals *sg,
ccl_device_extern bool osl_environment(ccl_private ShaderGlobals *sg,
DeviceString filename,
ccl_private void *texture_handle,
- OSLTextureOptions *opt,
+ ccl_private OSLTextureOptions *opt,
ccl_private const float3 *R,
ccl_private const float3 *dRdx,
ccl_private const float3 *dRdy,
@@ -1621,13 +1623,14 @@ ccl_device_extern bool osl_environment(ccl_private ShaderGlobals *sg,
ccl_private float *dalphay,
ccl_private void *errormessage)
{
- result[0] = 1.0f;
+ if (nchannels > 0)
+ result[0] = 1.0f;
if (nchannels > 1)
result[1] = 0.0f;
if (nchannels > 2)
result[2] = 1.0f;
- if (nchannels > 3)
- result[3] = 1.0f;
+ if (alpha)
+ *alpha = 1.0f;
return false;
}
More information about the Bf-blender-cvs
mailing list