protected override bool ProcessNode(CommandBuffer cmd) { Vector4 iMin = MixtureConversions.ConvertFloatToVector4(inputMin); Vector4 oMin = MixtureConversions.ConvertFloatToVector4(outputMin); o = oMin + (a - iMin) * (outputMax - outputMin) / (inputMax - inputMin); return(true); }
protected void AssignMaterialPropertiesFromEdges(List <SerializableEdge> edges, Material material) { // Update material settings when processing the graph: foreach (var edge in edges) { var propName = edge.inputPort.portData.identifier; int i = material.shader.FindPropertyIndex(propName); var type = material.shader.GetPropertyType(i); switch (type) { case ShaderPropertyType.Color: material.SetColor(propName, (Color)edge.passThroughBuffer); break; case ShaderPropertyType.Texture: // TODO: texture scale and offset material.SetTexture(propName, (Texture)edge.passThroughBuffer); break; case ShaderPropertyType.Float: case ShaderPropertyType.Range: switch (edge.passThroughBuffer) { case float f: material.SetFloat(propName, f); break; case Vector2 v: material.SetFloat(propName, v.x); break; case Vector3 v: material.SetFloat(propName, v.x); break; case Vector4 v: material.SetFloat(propName, v.x); break; default: throw new Exception($"Can't assign {edge.passThroughBuffer.GetType()} to material float property"); } break; case ShaderPropertyType.Vector: material.SetVector(propName, MixtureConversions.ConvertObjectToVector4(edge.passThroughBuffer)); break; } } }
protected void AssignMaterialPropertiesFromEdges(List <SerializableEdge> edges, Material material) { // Update material settings when processing the graph: foreach (var edge in edges) { var prop = MaterialEditor.GetMaterialProperty(new [] { material }, edge.inputPort.portData.identifier); switch (prop.type) { case MaterialProperty.PropType.Color: prop.colorValue = (Color)edge.passThroughBuffer; break; case MaterialProperty.PropType.Texture: // TODO: texture scale and offset prop.textureValue = (Texture)edge.passThroughBuffer; break; case MaterialProperty.PropType.Float: case MaterialProperty.PropType.Range: switch (edge.passThroughBuffer) { case float f: prop.floatValue = f; break; case Vector2 v: prop.floatValue = v.x; break; case Vector3 v: prop.floatValue = v.x; break; case Vector4 v: prop.floatValue = v.x; break; default: throw new Exception($"Can't assign {edge.passThroughBuffer.GetType()} to material float property"); } break; case MaterialProperty.PropType.Vector: prop.vectorValue = MixtureConversions.ConvertObjectToVector4(edge.passThroughBuffer); break; } } }
protected void AssignMaterialPropertiesFromEdges(List <SerializableEdge> edges, Material material) { // Update material settings when processing the graph: foreach (var edge in edges) { // Just in case something bad happened in a node if (edge.passThroughBuffer == null) { continue; } string propName = edge.inputPort.portData.identifier; int propertyIndex = material.shader.FindPropertyIndex(propName); if (propertyIndex == -1) { continue; } switch (material.shader.GetPropertyType(propertyIndex)) { case ShaderPropertyType.Color: material.SetColor(propName, MixtureConversions.ConvertObjectToColor(edge.passThroughBuffer)); break; case ShaderPropertyType.Texture: // TODO: texture scale and offset // Check texture dim before assigning: if (edge.passThroughBuffer is Texture t) { if (material.shader.GetPropertyTextureDimension(propertyIndex) == t.dimension) { material.SetTexture(propName, (Texture)edge.passThroughBuffer); } } break; case ShaderPropertyType.Float: case ShaderPropertyType.Range: switch (edge.passThroughBuffer) { case float f: material.SetFloat(propName, f); break; case Vector2 v: material.SetFloat(propName, v.x); break; case Vector3 v: material.SetFloat(propName, v.x); break; case Vector4 v: material.SetFloat(propName, v.x); break; case int i: material.SetFloat(propName, i); break; default: throw new Exception($"Can't assign {edge.passThroughBuffer.GetType()} to material float property"); } break; case ShaderPropertyType.Vector: material.SetVector(propName, MixtureConversions.ConvertObjectToVector4(edge.passThroughBuffer)); break; } } }