Set Material Param nodes
This commit is contained in:
parent
2fdcd7c520
commit
13731ae634
39
Sources/armory/logicnode/SetMaterialImageParamNode.hx
Normal file
39
Sources/armory/logicnode/SetMaterialImageParamNode.hx
Normal file
|
@ -0,0 +1,39 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.data.MaterialData;
|
||||
import iron.object.Object;
|
||||
|
||||
class SetMaterialImageParamNode extends LogicNode {
|
||||
|
||||
static var registered = false;
|
||||
static var mat:MaterialData = null;
|
||||
static var node = "";
|
||||
static var image:kha.Image = null;
|
||||
|
||||
public function new(tree:LogicTree) {
|
||||
super(tree);
|
||||
if (!registered) {
|
||||
registered = true;
|
||||
iron.object.Uniforms.externalTextureLinks.push(textureLink);
|
||||
}
|
||||
}
|
||||
|
||||
override function run() {
|
||||
mat = inputs[1].get();
|
||||
node = inputs[2].get();
|
||||
var name = inputs[3].get();
|
||||
iron.data.Data.getImage(name, function(img:kha.Image) {
|
||||
image = img;
|
||||
});
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
static function textureLink(object:Object, mat:MaterialData, link:String):kha.Image {
|
||||
if (link == node) {
|
||||
return image;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
36
Sources/armory/logicnode/SetMaterialRgbParamNode.hx
Normal file
36
Sources/armory/logicnode/SetMaterialRgbParamNode.hx
Normal file
|
@ -0,0 +1,36 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.data.MaterialData;
|
||||
import iron.object.Object;
|
||||
|
||||
class SetMaterialRgbParamNode extends LogicNode {
|
||||
|
||||
static var registered = false;
|
||||
static var mat:MaterialData = null;
|
||||
static var node = "";
|
||||
static var col:Vec4 = null;
|
||||
|
||||
public function new(tree:LogicTree) {
|
||||
super(tree);
|
||||
if (!registered) {
|
||||
registered = true;
|
||||
iron.object.Uniforms.externalVec3Links.push(vec3Link);
|
||||
}
|
||||
}
|
||||
|
||||
override function run() {
|
||||
mat = inputs[1].get();
|
||||
node = inputs[2].get();
|
||||
col = inputs[3].get();
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
static function vec3Link(object:Object, mat:MaterialData, link:String):iron.math.Vec4 {
|
||||
if (link == node) {
|
||||
return col;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
36
Sources/armory/logicnode/SetMaterialValueParamNode.hx
Normal file
36
Sources/armory/logicnode/SetMaterialValueParamNode.hx
Normal file
|
@ -0,0 +1,36 @@
|
|||
package armory.logicnode;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.data.MaterialData;
|
||||
import iron.object.Object;
|
||||
|
||||
class SetMaterialValueParamNode extends LogicNode {
|
||||
|
||||
static var registered = false;
|
||||
static var mat:MaterialData = null;
|
||||
static var node = "";
|
||||
static var value:Null<kha.FastFloat> = null;
|
||||
|
||||
public function new(tree:LogicTree) {
|
||||
super(tree);
|
||||
if (!registered) {
|
||||
registered = true;
|
||||
iron.object.Uniforms.externalFloatLinks.push(floatLink);
|
||||
}
|
||||
}
|
||||
|
||||
override function run() {
|
||||
mat = inputs[1].get();
|
||||
node = inputs[2].get();
|
||||
value = inputs[3].get();
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
static function floatLink(object:Object, mat:MaterialData, link:String):Null<kha.FastFloat> {
|
||||
if (link == node) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package armory.object;
|
||||
|
||||
import iron.Scene;
|
||||
import iron.object.Object;
|
||||
import iron.data.MaterialData;
|
||||
import iron.math.Vec4;
|
||||
|
||||
// Structure for setting shader uniforms
|
||||
|
@ -12,7 +14,7 @@ class Uniforms {
|
|||
iron.object.Uniforms.externalFloatLinks = [floatLink];
|
||||
}
|
||||
|
||||
public static function textureLink(link:String):kha.Image {
|
||||
public static function textureLink(object:Object, mat:MaterialData, link:String):kha.Image {
|
||||
if (link == "_smaaSearch") {
|
||||
return Scene.active.embedded.get('smaa_search.png');
|
||||
}
|
||||
|
@ -41,7 +43,7 @@ class Uniforms {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function vec3Link(link:String):iron.math.Vec4 {
|
||||
public static function vec3Link(object:Object, mat:MaterialData, link:String):iron.math.Vec4 {
|
||||
var v:Vec4 = null;
|
||||
#if arm_hosek
|
||||
if (link == "_hosekA") {
|
||||
|
@ -171,7 +173,7 @@ class Uniforms {
|
|||
return v;
|
||||
}
|
||||
|
||||
public static function floatLink(link:String):Null<kha.FastFloat> {
|
||||
public static function floatLink(object:Object, mat:MaterialData, link:String):Null<kha.FastFloat> {
|
||||
#if rp_dynres
|
||||
if (link == "_dynamicScale") {
|
||||
return armory.renderpath.DynamicResolutionScale.dynamicScale;
|
||||
|
|
|
@ -139,10 +139,14 @@ def parse_shader(sres, c, con, defs, lines, parse_attributes):
|
|||
# uniform layout(RGBA8) image3D myname;
|
||||
if s[1].startswith('layout'):
|
||||
ctype = s[2]
|
||||
cid = s[3][:-1]
|
||||
cid = s[3]
|
||||
if cid[-1] == ';':
|
||||
cid = cid[:-1]
|
||||
else:
|
||||
ctype = s[1]
|
||||
cid = s[2][:-1]
|
||||
cid = s[2]
|
||||
if cid[-1] == ';':
|
||||
cid = cid[:-1]
|
||||
|
||||
found = False # Unique check
|
||||
if ctype == 'sampler2D' or ctype == 'sampler2DShadow' or ctype == 'sampler3D' or ctype == 'samplerCube' or ctype == 'image2D' or ctype == 'uimage2D' or ctype == 'image3D' or ctype == 'uimage3D': # Texture unit
|
||||
|
|
19
blender/arm/logicnode/action_set_material_image_param.py
Normal file
19
blender/arm/logicnode/action_set_material_image_param.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class SetMaterialImageParamNode(Node, ArmLogicTreeNode):
|
||||
'''Set material image param node'''
|
||||
bl_idname = 'LNSetMaterialImageParamNode'
|
||||
bl_label = 'Set Material Image Param'
|
||||
bl_icon = 'GAME'
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('NodeSocketShader', 'Material')
|
||||
self.inputs.new('NodeSocketString', 'Node')
|
||||
self.inputs.new('NodeSocketString', 'Image')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
|
||||
add_node(SetMaterialImageParamNode, category='Action')
|
19
blender/arm/logicnode/action_set_material_rgb_param.py
Normal file
19
blender/arm/logicnode/action_set_material_rgb_param.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class SetMaterialRgbParamNode(Node, ArmLogicTreeNode):
|
||||
'''Set material rgb param node'''
|
||||
bl_idname = 'LNSetMaterialRgbParamNode'
|
||||
bl_label = 'Set Material RGB Param'
|
||||
bl_icon = 'GAME'
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('NodeSocketShader', 'Material')
|
||||
self.inputs.new('NodeSocketString', 'Node')
|
||||
self.inputs.new('NodeSocketColor', 'Color')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
|
||||
add_node(SetMaterialRgbParamNode, category='Action')
|
19
blender/arm/logicnode/action_set_material_value_param.py
Normal file
19
blender/arm/logicnode/action_set_material_value_param.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import bpy
|
||||
from bpy.props import *
|
||||
from bpy.types import Node, NodeSocket
|
||||
from arm.logicnode.arm_nodes import *
|
||||
|
||||
class SetMaterialValueParamNode(Node, ArmLogicTreeNode):
|
||||
'''Set material value param node'''
|
||||
bl_idname = 'LNSetMaterialValueParamNode'
|
||||
bl_label = 'Set Material Value Param'
|
||||
bl_icon = 'GAME'
|
||||
|
||||
def init(self, context):
|
||||
self.inputs.new('ArmNodeSocketAction', 'In')
|
||||
self.inputs.new('NodeSocketShader', 'Material')
|
||||
self.inputs.new('NodeSocketString', 'Node')
|
||||
self.inputs.new('NodeSocketFloat', 'Value')
|
||||
self.outputs.new('ArmNodeSocketAction', 'Out')
|
||||
|
||||
add_node(SetMaterialValueParamNode, category='Action')
|
|
@ -395,9 +395,9 @@ def parse_rgb(node, socket):
|
|||
|
||||
elif node.type == 'RGB':
|
||||
if node.arm_material_param:
|
||||
nn = node_name(node.name)
|
||||
curshader.add_uniform('vec3 param_{0}'.format(nn), link='{0}'.format(nn))
|
||||
return 'param_' + nn
|
||||
nn = 'param_' + node_name(node.name)
|
||||
curshader.add_uniform('vec3 {0}'.format(nn), link='{0}'.format(node.name))
|
||||
return nn
|
||||
else:
|
||||
return to_vec3(socket.default_value)
|
||||
|
||||
|
@ -456,7 +456,7 @@ def parse_rgb(node, socket):
|
|||
return '{0}.rgb'.format(store_var_name(node))
|
||||
tex_name = node_name(node.name)
|
||||
tex = make_texture(node, tex_name)
|
||||
tex_link = tex_name if node.arm_material_param else None
|
||||
tex_link = node.name if node.arm_material_param else None
|
||||
if tex != None:
|
||||
curshader.write_textures += 1
|
||||
to_linear = parsing_basecol and not tex['file'].endswith('.hdr')
|
||||
|
@ -1016,9 +1016,9 @@ def parse_value(node, socket):
|
|||
|
||||
elif node.type == 'VALUE':
|
||||
if node.arm_material_param:
|
||||
nn = node_name(node.name)
|
||||
curshader.add_uniform('float param_{0}'.format(nn), link='{0}'.format(nn))
|
||||
return 'param_' + nn
|
||||
nn = 'param_' + node_name(node.name)
|
||||
curshader.add_uniform('float {0}'.format(nn), link='{0}'.format(node.name))
|
||||
return nn
|
||||
else:
|
||||
return to_vec1(node.outputs[0].default_value)
|
||||
|
||||
|
@ -1076,7 +1076,7 @@ def parse_value(node, socket):
|
|||
return '{0}.a'.format(store_var_name(node))
|
||||
tex_name = safesrc(node.name)
|
||||
tex = make_texture(node, tex_name)
|
||||
tex_link = tex_name if node.arm_material_param else None
|
||||
tex_link = node.name if node.arm_material_param else None
|
||||
if tex != None:
|
||||
curshader.write_textures += 1
|
||||
res = '{0}.a'.format(texture_store(node, tex, tex_name, tex_link=tex_link))
|
||||
|
|
Loading…
Reference in a new issue