diff --git a/addons/material_maker/nodes/material.mmg b/addons/material_maker/nodes/material.mmg index 5e6adfd75..e2fd0376f 100644 --- a/addons/material_maker/nodes/material.mmg +++ b/addons/material_maker/nodes/material.mmg @@ -675,6 +675,51 @@ } ] }, + "Imaginando VS 2": { + "custom": [ + "func process_option_vs2(s : String, is_declaration : bool = false) -> String:", + "\ts = s.replace(\"elapsed_time\", \"time\")", + "\ts = s.replace(\"uniform vec2\", \"const vec2\")", + "\ts = s.replace(\"uniform vec3\", \"const vec3\")", + "\ts = s.replace(\"uniform mat2\", \"const mat2\")", + "\treturn s" + ], + "export_extension": "vs2.frag", + "files": [ + { + "file_name": "$(path_prefix).vs2.frag", + "template": [ + "/*", + "{", + "\t\"author\": \"\",", + "\t\"color\": \"white\",", + "\t\"movement\": true,", + "\t\"name\": \"$(file_prefix)\",", + "\t\"parameters\": [],", + "\t\"url\": \"\",", + "\t\"uuid\": \"$uid(0)\"", + "}", + "*/", + "// mm2vs: exported-by=material-maker | target=imaginando-vs2", + "// mm2vs: finalize with `mm2vs convert ` to normalize the uuid and lift exposed parameters.", + "$definitions float_uniform_to_const,vs2", + "void main() {", + "\tfloat _seed_variation_ = 0.0;", + "\tvec4 _controlled_variation_ = vec4(0.0);", + "\tvec2 uv = fract(texCoord);", + "$begin_generate vs2", + "\tvec3 mm2vs_albedo = $albedo_tex(uv) * vec3($(param:albedo_color.r), $(param:albedo_color.g), $(param:albedo_color.b));", + "\tvec3 mm2vs_emission = $emission_tex(uv) * $(param:emission_energy);", + "\tfloat mm2vs_opacity = $opacity_tex(uv) * $(param:albedo_color.a);", + "\tvec4 generatedColor = vec4(mm2vs_albedo + mm2vs_emission, mm2vs_opacity);", + "$end_generate", + "\tfragColor = vec4(generatedColor.rgb, generatedColor.a * alpha);", + "}" + ], + "type": "template" + } + ] + }, "Unity/3D": { "export_extension": "mat", "files": [ diff --git a/addons/material_maker/nodes/material_unlit.mmg b/addons/material_maker/nodes/material_unlit.mmg index 4e21c74c7..9ed418771 100644 --- a/addons/material_maker/nodes/material_unlit.mmg +++ b/addons/material_maker/nodes/material_unlit.mmg @@ -243,6 +243,48 @@ } ] }, + "Imaginando VS 2": { + "custom": [ + "func process_option_vs2(s : String, is_declaration : bool = false) -> String:", + "\ts = s.replace(\"elapsed_time\", \"time\")", + "\ts = s.replace(\"uniform vec2\", \"const vec2\")", + "\ts = s.replace(\"uniform vec3\", \"const vec3\")", + "\ts = s.replace(\"uniform mat2\", \"const mat2\")", + "\treturn s" + ], + "export_extension": "vs2.frag", + "files": [ + { + "file_name": "$(path_prefix).vs2.frag", + "template": [ + "/*", + "{", + "\t\"author\": \"\",", + "\t\"color\": \"white\",", + "\t\"movement\": true,", + "\t\"name\": \"$(file_prefix)\",", + "\t\"parameters\": [],", + "\t\"url\": \"\",", + "\t\"uuid\": \"$uid(0)\"", + "}", + "*/", + "// mm2vs: exported-by=material-maker | target=imaginando-vs2", + "// mm2vs: finalize with `mm2vs convert ` to normalize the uuid and lift exposed parameters.", + "$definitions float_uniform_to_const,vs2", + "void main() {", + "\tfloat _seed_variation_ = 0.0;", + "\tvec4 _controlled_variation_ = vec4(0.0);", + "\tvec2 uv = fract(texCoord);", + "$begin_generate vs2", + "\tvec4 generatedColor = $color_tex(uv);", + "$end_generate", + "\tfragColor = vec4(generatedColor.rgb, generatedColor.a * alpha);", + "}" + ], + "type": "template" + } + ] + }, "Unity": { "export_extension": "mat", "files": [ diff --git a/material_maker/doc/export.rst b/material_maker/doc/export.rst index 1af3b9ffb..777fa9561 100644 --- a/material_maker/doc/export.rst +++ b/material_maker/doc/export.rst @@ -26,6 +26,30 @@ Godot game engine When exporting for the Godot game engine, Material Maker will generate a .tres file that describes a fully configured SpatialMaterial. +Imaginando VS 2 +----------------- + +When exporting for `Imaginando VS 2 `_ +(Visual Synthesizer), Material Maker generates a single ``.vs2.frag`` GLSL fragment +shader that can be imported with the Import button of VS 2's Material Browser. + +The file contains the generated code for the material's albedo, emission and +opacity channels (VS 2 layers are unlit, so lighting inputs such as roughness or +normal are not exported), adapted to VS 2's predeclared environment (``time``, +``alpha``, ``color``, ``resolution``, ``texCoord``, ``fragColor``) and preceded +by the JSON manifest VS 2 requires. Named parameters referenced in the exported +branch are included with their current values. + +Two limitations are worth knowing: + +* the manifest uuid is generated without hyphens; VS 2 uses the hyphenated form, + which can be obtained by inserting hyphens in 8-4-4-4-12 grouping (the + companion ``mm2vs`` tool does this automatically and can also turn named + parameters into live VS 2 controls), +* materials that use buffer-based nodes (blur, warp, …) cannot be expressed as a + single VS 2 fragment shader; the exported file will reference textures that VS + 2 cannot provide. + Unity game engine -----------------