Skip to content

Commit

Permalink
Clean up ColorRamp
Browse files Browse the repository at this point in the history
  • Loading branch information
denghilbert committed Jul 24, 2023
1 parent 8823a98 commit 55d1c61
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/textures/color_ramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ ColorRamp texture (:monosp:`color_ramp`)
- ``nearest``: disable filtering and interpolation. In this mode, the plugin
performs nearest neighbor lookups of texture values.
* - wrap_mode
- |string|
- Controls the behavior of texture evaluations that fall outside of the
:math:`[0, 1]` range. The following options are currently available:
- ``repeat`` (default): tile the texture infinitely.
* - num_band
- |integer|
- Specifies the number of color bands used in ColorRamp
- ``mirror``: mirror the texture along its boundaries.
* - posx
- |float|
- Specifies the position of color bands used in ColorRamp
- x starts from 0 to num_band - 1
- Used for interpolation factor
- ``clamp``: clamp coordinates to the edge of the texture.
* - colorx
- |Color3f|
- Specifies the 3 channels of color bands used in ColorRamp
- Used for interpolation color results
* - raw
- |bool|
Expand Down Expand Up @@ -99,18 +103,33 @@ at all.
.. tabs::
.. code-tab:: xml
:name: bitmap-texture
:name: color-ramp
<texture type="bitmap">
<texture type="color_ramp">
<string name="filename" value="texture.png"/>
<string name="wrap_mode" value="mirror"/>
<string name="mode" value="linear"/>
<float name="pos0" value="0.040000"/>
<rgb value="0.602237 0.482636 0.000000" name="color0"/>
<float name="pos1" value="0.084091"/>
<rgb value="0.019626 0.077920 0.174928" name="color1"/>
</texture>
.. code-tab:: python
'type': 'bitmap',
'type': 'color_ramp',
'filename': 'texture.png',
'wrap_mode': 'mirror'
"mode": "linear",
"num_band": 2,
"pos0": 0.0,
"pos1": 1.0,
"color0": {
'type': 'rgb',
'value': [0.0, 0.0, 0.0]
},
"color1": {
'type': 'rgb',
'value': [1.0, 1.0, 1.0]
},
*/

Expand Down Expand Up @@ -329,7 +348,6 @@ class ColorRamp final : public Texture<Float, Spectrum> {

}

// m_base_color in principled
UnpolarizedSpectrum eval(const SurfaceInteraction3f &si,
Mask active) const override {
MI_MASKED_FUNCTION(ProfilerPhase::TextureEvaluate, active);
Expand Down Expand Up @@ -368,8 +386,6 @@ class ColorRamp final : public Texture<Float, Spectrum> {
}
}

// m_roughness, m_anisotropic, m_sheen, m_sheen_tint, m_spec_trans, m_flatness,
// m_spec_tint, m_clearcoat, m_clearcoat, m_metallic in principled
Float eval_1(const SurfaceInteraction3f &si,
Mask active = true) const override {

Expand Down Expand Up @@ -672,7 +688,7 @@ class ColorRamp final : public Texture<Float, Spectrum> {
m_name);
}

/// Construct 2D distribution upon first access, avoid races
// Construct 2D distribution upon first access, avoid races
MI_INLINE void init_distr() const {
std::lock_guard<std::mutex> lock(m_mutex);
if (!m_distr2d) {
Expand All @@ -681,7 +697,7 @@ class ColorRamp final : public Texture<Float, Spectrum> {
}
}

// Calculate the weight of cardinal and B-splines interpolation
// Calculate the weight of cardinal and B-spline interpolation
// Borrow from Blender
MI_INLINE void key_curve_position_weights(Float t, Float *data, std::string type) const {
if(type == "cardinal") {
Expand Down Expand Up @@ -1356,7 +1372,6 @@ class ColorRamp final : public Texture<Float, Spectrum> {
ref<Bitmap> m_bitmap;
std::string m_name;


// Single factor
ScalarFloat m_factor;
// Bitmap or color interpolator
Expand All @@ -1378,4 +1393,4 @@ class ColorRamp final : public Texture<Float, Spectrum> {
MI_IMPLEMENT_CLASS_VARIANT(ColorRamp, Texture)
MI_EXPORT_PLUGIN(ColorRamp, "Color Ramp")

NAMESPACE_END(mitsuba)
NAMESPACE_END(mitsuba)

0 comments on commit 55d1c61

Please sign in to comment.