protected override bool OnAttach(IRenderTechnique technique) { mtWeightsB = new StructuredBufferProxy(sizeof(float), false); mtDeltasB = new ImmutableBufferProxy(sizeof(float) * 3, BindFlags.ShaderResource, ResourceOptionFlags.BufferStructured); mtOffsetsB = new ImmutableBufferProxy(sizeof(int), BindFlags.ShaderResource, ResourceOptionFlags.BufferStructured); return(true); }
protected override void OnDetach() { MTWeightsB = null; MTDeltasB = null; MTOffsetsB = null; cbMorphTarget.Detach(); base.OnDetach(); }
public bool InitializeMorphTargets(MorphTargetVertex[] targets, int pitch) { //The buffer is immutable, if it was already created, dont allow for recreation if (MTDeltasB != null) { return(false); } //Setup buffer and keep track of data to update MTDeltasB = new ImmutableBufferProxy(sizeof(float) * 3, BindFlags.ShaderResource, ResourceOptionFlags.BufferStructured); MTOffsetsB = new ImmutableBufferProxy(sizeof(int), BindFlags.ShaderResource, ResourceOptionFlags.BufferStructured); setDeltas = true; //Setup arrays for morph target data FastList <Vector3> mtdList = new FastList <Vector3>(targets.Length * 3); morphTargetOffsets = new int[targets.Length]; //First element is always 0 delta mtdList.Add(Vector3.Zero); mtdList.Add(Vector3.Zero); mtdList.Add(Vector3.Zero); //Subsequent elements should never need 0 delta vertex Vector3 zv = Vector3.Zero; int current = 1; for (int i = 0; i < targets.Length; i++) { //Skip if 0 delta if (targets[i].deltaNormal == zv && targets[i].deltaPosition == zv && targets[i].deltaTangent == zv) { morphTargetOffsets[i] = 0; } else { morphTargetOffsets[i] = current * 3; mtdList.Add(targets[i].deltaPosition); mtdList.Add(targets[i].deltaNormal); mtdList.Add(targets[i].deltaTangent); current++; } } morphTargetsDeltas = mtdList.ToArray(); //Set cbuffer data {int count, int pitch} setCBuffer = true; mtCount = targets.Length / pitch; mtPitch = pitch; return(true); }