public override void Prepare(DrawInfo info){ // "Bake" surface property now, if we have one: if(SurfaceProperty==null){ return; } PropertyValue value=SurfaceProperty.Value; // Numeric or colour? ColourValue col=value as ColourValue; if(col!=null){ // It's a colour! Colour=col.Value; // Value is intensity: Value=(Colour.r + Colour.g + Colour.b) / 3.0; }else{ // Try as numeric instead: NumericValue num=value as NumericValue; if(num!=null){ // Get it as a double: Value=num.ToDouble(); // Create a colour: float c=(float)Value; Colour=new Color(c,c,c,1f); }else{ // White: Colour=new Color(1f,1f,1f,1f); Value=1.0; } } // Reset DrawStore: if(IsTexture){ // Pull the texture: LiveStackNode lsn=(DrawStore as LiveStackNode); if(lsn!=null){ // Set: lsn.Image=(SurfaceProperty.Value as TextureValue).Value; // We may now need to bump parent if we're in a Draw() call; // i.e. it needs to hook up this new image to its material. if(info.CurrentParent!=null && info.CurrentParent.DrawStore!=null){ // Link away! Material material=info.CurrentParent.DrawStore.NodeMaterial; // Reset _srcX: material.SetTexture("_Src"+info.CurrentIndex,lsn.Image); } } }else{ TextureStackNode tsn=(DrawStore as TextureStackNode); if(tsn!=null){ // Bake: tsn.Bake(); } } }
/// <summary>Allocates GPU drawing meta now.</summary> public virtual DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID) { // If the source is a constant or a graph // then we don't allocate a material for it. // We do, however, create a texture: // CONSTANT: 1 * 1 (Texture) // GRAPH : info.ImageX * 1 (Texture) // ELSE : info.ImageX * info.ImageY (Stack) int dimensions = OutputDimensions; if (dimensions == 2) { // Stack required. // Allocate a target stack now: int targetStack = stackID; DrawStack stack = tex.GetStack(targetStack, info); stackID++; // Create the material: Material material = GetMaterial(MaterialID, SubMaterialID); if (Sources != null) { int inputStacks = (targetStack == 0)?1:0; for (int i = 0; i < Sources.Length; i++) { // Get the input node: TextureNode input = Sources[i]; // Allocate it now (must not allocate targetStack in the direct kids): DrawStackNode drawNode = input.Allocate(info, tex, ref inputStacks); if (inputStacks == targetStack) { // Skip: inputStacks++; } // Apply it to our material: material.SetTexture("_Src" + i, drawNode.Texture); } } // Create our node: MaterialStackNode matNode = DrawStore as MaterialStackNode; if (matNode == null) { matNode = new MaterialStackNode(); DrawStore = matNode; matNode.Mesh = info.Mesh; } matNode.Material = material; matNode.Stack = stack; return(matNode); } // It'll be baked/ drawn by the CPU. // Get the width of the texture: int width = (dimensions == 1)?info.ImageX : 1; TextureStackNode constNode = DrawStore as TextureStackNode; if (constNode == null) { constNode = new TextureStackNode(this, info.HDR, width); DrawStore = constNode; } // Ok: return(constNode); }