mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-09 05:39:38 +01:00
Added support for shader materials and added a tesselated sphere in preview shapes
This commit is contained in:
parent
3bd0cf228a
commit
f136046082
@ -2,8 +2,6 @@ tool
|
|||||||
extends MMGenBase
|
extends MMGenBase
|
||||||
class_name MMGenMaterial
|
class_name MMGenMaterial
|
||||||
|
|
||||||
var texture_list
|
|
||||||
|
|
||||||
var material : SpatialMaterial
|
var material : SpatialMaterial
|
||||||
var generated_textures = {}
|
var generated_textures = {}
|
||||||
|
|
||||||
@ -25,8 +23,7 @@ const TEXTURE_SIZE_MAX = 12 # 4096x4096
|
|||||||
const TEXTURE_SIZE_DEFAULT = 10 # 1024x1024
|
const TEXTURE_SIZE_DEFAULT = 10 # 1024x1024
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
texture_list = TEXTURE_LIST
|
for t in TEXTURE_LIST:
|
||||||
for t in texture_list:
|
|
||||||
generated_textures[t.texture] = null
|
generated_textures[t.texture] = null
|
||||||
material = SpatialMaterial.new()
|
material = SpatialMaterial.new()
|
||||||
|
|
||||||
@ -82,12 +79,19 @@ func set_parameter(p, v) -> void:
|
|||||||
update_preview()
|
update_preview()
|
||||||
|
|
||||||
func source_changed(input_index : int) -> void:
|
func source_changed(input_index : int) -> void:
|
||||||
|
for t in TEXTURE_LIST:
|
||||||
|
if t.has("port") and t.port == input_index:
|
||||||
|
generated_textures[t.texture] = null
|
||||||
|
elif t.has("ports") and t.ports.has(input_index):
|
||||||
|
generated_textures[t.texture] = null
|
||||||
update_preview()
|
update_preview()
|
||||||
|
|
||||||
func render_textures(renderer : MMGenRenderer) -> void:
|
func render_textures(renderer : MMGenRenderer) -> void:
|
||||||
for t in texture_list:
|
for t in TEXTURE_LIST:
|
||||||
var texture = null
|
var texture = null
|
||||||
if t.has("port"):
|
if t.has("port"):
|
||||||
|
if generated_textures[t.texture] != null:
|
||||||
|
continue
|
||||||
var source = get_source(t.port)
|
var source = get_source(t.port)
|
||||||
if source != null:
|
if source != null:
|
||||||
var result = source.generator.render(source.output_index, renderer, get_image_size())
|
var result = source.generator.render(source.output_index, renderer, get_image_size())
|
||||||
@ -152,6 +156,7 @@ func get_generated_texture(slot, file_prefix = null) -> ImageTexture:
|
|||||||
func update_spatial_material(m, file_prefix = null) -> void:
|
func update_spatial_material(m, file_prefix = null) -> void:
|
||||||
var texture
|
var texture
|
||||||
|
|
||||||
|
if m is SpatialMaterial:
|
||||||
# Make the material double-sided for better visiblity in the preview
|
# Make the material double-sided for better visiblity in the preview
|
||||||
m.params_cull_mode = SpatialMaterial.CULL_DISABLED
|
m.params_cull_mode = SpatialMaterial.CULL_DISABLED
|
||||||
|
|
||||||
@ -198,9 +203,24 @@ func update_spatial_material(m, file_prefix = null) -> void:
|
|||||||
m.depth_texture = texture
|
m.depth_texture = texture
|
||||||
else:
|
else:
|
||||||
m.depth_enabled = false
|
m.depth_enabled = false
|
||||||
|
else:
|
||||||
|
m.set_shader_param("albedo", parameters.albedo_color)
|
||||||
|
m.set_shader_param("texture_albedo", get_generated_texture("albedo", file_prefix))
|
||||||
|
m.set_shader_param("metallic", parameters.metallic)
|
||||||
|
m.set_shader_param("roughness", parameters.roughness)
|
||||||
|
m.set_shader_param("texture_metallic", get_generated_texture("orm", file_prefix))
|
||||||
|
m.set_shader_param("metallic_texture_channel", PoolRealArray([0.0, 0.0, 1.0, 0.0]))
|
||||||
|
m.set_shader_param("texture_roughness", get_generated_texture("orm", file_prefix))
|
||||||
|
m.set_shader_param("roughness_texture_channel", PoolRealArray([0.0, 1.0, 0.0, 0.0]))
|
||||||
|
m.set_shader_param("emission_energy", parameters.emission_energy)
|
||||||
|
m.set_shader_param("texture_emission", get_generated_texture("emission", file_prefix))
|
||||||
|
m.set_shader_param("normal_scale", parameters.normal_scale)
|
||||||
|
m.set_shader_param("texture_normal", get_generated_texture("normal_texture", file_prefix))
|
||||||
|
m.set_shader_param("depth_scale", parameters.depth_scale * 0.2)
|
||||||
|
m.set_shader_param("texture_depth", get_generated_texture("depth_texture", file_prefix))
|
||||||
|
|
||||||
func export_textures(prefix, editor_interface = null) -> SpatialMaterial:
|
func export_textures(prefix, editor_interface = null) -> SpatialMaterial:
|
||||||
for t in texture_list:
|
for t in TEXTURE_LIST:
|
||||||
var texture = generated_textures[t.texture]
|
var texture = generated_textures[t.texture]
|
||||||
if texture != null:
|
if texture != null:
|
||||||
var image = texture.get_data()
|
var image = texture.get_data()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=13 format=2]
|
[gd_scene load_steps=17 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://rodz_labs_logo.png" type="Texture" id=1]
|
[ext_resource path="res://rodz_labs_logo.png" type="Texture" id=1]
|
||||||
|
|
||||||
@ -17,6 +17,8 @@ uv1_scale = Vector3( 2, 2, 2 )
|
|||||||
[sub_resource type="SphereMesh" id=5]
|
[sub_resource type="SphereMesh" id=5]
|
||||||
radius = 1.5
|
radius = 1.5
|
||||||
height = 3.0
|
height = 3.0
|
||||||
|
radial_segments = 512
|
||||||
|
rings = 256
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=6]
|
[sub_resource type="SpatialMaterial" id=6]
|
||||||
albedo_texture = ExtResource( 1 )
|
albedo_texture = ExtResource( 1 )
|
||||||
@ -26,23 +28,95 @@ albedo_texture = ExtResource( 1 )
|
|||||||
uv1_scale = Vector3( 2, 2, 2 )
|
uv1_scale = Vector3( 2, 2, 2 )
|
||||||
uv1_offset = Vector3( 0, 0.5, 0 )
|
uv1_offset = Vector3( 0, 0.5, 0 )
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id=8]
|
[sub_resource type="PrismMesh" id=8]
|
||||||
size = Vector2( 3, 3 )
|
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=9]
|
[sub_resource type="SpatialMaterial" id=9]
|
||||||
albedo_texture = ExtResource( 1 )
|
albedo_texture = ExtResource( 1 )
|
||||||
|
uv1_scale = Vector3( 3, 2, 2 )
|
||||||
|
|
||||||
[sub_resource type="PlaneMesh" id=10]
|
[sub_resource type="PlaneMesh" id=10]
|
||||||
size = Vector2( 12, 12 )
|
size = Vector2( 3, 3 )
|
||||||
|
|
||||||
[sub_resource type="SpatialMaterial" id=11]
|
[sub_resource type="SpatialMaterial" id=11]
|
||||||
albedo_texture = ExtResource( 1 )
|
albedo_texture = ExtResource( 1 )
|
||||||
|
|
||||||
|
[sub_resource type="PlaneMesh" id=12]
|
||||||
|
size = Vector2( 12, 12 )
|
||||||
|
|
||||||
|
[sub_resource type="SpatialMaterial" id=13]
|
||||||
|
albedo_texture = ExtResource( 1 )
|
||||||
uv1_scale = Vector3( 4, 4, 4 )
|
uv1_scale = Vector3( 4, 4, 4 )
|
||||||
|
|
||||||
|
[sub_resource type="Shader" id=14]
|
||||||
|
code = "shader_type spatial;
|
||||||
|
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx,skip_vertex_transform;
|
||||||
|
uniform vec4 albedo : hint_color;
|
||||||
|
uniform sampler2D texture_albedo : hint_albedo;
|
||||||
|
uniform float specular;
|
||||||
|
uniform float metallic;
|
||||||
|
uniform float roughness : hint_range(0,1);
|
||||||
|
uniform float point_size : hint_range(0,128);
|
||||||
|
uniform sampler2D texture_metallic : hint_white;
|
||||||
|
uniform vec4 metallic_texture_channel;
|
||||||
|
uniform sampler2D texture_roughness : hint_white;
|
||||||
|
uniform vec4 roughness_texture_channel;
|
||||||
|
uniform sampler2D texture_emission : hint_black_albedo;
|
||||||
|
uniform vec4 emission : hint_color;
|
||||||
|
uniform float emission_energy;
|
||||||
|
uniform sampler2D texture_normal : hint_normal;
|
||||||
|
uniform float normal_scale : hint_range(-16,16);
|
||||||
|
uniform sampler2D texture_depth : hint_white;
|
||||||
|
uniform float depth_scale : hint_range(0,1);
|
||||||
|
uniform vec3 uv1_scale;
|
||||||
|
uniform vec3 uv1_offset;
|
||||||
|
uniform vec3 uv2_scale;
|
||||||
|
uniform vec3 uv2_offset;
|
||||||
|
|
||||||
|
void vertex() {
|
||||||
|
VERTEX = (MODELVIEW_MATRIX * vec4(VERTEX+NORMAL*depth_scale*(1.0-texture(texture_depth, UV).r), 1.0)).xyz;
|
||||||
|
UV=UV*uv1_scale.xy+uv1_offset.xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
vec2 base_uv = UV;
|
||||||
|
vec4 albedo_tex = texture(texture_albedo,base_uv);
|
||||||
|
ALBEDO = albedo.rgb * albedo_tex.rgb;
|
||||||
|
float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);
|
||||||
|
METALLIC = metallic_tex * metallic;
|
||||||
|
float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);
|
||||||
|
ROUGHNESS = roughness_tex * roughness;
|
||||||
|
SPECULAR = specular;
|
||||||
|
NORMALMAP = texture(texture_normal,base_uv).rgb;
|
||||||
|
NORMALMAP_DEPTH = normal_scale;
|
||||||
|
vec3 emission_tex = texture(texture_emission,base_uv).rgb;
|
||||||
|
EMISSION = (emission.rgb+emission_tex)*emission_energy;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id=15]
|
||||||
|
shader = SubResource( 14 )
|
||||||
|
shader_param/albedo = Color( 1, 1, 1, 1 )
|
||||||
|
shader_param/specular = 0.5
|
||||||
|
shader_param/metallic = 0.0
|
||||||
|
shader_param/roughness = 1.0
|
||||||
|
shader_param/point_size = 1.0
|
||||||
|
shader_param/metallic_texture_channel = Plane( 1, 0, 0, 0 )
|
||||||
|
shader_param/roughness_texture_channel = Plane( 1, 0, 0, 0 )
|
||||||
|
shader_param/emission = Color( 0, 0, 0, 1 )
|
||||||
|
shader_param/emission_energy = 1.0
|
||||||
|
shader_param/normal_scale = 1.0
|
||||||
|
shader_param/depth_scale = null
|
||||||
|
shader_param/uv1_scale = Vector3( 1, 1, 1 )
|
||||||
|
shader_param/uv1_offset = Vector3( 0, 0, 0 )
|
||||||
|
shader_param/uv2_scale = Vector3( 1, 1, 1 )
|
||||||
|
shader_param/uv2_offset = Vector3( 0, 0, 0 )
|
||||||
|
shader_param/texture_albedo = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Objects" type="Spatial"]
|
[node name="Objects" type="Spatial"]
|
||||||
transform = Transform( -0.685898, 0, 0.727691, 0, 1, 0, -0.727691, 0, -0.685898, 0, 0, 0 )
|
transform = Transform( -0.685898, 0, 0.727691, 0, 1, 0, -0.727691, 0, -0.685898, 0, 0, 0 )
|
||||||
|
|
||||||
[node name="Cube" type="MeshInstance" parent="."]
|
[node name="Cube" type="MeshInstance" parent="."]
|
||||||
|
visible = false
|
||||||
mesh = SubResource( 1 )
|
mesh = SubResource( 1 )
|
||||||
material/0 = SubResource( 2 )
|
material/0 = SubResource( 2 )
|
||||||
|
|
||||||
@ -61,12 +135,22 @@ visible = false
|
|||||||
mesh = SubResource( 5 )
|
mesh = SubResource( 5 )
|
||||||
material/0 = SubResource( 7 )
|
material/0 = SubResource( 7 )
|
||||||
|
|
||||||
[node name="Quad" type="MeshInstance" parent="."]
|
[node name="Prism" type="MeshInstance" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
mesh = SubResource( 8 )
|
mesh = SubResource( 8 )
|
||||||
material/0 = SubResource( 9 )
|
material/0 = SubResource( 9 )
|
||||||
|
|
||||||
[node name="Plane" type="MeshInstance" parent="."]
|
[node name="Quad" type="MeshInstance" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
mesh = SubResource( 10 )
|
mesh = SubResource( 10 )
|
||||||
material/0 = SubResource( 11 )
|
material/0 = SubResource( 11 )
|
||||||
|
|
||||||
|
[node name="Plane" type="MeshInstance" parent="."]
|
||||||
|
visible = false
|
||||||
|
mesh = SubResource( 12 )
|
||||||
|
material/0 = SubResource( 13 )
|
||||||
|
|
||||||
|
[node name="SphereTess" type="MeshInstance" parent="."]
|
||||||
|
visible = false
|
||||||
|
mesh = SubResource( 5 )
|
||||||
|
material/0 = SubResource( 15 )
|
||||||
|
Loading…
Reference in New Issue
Block a user