Skip to content

TEX3D Blend: missing function hsv_to_rgb() #1502

Description

@unfa

Material Maker version:
1.7 stable

OS/device including version:
Operating System: MX Linux 23
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 7.0.9-1-liquorix-amd64 (64-bit)
Graphics Platform: X11
Processors: 24 × AMD Ryzen 9 3900X 12-Core Processor
Memory: 31.2 GiB of RAM
Graphics Processor: AMD Radeon RX 6800 XT
Manufacturer: Gigabyte Technology Co., Ltd.
Product Name: B550 AORUS ELITE V2

Issue description:

TL;DR

using a TEX3D Blend node in any Dynamic Sky material breaks 3D preview and exported shader shows an error: missing function hsv_to_rgb().

It seems there's a function naming convention mismatch.
Godot used to call such functions x2y (for example bytes2var) but with switch to Godot 4 the convention changed to name such conversion functions as x_to_y (bytes_to_var).

It seems that in material Maker's shader code both conventions are used and that causes an error where this function can't be found, because it's not called hsv_to_rgb, but hsv2rgb (using Godot 3 convention):

vec3 hsv2rgb(vec3 c) {
	vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
	vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
	return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

Whole Story

I've created a simple Dynamic Sky material:

{"connections":[{"from":"tex3d_uniform","from_port":0,"to":"tex3d_blend_v2","to_port":0},{"from":"tex3d_tones_range","from_port":0,"to":"tex3d_blend_v2","to_port":1},{"from":"tex3d_fbm_3","from_port":0,"to":"tex3d_translate","to_port":0},{"from":"tex3d_translate","from_port":0,"to":"tex3d_tones_range","to_port":0},{"from":"tex3d_blend_v2","from_port":0,"to":"Material","to_port":0}],"nodes":[{"name":"tex3d_fbm_3","node_position":{"x":-498.139099121094,"y":-20.2319011688232},"parameters":{"iterations":2.0,"noise":1,"persistence":0.35,"scale_x":20.0,"scale_y":1.0,"scale_z":24.0},"seed_int":0,"type":"tex3d_fbm_3"},{"generic_size":1,"name":"tex3d_translate","node_position":{"x":-275.005615234375,"y":-26.7638111114502},"parameters":{"x":0.0,"y":0.0,"z":"$time / 20.0"},"seed_int":0,"type":"tex3d_translate"},{"name":"tex3d_tones_range","node_position":{"x":-90.9114990234375,"y":-16.8075981140137},"parameters":{"contrast":0.5,"invert":false,"value":0.71,"width":0.31},"seed_int":0,"type":"tex3d_tones_range"},{"generic_size":1,"name":"tex3d_blend_v2","node_position":{"x":102.923095703125,"y":-73.2256164550781},"parameters":{"amount1":0.5,"blend_type1":3},"seed_int":0,"type":"tex3d_blend_v2"},{"name":"tex3d_uniform","node_position":{"x":-45.6531982421875,"y":-120.36962890625},"parameters":{"color":{"a":1.0,"b":1.0,"g":0.44683837890625,"r":0.37890625,"type":"Color"}},"seed_int":0,"type":"tex3d_uniform"},{"export_last_target":"Godot 4/Dynamic Sky","export_paths":{"Godot 4/Dynamic Sky":"/home/unfa/Documents/Projects/Godot/Experiments/MaterialMakerDynamicSky/dynamic_sky"},"name":"Material","node_position":{"x":325.786376953125,"y":-76.6015472412109},"parameters":{},"seed_int":0,"type":"material_dynamic_sky"}]}
Image

dynamic_sky.ptex.zip

After exporting it to Godot 4 I got an error with the generated shader:

Error at line 84: No matching function found for: 'rgb_to_hsv'.
Image

I have tried to fix this by hand and copied rghb2hsv and hsv2rgb functions from elsewhere in Material Maker) as it seems both functions are not found, pasted them on top of the generated shader but then got another error:

Error at line 168: Too few arguments for "blend3d_overlay(vec3, vec3, vec3, float)" call. Expected at least 4 but received 3.
Image

So it seems there's more problems with TEX3D Blend than just the hsv<->rgb conversion method naming.

I managed to fix this problem too however and got my fist dynamic sky material working in Godot 4!

Had to add uv as first parameter in call to blend3d_overlay in this blend3d_hard_light function:

BEFORE:

vec3 blend3d_hard_light(vec3 uv, vec3 c1, vec3 c2, float opacity) {
	return opacity*0.5*(c1*c2+blend3d_overlay(c1, c2, 1.0)) + (1.0-opacity)*c2;
}

AFTER:

vec3 blend3d_hard_light(vec3 uv, vec3 c1, vec3 c2, float opacity) {
	return opacity*0.5*(c1*c2+blend3d_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;
}
Image Image

Steps to reproduce:

  1. Create a new Material Maker project
  2. Right-click on the Output node and change it's type to Dynamic Sky Material
Image
  1. Add a Tex3D FBM node and a Tex3D Blend node
  2. Connect the nodes like so:
Image
  1. Note that the sky preview is broken at this point
  2. Export the material to Godot 4 using Project > Export >Godot 4 from main menu
  3. Put into Godot's Environment Sky slot
  4. Look at the shader error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions