Code improvements + Mix node #30

Merged
Bogdan Nagirniak merged 18 commits from BogdanNagirniak/blender:matx-code-improvements into matx-export-material 2023-09-22 18:23:13 +02:00
Showing only changes of commit 51cfa8f267 - Show all commits

View File

@ -240,46 +240,42 @@ NODE_SHADER_MATERIALX_BEGIN
detail_scale = detail_scale * val(10.0f); detail_scale = detail_scale * val(10.0f);
NodeItem pos = vector * scale; NodeItem pos = vector * scale;
//pos = (pos + val(0.000001f)) * val(0.999999f);
NodeItem fractal = create_node("fractal3d", NodeItem fractal = create_node("fractal3d",
NodeItem::Type::Float, NodeItem::Type::Float,
{{"position", pos}, {{"position", pos},
{"octaves", val(int(detail.value->asA<float>()))}, {"octaves", val(int(detail.value->asA<float>()))},
{"lacunarity", val(2.0f)}}); {"lacunarity", val(2.0f)}});
NodeItem n = val(0.0f);
NodeItem value = val(0.0f); NodeItem value = val(0.0f);
switch (tex->wave_type) { switch (tex->wave_type) {
case SHD_WAVE_BANDS: case SHD_WAVE_BANDS:
switch (tex->bands_direction) { switch (tex->bands_direction) {
case SHD_WAVE_BANDS_DIRECTION_X: case SHD_WAVE_BANDS_DIRECTION_X:
n = pos[0] * val(20.0f); value = pos[0] * val(20.0f);
break; break;
case SHD_WAVE_BANDS_DIRECTION_Y: case SHD_WAVE_BANDS_DIRECTION_Y:
n = pos[1] * val(20.0f); value = pos[1] * val(20.0f);
break; break;
case SHD_WAVE_BANDS_DIRECTION_Z: case SHD_WAVE_BANDS_DIRECTION_Z:
n = pos[2] * val(20.0f); value = pos[2] * val(20.0f);
break; break;
case SHD_WAVE_BANDS_DIRECTION_DIAGONAL: case SHD_WAVE_BANDS_DIRECTION_DIAGONAL:
n = (pos[0] + pos[1] + pos[2]) * val(10.0f); value = (pos[0] + pos[1] + pos[2]) * val(10.0f);
break; break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
} }
break; break;
case SHD_WAVE_RINGS: case SHD_WAVE_RINGS:
NodeItem rp = pos; NodeItem rpos = pos;
switch (tex->rings_direction) { switch (tex->rings_direction) {
case SHD_WAVE_RINGS_DIRECTION_X: case SHD_WAVE_RINGS_DIRECTION_X:
rp = rp * val(MaterialX::Vector3(0.0f, 1.0f, 1.0f)); rpos = pos * val(MaterialX::Vector3(0.0f, 1.0f, 1.0f));
break; break;
case SHD_WAVE_RINGS_DIRECTION_Y: case SHD_WAVE_RINGS_DIRECTION_Y:
rp = rp * val(MaterialX::Vector3(1.0f, 0.0f, 1.0f)); rpos = pos * val(MaterialX::Vector3(1.0f, 0.0f, 1.0f));
break; break;
case SHD_WAVE_RINGS_DIRECTION_Z: case SHD_WAVE_RINGS_DIRECTION_Z:
rp = rp * val(MaterialX::Vector3(1.0f, 1.0f, 0.0f)); rpos = pos * val(MaterialX::Vector3(1.0f, 1.0f, 0.0f));
break; break;
case SHD_WAVE_RINGS_DIRECTION_SPHERICAL: case SHD_WAVE_RINGS_DIRECTION_SPHERICAL:
/* Ignore. */ /* Ignore. */
@ -287,27 +283,28 @@ NODE_SHADER_MATERIALX_BEGIN
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
} }
n = rp.dotproduct(rp).sqrt() * val(20.0f); value = rpos.length() * val(20.0f);
break; break;
} }
n = n + phase_offset + distortion * detail_scale * fractal; value = value + phase_offset + distortion * detail_scale * fractal;
NodeItem res = empty();
switch (tex->wave_profile) { switch (tex->wave_profile) {
case SHD_WAVE_PROFILE_SIN: case SHD_WAVE_PROFILE_SIN:
value = val(0.5f) + val(0.5f) * (n - val(float(M_PI_2))).sin(); res = val(0.5f) + val(0.5f) * (value - val(float(M_PI_2))).sin();
break; break;
case SHD_WAVE_PROFILE_SAW: case SHD_WAVE_PROFILE_SAW:
n = n / val(float(M_PI * 2.0f)); value = value / val(float(M_PI * 2.0f));
value = n - n.floor(); res = value - value.floor();
break; break;
case SHD_WAVE_PROFILE_TRI: case SHD_WAVE_PROFILE_TRI:
n = n / val(float(M_PI * 2.0f)); value = value / val(float(M_PI * 2.0f));
value = (n - (n + val(0.5f)).floor()).abs() * val(2.0f); res = (value - (value + val(0.5f)).floor()).abs() * val(2.0f);
break; break;
default: default:
BLI_assert_unreachable(); BLI_assert_unreachable();
} }
return value; return res;
} }
#endif #endif
NODE_SHADER_MATERIALX_END NODE_SHADER_MATERIALX_END