add color mixing
This commit is contained in:
parent
80d473155e
commit
c1f6f36d48
2 changed files with 79 additions and 2 deletions
|
@ -20,7 +20,7 @@ artnet = NodePath("../ArtNet")
|
||||||
channel_offset = 100
|
channel_offset = 100
|
||||||
|
|
||||||
[node name="ColorRect" type="Sprite2D" parent="." node_paths=PackedStringArray("artnet")]
|
[node name="ColorRect" type="Sprite2D" parent="." node_paths=PackedStringArray("artnet")]
|
||||||
modulate = Color(0.0711767, 0.291016, 0.177359, 1)
|
modulate = Color(0.862745, 0.898039, 0.603922, 1)
|
||||||
position = Vector2(162.125, 549.375)
|
position = Vector2(162.125, 549.375)
|
||||||
scale = Vector2(283.75, 328.75)
|
scale = Vector2(283.75, 328.75)
|
||||||
texture = ExtResource("3_qvw8c")
|
texture = ExtResource("3_qvw8c")
|
||||||
|
|
|
@ -24,19 +24,96 @@ func _ready() -> void:
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var rgb=[modulate.r,modulate.g,modulate.b]
|
var rgb=[modulate.r,modulate.g,modulate.b]
|
||||||
|
|
||||||
#TODO, color mix
|
|
||||||
values.fill(0.0)
|
values.fill(0.0)
|
||||||
|
|
||||||
|
# 1 0.78 0.78 <- rgb soll
|
||||||
|
# 1 1 1 = min=0.8 rgb-min*f = 0.2 0.1 0
|
||||||
|
# 1 0.9 0.9 = min=0.88
|
||||||
|
# 1 0 0 = min=1
|
||||||
|
# 0.1 1 1 = min=0.78
|
||||||
|
#print("Calculating color mix ++++++")
|
||||||
|
#print("For rgb="+str(rgb))
|
||||||
|
var passes=0
|
||||||
|
while rgb[0]+rgb[1]+rgb[2]>0.01:
|
||||||
|
passes+=1
|
||||||
|
|
||||||
|
#print("Error:"+str(rgb[0]+rgb[1]+rgb[2]))
|
||||||
|
var cmixsums=[]
|
||||||
|
for cmix in colormix:
|
||||||
|
#print(" cmix:"+str(matrixDivide(rgb,cmix)))
|
||||||
|
var colormix_min=matrixDivide(rgb,cmix).min()
|
||||||
|
var resultrgb = matrixSubtract(rgb,matrixMult(cmix,colormix_min))
|
||||||
|
cmixsums.append(matrixSum(resultrgb))
|
||||||
|
#print("cmixsums="+str(cmixsums))
|
||||||
|
var cmixsums_min=matrixMinIndex(cmixsums)
|
||||||
|
#print("cmixsums_min="+str(cmixsums_min))
|
||||||
|
var colormix_min=matrixDivide(rgb,colormix[cmixsums_min]).min()
|
||||||
|
rgb = matrixSubtract(rgb,matrixMult(colormix[cmixsums_min],colormix_min))
|
||||||
|
values[cmixsums_min]+=colormix_min
|
||||||
|
#print("new rgb="+str(rgb))
|
||||||
|
#print("new color mix:"+str(values))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#print("Remaining Error:"+str(rgb[0]+rgb[1]+rgb[2]))
|
||||||
|
print("Result color mix:"+str(values)+" passes="+str(passes)+ " remaining error="+str(rgb[0]+rgb[1]+rgb[2]))
|
||||||
|
#print("")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
artnet.setDMXChannel(channel_offset-1+1,master) #master dimmer
|
artnet.setDMXChannel(channel_offset-1+1,master) #master dimmer
|
||||||
artnet.setDMXChannel(channel_offset-1+2,0) #strobo
|
artnet.setDMXChannel(channel_offset-1+2,0) #strobo
|
||||||
artnet.setDMXChannel(channel_offset-1+8,0) #macros
|
artnet.setDMXChannel(channel_offset-1+8,0) #macros
|
||||||
|
|
||||||
|
var vi=0
|
||||||
|
for v in values:
|
||||||
|
artnet.setDMXChannel(channel_offset-1+colorchannels[vi],v*255)
|
||||||
|
vi+=1
|
||||||
|
|
||||||
|
'''
|
||||||
artnet.setDMXChannel(channel_offset-1+3,modulate.r*255) #red
|
artnet.setDMXChannel(channel_offset-1+3,modulate.r*255) #red
|
||||||
artnet.setDMXChannel(channel_offset-1+4,modulate.g*255) #green
|
artnet.setDMXChannel(channel_offset-1+4,modulate.g*255) #green
|
||||||
artnet.setDMXChannel(channel_offset-1+5,modulate.b*255) #blue
|
artnet.setDMXChannel(channel_offset-1+5,modulate.b*255) #blue
|
||||||
artnet.setDMXChannel(channel_offset-1+6,modulate.b*255) #white
|
artnet.setDMXChannel(channel_offset-1+6,modulate.b*255) #white
|
||||||
artnet.setDMXChannel(channel_offset-1+7,modulate.b*255) #amber
|
artnet.setDMXChannel(channel_offset-1+7,modulate.b*255) #amber
|
||||||
|
'''
|
||||||
|
|
||||||
|
func matrixDivide(m1:Array,m2:Array) -> Array:
|
||||||
|
var res=[]
|
||||||
|
var i=0
|
||||||
|
for m in m1:
|
||||||
|
if (m==0 and m2[i]==0): #0/0 should be inf
|
||||||
|
res.append(1.0/0)
|
||||||
|
else:
|
||||||
|
res.append(m/m2[i])
|
||||||
|
i+=1
|
||||||
|
return res
|
||||||
|
|
||||||
|
func matrixMult(m1:Array,p:float) -> Array:
|
||||||
|
var res=[]
|
||||||
|
for m in m1:
|
||||||
|
res.append(m*p)
|
||||||
|
return res
|
||||||
|
|
||||||
|
func matrixSubtract(m1:Array,m2:Array) -> Array:
|
||||||
|
var res=[]
|
||||||
|
var i=0
|
||||||
|
for m in m1:
|
||||||
|
res.append(m-m2[i])
|
||||||
|
i+=1
|
||||||
|
return res
|
||||||
|
|
||||||
|
func matrixSum(m1:Array) -> float:
|
||||||
|
var res=0
|
||||||
|
for m in m1:
|
||||||
|
res+=m
|
||||||
|
return res
|
||||||
|
|
||||||
|
func matrixMinIndex(m:Array) -> int:
|
||||||
|
var min=0
|
||||||
|
var i=0
|
||||||
|
for e in m:
|
||||||
|
if (m[i]<m[min]):
|
||||||
|
min=i
|
||||||
|
i+=1
|
||||||
|
return min
|
||||||
|
|
Loading…
Add table
Reference in a new issue