public FieldCollection GenerateLerpField() { int lerpFieldHandler = lerpFieldGenerator.FindKernel("LerpField"); lerpField_texture = CreateTexture(); lerpFieldGenerator.SetTexture(lerpFieldHandler, "LerpField_Texture", lerpField_texture); LerpField XField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_X"); LerpField YField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_Y"); LerpField ZField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_Z"); SetupShaderOffsets(lerpFieldGenerator); lerpFieldGenerator.Dispatch(lerpFieldHandler, volumeSize / 8, volumeSize / 8, volumeSize / 8); //lerpField_material.mainTexture = lerpField_texture; GetFieldDataFromComputeShader(XField); GetFieldDataFromComputeShader(YField); GetFieldDataFromComputeShader(ZField); FieldCollection collection = new FieldCollection(); collection.X = XField; collection.Y = YField; collection.Z = ZField; return(collection); }
private LerpField SetLerpFieldArrayForDirection(int lerpFieldHandler, string arrayName) { LerpField result = new LerpField(); result.lerpValues = new float[volumeSize * volumeSize * volumeSize]; result.lerpBuffer = new ComputeBuffer(result.lerpValues.Length, sizeof(float)); lerpFieldGenerator.SetBuffer(lerpFieldHandler, arrayName, result.lerpBuffer); return(result); }
private void GenerateLerpField() { int lerpFieldHandler = lerpFieldGenerator.FindKernel("LerpField"); lerpField_texture = CreateTexture(); lerpFieldGenerator.SetTexture(lerpFieldHandler, "LerpField_Texture", lerpField_texture); LerpField XField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_X"); LerpField YField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_Y"); LerpField ZField = SetLerpFieldArrayForDirection(lerpFieldHandler, "LerpFloats_Z"); SetupShaderOffsets(lerpFieldGenerator); lerpFieldGenerator.Dispatch(lerpFieldHandler, volumeSize / 8, volumeSize / 8, volumeSize / 8); lerpField_material.mainTexture = lerpField_texture; GetFieldDataFromComputeShader(XField); GetFieldDataFromComputeShader(YField); GetFieldDataFromComputeShader(ZField); }
// Returns the array, but it is also stored in the lerpField passed in. private static float[] GetFieldDataFromComputeShader(LerpField lerpField) { lerpField.lerpBuffer.GetData(lerpField.lerpValues); lerpField.lerpBuffer.Dispose(); return(lerpField.lerpValues); }