Exemple #1
0
 /// <summary>
 /// Construct a new matrix from 4 vectors representing each row
 /// </summary>
 /// <param name="row0">Top row of the matrix</param>
 /// <param name="row1">2nd row of the matrix</param>
 /// <param name="row2">3rd row of the matrix</param>
 /// <param name="row3">Bottom row of the matrix</param>
 public Matrix4(float4 row0, float4 row1, float4 row2, float4 row3)
 {
     Row0 = row0;
     Row1 = row1;
     Row2 = row2;
     Row3 = row3;
 }
Exemple #2
0
 /// <summary>
 /// Create a ColorNode with name
 /// </summary>
 /// <param name="name"></param>
 public ColorNode(string name)
     : base(ShaderNodeType.Color, name)
 {
     inputs = null;
     outputs = new ColorOutputs(this);
     Value = new float4(0.8f);
 }
Exemple #3
0
 public float4x3(float4 r0, float4 r1, float4 r2)
 {
     M11 = r0.x; M12 = r1.x; M13 = r2.x;
     M21 = r0.y; M22 = r1.y; M23 = r2.y;
     M31 = r0.z; M32 = r1.z; M33 = r2.z;
     M41 = r0.w; M42 = r1.w; M43 = r2.w;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PointLight"/> class. Only the channel is needed. Other params
 /// will be set to default value. 
 /// </summary>
 /// <param name="channel">The memory space of the light(0 - 7).</param>
 public PointLight(int channel)
 {
     _type = LightType.Point;
     _position = new float3(0, 0, 0);
     _diffuseColor = new float4(1, 1, 1, 1);
     _channel = channel;
 }
Exemple #5
0
 public float4x4(float4 r0, float4 r1, float4 r2, float4 r3)
 {
     M11 = r0.x; M12 = r0.y; M13 = r0.z; M14 = r0.w;
     M21 = r1.x; M22 = r1.y; M23 = r1.z; M24 = r1.w;
     M31 = r2.x; M32 = r2.y; M33 = r2.z; M34 = r2.w;
     M41 = r3.x; M42 = r3.y; M43 = r3.z; M44 = r3.w;
 }
 public FaceLandmarks(int4 boundingBox)
 {
     this.boundingBox2D = boundingBox;
     rightEye = new float4(0, 0, 0, -1);
     leftEye = new float4(0, 0, 0, -1);
     noseBridge = new float4(0, 0, 0, -1);
     noseTip = new float4(0, 0, 0, -1);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpotLight"/> class. Only the channel is needed.
 /// </summary>
 /// <param name="channel">The memory space of the light(0 - 7).</param>
 public SpotLight( int channel)
 {
     _type = LightType.Spot;
     _position = new float3(0,0,0);
     _direction = new float3(0,-1,0);
     _diffuseColor = new float4(1, 1, 1, 1);
     _channel = channel;
 }
Exemple #8
0
        /// <summary>
        /// Gets a 4D noise
        /// </summary>
        /// <param name="_Position"></param>
        /// <returns></returns>
        public float GetNoise( float4 _Position )
        {
            float	x = _Position.x + NOISE_BIAS;
            float	y = _Position.y + NOISE_BIAS;
            float	z = _Position.z + NOISE_BIAS;
            float	w = _Position.w + NOISE_BIAS;

            uint	FloorX = (uint) Math.Floor( x );
            float	rx = x - FloorX;
            float	rxc = rx - 1.0f;

            uint	FloorY = (uint) Math.Floor( y );
            float	ry = y - FloorY;
            float	ryc = ry - 1.0f;

            uint	FloorZ = (uint) Math.Floor( z );
            float	rz = z - FloorZ;
            float	rzc = rz - 1.0f;

            uint	FloorW = (uint) Math.Floor( w );
            float	rw = w - FloorW;
            float	rwc = rw - 1.0f;

            uint	dwBoundX0 = FloorX % m_NoiseSize;
            uint	dwBoundX1 = (dwBoundX0 + 1) % m_NoiseSize;
            uint	dwBoundY0 = FloorY % m_NoiseSize;
            uint	dwBoundY1 = (dwBoundY0 + 1) % m_NoiseSize;
            uint	dwBoundZ0 = FloorZ % m_NoiseSize;
            uint	dwBoundZ1 = (dwBoundZ0 + 1) % m_NoiseSize;
            uint	dwBoundW0 = FloorW % m_NoiseSize;
            uint	dwBoundW1 = (dwBoundW0 + 1) % m_NoiseSize;

            float	sx = SCurve( rx );
            float	sy = SCurve( ry );
            float	sz = SCurve( rz );
            float	sw = SCurve( rw );

            float	f0000 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY0]+dwBoundZ0]+dwBoundW0], rx,  ry,  rz,  rw  );
            float	f1000 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY0]+dwBoundZ0]+dwBoundW0], rxc, ry,  rz,  rw  );
            float	f1100 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY1]+dwBoundZ0]+dwBoundW0], rxc, ryc, rz,  rw  );
            float	f0100 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY1]+dwBoundZ0]+dwBoundW0], rx,  ryc, rz,  rw  );
            float	f0010 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY0]+dwBoundZ1]+dwBoundW0], rx,  ry,  rzc, rw  );
            float	f1010 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY0]+dwBoundZ1]+dwBoundW0], rxc, ry,  rzc, rw  );
            float	f1110 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY1]+dwBoundZ1]+dwBoundW0], rxc, ryc, rzc, rw  );
            float	f0110 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY1]+dwBoundZ1]+dwBoundW0], rx,  ryc, rzc, rw  );
            float	f0001 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY0]+dwBoundZ0]+dwBoundW1], rx,  ry,  rz,  rwc );
            float	f1001 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY0]+dwBoundZ0]+dwBoundW1], rxc, ry,  rz,  rwc );
            float	f1101 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY1]+dwBoundZ0]+dwBoundW1], rxc, ryc, rz,  rwc );
            float	f0101 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY1]+dwBoundZ0]+dwBoundW1], rx,  ryc, rz,  rwc );
            float	f0011 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY0]+dwBoundZ1]+dwBoundW1], rx,  ry,  rzc, rwc );
            float	f1011 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY0]+dwBoundZ1]+dwBoundW1], rxc, ry,  rzc, rwc );
            float	f1111 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX1]+dwBoundY1]+dwBoundZ1]+dwBoundW1], rxc, ryc, rzc, rwc );
            float	f0111 = Dot( m_NoiseTable[m_PermutationTable[m_PermutationTable[m_PermutationTable[dwBoundX0]+dwBoundY1]+dwBoundZ1]+dwBoundW1], rx,  ryc, rzc, rwc );

            float	a = TriLerp( f0000, f1000, f1100, f0100, f0010, f1010, f1110, f0110, sx, sy, sz );
            float	b = TriLerp( f0001, f1001, f1101, f0101, f0011, f1011, f1111, f0111, sx, sy, sz );
            return	Lerp( a, b, sw );
        }
 /// <summary>
 /// Lerp Function for Float4s.
 /// </summary>
 public static float4 Float4Lerp(float4 val1, float4 val2, float time1, float time2)
 {
     float4 values = new float4();
     values.w = val1.w + ((val2.w - val1.w) / time1) * time2;
     values.x = val1.x + ((val2.x - val1.x) / time1) * time2;
     values.y = val1.y + ((val2.y - val1.y) / time1) * time2;
     values.z = val1.z + ((val2.z - val1.z) / time1) * time2;
     return values;
 }
 /// <summary>
 /// Creates a point light in the scene. Position, color, position, and channel is needed.
 /// It is possible to set up to 8 lights in the scene.
 /// </summary>
 /// <param name="color">The color of the light.</param>
 /// <param name="position">The position in the scene.</param>
 /// <param name="channel">The memory space of the light.(0 - 7)</param>
 public PointLight(float4 color, float3 position, int channel)
 {
     _position = position;
     _diffuseColor = new float4(0.6f, 0.6f, 0.6f, 1);
     _ambientColor = new float4(0.3f, 0.3f, 0.3f, 1);
     _specularColor = new float4(0.1f, 0.1f, 0.1f, 1);
     _type = LightType.Point;
     _channel = channel;
 }
 //[adjustMomentum]
 static float4 Momentum(float4 velocity)
 {
     // we store mass in velocity.w
     var mass = velocity.w;
     return new float4(velocity.x * mass,
                       velocity.y * mass,
                       velocity.z * mass,
                       mass);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderPointLight" /> class. Position, color, type and channel are needed.
 /// </summary>
 /// <param name="position">The position of the light.</param>
 /// <param name="diffuse">The diffuse light color.</param>
 /// <param name="ambient">The ambient light color.</param>
 /// <param name="specular">The specular light color.</param>
 /// <param name="type">The light type.</param>
 /// <param name="channel">The memory space of the light(0 - 7).</param>
 public RenderPointLight(float3 position, float4 diffuse, float4 ambient, float4 specular, Light.LightType type, int channel)
 {
     _position = position;
     _type = Light.LightType.Point;
     _diffuseColor = diffuse;
     _ambientColor = ambient;
     _specularColor = specular;
     _channel = channel;
 }
 /// <summary>
 /// Creates a spot light in the scene. Position, color, position, and channel is needed.
 /// It is possible to set up to 8 lights in the scene.
 /// </summary>
 /// <param name="direction">Direction of the light.</param>
 /// <param name="diffuse">The diffuse light color.</param>
 /// <param name="ambient">The ambient light color.</param>
 /// <param name="specular">The specular light color.</param>
 /// <param name="position">The lights position in the scene.</param>
 /// <param name="channel">The memory space of the light.(0 - 7)</param>
 public SpotLight(float3 direction, float4 diffuse, float4 ambient, float4 specular, float3 position, int channel)
 {
     _direction = direction;
     _position = position;
     _diffuseColor = diffuse;
     _ambientColor = ambient;
     _specularColor = specular;
     _type = LightType.Spot;
     _channel = channel;
 }
 /// <summary>
 /// Creates a directional light in the scene. Direction, color and position will get standart values.
 /// Channel is needed. It is possible to set up to 8 lights in the scene.
 /// </summary>
 /// <param name="channel">The memory space of the light(0 - 7).</param>
 public DirectionalLight( int channel)
 {
     _position = new float3(0,0,0);
     _direction = new float3(0,-1,0);
     _diffuseColor = new float4(0.6f, 0.6f, 0.6f, 1);
     _ambientColor = new float4(0.3f, 0.3f, 0.3f, 1);
     _specularColor = new float4(0.1f, 0.1f, 0.1f, 1);
     _type = LightType.Directional;
     _channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderSpotLight" /> class. Position, direction, color, type and channel.
 /// </summary>
 /// <param name="position">The position of the light.</param>
 /// <param name="direction">The direction of the light.</param>
 /// <param name="diffuse">The diffuse light color.</param>
 /// <param name="ambient">The ambient light color.</param>
 /// <param name="specular">The specular light color.</param>
 /// <param name="angle">The angle of the spot light.</param>
 /// <param name="type">The lighttype.</param>
 /// <param name="channel">The memory space of the light(0 - 7).</param>
 public RenderSpotLight(float3 position, float3 direction, float4 diffuse, float4 ambient, float4 specular, float angle, Light.LightType type, int channel)
 {
     _position = position;
     _direction = direction;
     _type = Light.LightType.Spot;
     _diffuseColor = diffuse;
     _ambientColor = ambient;
     _specularColor = specular;
     _channel = channel;
     _angle = angle;
 }
Exemple #16
0
 public MappingNode(string name)
     : base(ShaderNodeType.Mapping, name)
 {
     inputs = new MappingInputs(this);
     outputs = new MappingOutputs(this);
     Mapping = MappingType.Texture;
     UseMin = false;
     UseMax = false;
     Translation = new float4(0.0f);
     Rotation = new float4(0.0f);
     Scale = new float4(0.0f);
     Min = new float4(0.0f);
     Max = new float4(0.0f);
 }
        public void Kernel(deviceptr<float4> pos, float time)
        {
            var x = blockIdx.x*blockDim.x + threadIdx.x;
            var y = blockIdx.y*blockDim.y + threadIdx.y;

            var u = ((float) x)/((float) Width);
            var v = ((float) y)/((float) Height);
            u = u*2.0f - 1.0f;
            v = v*2.0f - 1.0f;

            const float freq = 4.0f;
            var w = LibDevice.__nv_sinf(u*freq + time)*LibDevice.__nv_cosf(v*freq + time)*0.5f;

            pos[y * Width + x] = new float4(u, w, v, LibDevice.__nv_uint_as_float(0xff00ff00));
        }
        public CpuSimulator(Worker worker, int numBodies)
        {
            _worker = worker;
            _numBodies = numBodies;
            _haccel = new float3[numBodies];
            _hpos = new float4[numBodies];
            _hvel = new float4[numBodies];

            for (var i = 0; i < numBodies; i++)
            {
                _haccel[i] = new float3(0.0f, 0.0f, 0.0f);
                _hpos[i] = new float4(0.0f, 0.0f, 0.0f, 0.0f);
                _hvel[i] = new float4(0.0f, 0.0f, 0.0f, 0.0f);
            }

            _description = "CPU.Simple";
        }
        //[IntegrateCommonNbodySystem]
        public static void IntegrateNbodySystem(float3[] accel, float4[] pos, float4[] vel, int numBodies,
            float deltaTime, float softeningSquared, float damping)
        {
            // Force of particle i on itselfe is 0 because of the regularisatino of the force.
            // As fij = -fji we could save half of the time, but implement it here as on GPU.            
            for (var i = 0; i < numBodies; i++)
            {
                var acc = new float3(0.0f, 0.0f, 0.0f);
                for (var j = 0; j < numBodies; j++)
                {
                    acc = Common.BodyBodyInteraction(softeningSquared, acc, pos[i], pos[j]);
                }
                accel[i] = acc;
            }
            for (var i = 0; i < numBodies; i++)
            {

                var position = pos[i];
                var localAccel = accel[i];

                // acceleration = force \ mass
                // new velocity = old velocity + acceleration*deltaTime
                // note we factor out the body's mass from the equation, here and in bodyBodyInteraction 
                // (because they cancel out).  Thus here force = acceleration
                var velocity = vel[i];

                velocity.x = velocity.x + localAccel.x*deltaTime;
                velocity.y = velocity.y + localAccel.y*deltaTime;
                velocity.z = velocity.z + localAccel.z*deltaTime;

                velocity.x = velocity.x*damping;
                velocity.y = velocity.y*damping;
                velocity.z = velocity.z*damping;

                // new position = old position + velocity*deltaTime
                position.x = position.x + velocity.x*deltaTime;
                position.y = position.y + velocity.y*deltaTime;
                position.z = position.z + velocity.z*deltaTime;

                // store new position and velocity
                pos[i] = position;
                vel[i] = velocity;
            }
        }
        // is called on startup
        public override void Init()
        {
            _theColor = new float4(0.5f, 0.8f, 0, 1);
            RC.ClearColor = new float4(1, 1, 1, 1);

            // initialize the variables
            _meshTea = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            _meshFace = MeshReader.LoadMesh(@"Assets/Face.obj.model");

            _spColor = MoreShaders.GetShader("simple", RC);
            _spTexture = MoreShaders.GetShader("texture", RC);

            _colorParam = _spColor.GetShaderParam("vColor");
            _textureParam = _spTexture.GetShaderParam("texture1");

            // load texture
            var imgData = RC.LoadImage("Assets/world_map.jpg");
            _iTex = RC.CreateTexture(imgData);
        }
        //[/DynamicAOTCompile]

        //[DynamicComputeBodyAccel]
        public float3 ComputeBodyAccel(float softeningSquared, float4 bodyPos, deviceptr<float4> positions, 
                                       int numTiles)
        {
            var sharedPos = __shared__.ExternArray<float4>();
            var acc = new float3(0.0f, 0.0f, 0.0f);

            for (var tile = 0; tile < numTiles; tile++)
            {
                sharedPos[threadIdx.x] = positions[tile*blockDim.x + threadIdx.x];

                Intrinsic.__syncthreads();

                // This is the "tile_calculation" function from the GPUG3 article.
                for (var counter = 0; counter < blockDim.x; counter++)
                {
                    acc = Common.BodyBodyInteraction(softeningSquared, acc, bodyPos, sharedPos[counter]);
                }
                Intrinsic.__syncthreads();
            }
            return (acc);
        }
        static public void Initialize(BodyInitializer initializer, float clusterScale,
                                      float velocityScale, int numBodies, 
                                      out float4[] positions, out float4[] velocities)
        {
            var pscale = clusterScale*Math.Max(1.0f, numBodies/1024.0f);
            var vscale = velocityScale*pscale;
            initializer.NumBodies = numBodies;
            initializer.PScale = pscale;
            initializer.VScale = vscale;
            positions = Enumerable.Range(0, numBodies).Select(initializer.Position).ToArray();
            velocities = positions.Select(initializer.Velocity).ToArray();

            // now we try to adjust velocity to make total momentum = zero.
            var momentums = velocities.Select(Momentum).ToArray();
            var totalMomentum = momentums.Aggregate(new float4(0.0f, 0.0f, 0.0f, 0.0f),
                (accum, momentum) =>
                    new float4(accum.x + momentum.x,
                               accum.y + momentum.y,
                               accum.z + momentum.z, 
                               accum.w + momentum.w));
            Console.WriteLine("total momentum and mass 0 = {0}", totalMomentum);

            var len = velocities.Length;
            // adjust velocities
            velocities = velocities.Select((vel, i) => new float4(
                vel.x - totalMomentum.x / len / vel.w,
                vel.y - totalMomentum.y / len / vel.w,
                vel.z - totalMomentum.z / len / vel.w,
                vel.w)).ToArray();

            // see total momentum after adjustment
            momentums = velocities.Select(Momentum).ToArray();
            totalMomentum = momentums.Aggregate(new float4(0.0f, 0.0f, 0.0f, 0.0f),
                (accum, momentum) =>
                    new float4(accum.x + momentum.x,
                               accum.y + momentum.y,
                               accum.z + momentum.z,
                               accum.w + momentum.w));
            Console.WriteLine("total momentum and mass 1 = {0}", totalMomentum);
        }
 public static int GreaterThanOrEqualFloat4(ref float4 a, ref float4 b)
 {
     return(ConvertToInt(a >= b));
 }
Exemple #24
0
            public static bool BoxUnderPlane(ref float4 plane, ref FogVolume fog, int i)
            {
                float3 absNormal = abs(normalize(mul(plane.xyz, fog.localToWorld)));

                return(dot(fog.position, plane.xyz) - dot(absNormal, fog.extent) < -plane.w);
            }
Exemple #25
0
        public void Execute(int i)
        {
            var   unitTransform = unitTransformData[i];
            float distance      = math.length(CameraPosition - unitTransform.Position);

            var animatorData = textureAnimatorData[i];

            AnimationClipDataBaked clip     = animationClips[(int)animatorData.UnitType * 25 + animatorData.CurrentAnimationId];
            Quaternion             rotation = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f));
            float  texturePosition          = textureAnimatorData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
            float4 position = new float4(unitTransform.Position, unitTransform.Scale);

            if (distance < DistanceMaxLod0)
            {
                int writeIndex = BufferCounterLod0.Increment();

                //unitPositions[writeIndex] = unitTransform.Position;
                UnsafeUtility.WriteArrayElement(BufferPointers[0], writeIndex, position);

                //unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
                UnsafeUtility.WriteArrayElement(BufferPointers[1], writeIndex, rotation);

                //textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
                UnsafeUtility.WriteArrayElement(BufferPointers[2], writeIndex, texturePosition);
            }
            else if (distance < DistanceMaxLod1)
            {
                int writeIndex = BufferCounterLod1.Increment();

                //unitPositions[writeIndex] = unitTransform.Position;
                UnsafeUtility.WriteArrayElement(BufferPointers[3], writeIndex, position);

                //unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
                UnsafeUtility.WriteArrayElement(BufferPointers[4], writeIndex, rotation);

                //textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
                UnsafeUtility.WriteArrayElement(BufferPointers[5], writeIndex, texturePosition);
            }
            else if (distance < DistanceMaxLod2)
            {
                int writeIndex = BufferCounterLod2.Increment();

                //unitPositions[writeIndex] = unitTransform.Position;
                UnsafeUtility.WriteArrayElement(BufferPointers[6], writeIndex, position);

                //unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
                UnsafeUtility.WriteArrayElement(BufferPointers[7], writeIndex, rotation);

                //textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
                UnsafeUtility.WriteArrayElement(BufferPointers[8], writeIndex, texturePosition);
            }
            else
            {
                int writeIndex = BufferCounterLod3.Increment();

                //unitPositions[writeIndex] = unitTransform.Position;
                UnsafeUtility.WriteArrayElement(BufferPointers[9], writeIndex, position);

                //unitRotations[writeIndex] = Quaternion.LookRotation(unitTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f) /* Vector3.up */);
                UnsafeUtility.WriteArrayElement(BufferPointers[10], writeIndex, rotation);

                //textureCoordinates[writeIndex] = animationData[i].AnimationNormalizedTime * clip.TextureRange + clip.TextureOffset;
                UnsafeUtility.WriteArrayElement(BufferPointers[11], writeIndex, texturePosition);
            }
        }
Exemple #26
0
 internal static float4 CircEaseIn(float4 a, float4 b, float t, float d)
 {
     return(lerp(a, b, Easing.CircEaseIn(t, d)));
 }
        //@TODO: Test len > epsilon4f... it is weird. compare to hlsl beahviour...
        // discuss if we want this function at all???
        static public float4 normalizeSafe(float4 v, float4 defaultValue = new float4())
        {
            float len = math.dot(v, v);

            return(math.select(defaultValue, v * math.rsqrt(len), len > epsilon4f));
        }
 public static float ConvertToFloat(float4 result)
 {
     return(result.x + result.y * 10.0f + result.z * 100.0f + result.w * 1000.0f);
 }
Exemple #29
0
        public void Execute(int index)
        {
            var p = Input[index];

            Output[index] = new float4(p.x, p.y, p.z, Alpha);
        }
Exemple #30
0
 public static extern CUResult cuMemcpyDtoH_v2(ref float4 dstHost, CUdeviceptr srcDevice, SizeT ByteCount);
Exemple #31
0
 public void CalculateBasis(float4 relativeVelocity)
 {
     tangent   = math.normalizesafe(relativeVelocity - math.dot(relativeVelocity, normal) * normal);
     bitangent = math.normalizesafe(new float4(math.cross(normal.xyz, tangent.xyz), 0));
 }
Exemple #32
0
 static float4 taylorInvSqrt(float4 r)
 {
     return(1.79284291400159f - 0.85373472095314f * r);
 }
Exemple #33
0
 static float4 fade(float4 t)
 {
     return(t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f));
 }
Exemple #34
0
 static float4 permute(float4 x)
 {
     return(mod289((34.0f * x + 1.0f) * x));
 }
Exemple #35
0
 static float4 mod7(float4 x)
 {
     return(x - floor(x * (1.0f / 7.0f)) * 7.0f);
 }
Exemple #36
0
 static float4 mod289(float4 x)
 {
     return(x - floor(x * (1.0f / 289.0f)) * 289.0f);
 }
 public static int LessThanFloat4Float(ref float4 a, float b)
 {
     return(ConvertToInt(a < b));
 }
 public SerializableColorContainerStruct(ColorContainerStruct C)
 {
     coresEditaveis = C.coresEditaveis;
     cor            = new float4(C.cor.r, C.cor.g, C.cor.b, C.cor.a);
 }
 public static int LessThanOrEqualFloat4(ref float4 a, ref float4 b)
 {
     return(ConvertToInt(a <= b));
 }
        public static ShaderEffect GetShaderEffect(RenderContext rc, ITexture baseTexture, ITexture colorMapTexture, float4 lineColor, float2 lineWidth)
        {
            EffectPassDeclaration[] epd =
            {
                new EffectPassDeclaration
                {
                    VS = VsSimpleToonPass1,
                    PS = PsSimpleToonPass1,
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                },
                new EffectPassDeclaration
                {
                    VS = VsSimpleToonPass2,
                    PS = PsTextureToonPass2,  //The only difference to the previous shader definition
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true
                    }
                }
            };

            var shaderEffect = new ShaderEffect(epd, new[]
            {
                new EffectParameterDeclaration {Name = "uLineColor", Value = lineColor},
                new EffectParameterDeclaration {Name = "texture1", Value = colorMapTexture},
                new EffectParameterDeclaration {Name = "uLineWidth", Value = lineWidth},
                new EffectParameterDeclaration {Name = "texture2", Value = baseTexture}
            });

            shaderEffect.AttachToContext(rc);

            return shaderEffect;
        }
                public static float SubByArgs(ref float4 left, ref float4 right)
                {
                    var result = left - right;

                    return(ConvertToFloat(result));
                }
Exemple #42
0
            public void Execute(int i)
            {
                var cell = particleGrid.usedCells[i];

                BurstAabb cellBounds = new BurstAabb(float.MaxValue, float.MinValue);

                // here we calculate cell bounds that enclose both the predicted position and the original position of all its particles,
                // for accurate continuous collision detection.
                for (int p = 0; p < cell.Length; ++p)
                {
                    int pIndex = cell[p];

                    // get collision material stick distance:
                    float stickDistance = 0;
                    int   materialIndex = particleMaterialIndices[pIndex];
                    if (materialIndex >= 0)
                    {
                        stickDistance = collisionMaterials[materialIndex].stickDistance;
                    }

                    cellBounds.EncapsulateParticle(positions[pIndex],
                                                   positions[pIndex] + velocities[pIndex] * deltaTime,
                                                   radii[pIndex].x + stickDistance);
                }

                // transform the cell bounds to world space:
                cellBounds.Transform(solverToWorld);

                // get all colliders overlapped by the cell bounds, in all grid levels:
                NativeList <int> candidates = new NativeList <int>(Allocator.Temp);

                for (int l = 0; l < gridLevels.Length; ++l)
                {
                    GetCandidatesForBoundsAtLevel(candidates, cellBounds, gridLevels[l], is2D);
                }

                if (candidates.Length > 0)
                {
                    // make sure each candidate collider only shows up once in the array:
                    NativeArray <int> uniqueCandidates = candidates.AsArray();
                    uniqueCandidates.Sort();
                    int uniqueCount = uniqueCandidates.Unique();

                    // iterate over candidate colliders, generating contacts for each one
                    for (int c = 0; c < uniqueCount; ++c)
                    {
                        int colliderIndex                     = uniqueCandidates[c];
                        BurstColliderShape   shape            = shapes[colliderIndex];
                        BurstAabb            colliderBounds   = bounds[colliderIndex];
                        BurstAffineTransform colliderToSolver = worldToSolver * transforms[colliderIndex];

                        // transform collider bounds to solver space:
                        colliderBounds.Transform(worldToSolver);

                        // iterate over all particles in the cell:
                        for (int p = 0; p < cell.Length; ++p)
                        {
                            int particleIndex = cell[p];

                            // skip this pair if particle and collider have the same phase:
                            if (shape.phase == (phases[particleIndex] & (int)Oni.ParticleFlags.GroupMask))
                            {
                                continue;
                            }

                            // get collision material stick distance:
                            float stickDistance = 0;
                            int   materialIndex = particleMaterialIndices[particleIndex];
                            if (materialIndex >= 0)
                            {
                                stickDistance = collisionMaterials[materialIndex].stickDistance;
                            }

                            // inflate collider bounds by particle's bounds:
                            BurstAabb inflatedColliderBounds = colliderBounds;
                            inflatedColliderBounds.Expand(radii[particleIndex].x * 1.2f + stickDistance);

                            float4 invDir = math.rcp(velocities[particleIndex] * deltaTime);

                            // We check particle trajectory ray vs inflated collider aabb
                            // instead of checking particle vs collider aabbs directly, as this reduces
                            // the amount of contacts generated for fast moving particles.
                            if (inflatedColliderBounds.IntersectsRay(positions[particleIndex], invDir, shape.is2D != 0))
                            {
                                // generate contacts for the collider:
                                GenerateContacts(shape.type,
                                                 particleIndex, colliderIndex,
                                                 positions[particleIndex], orientations[particleIndex], velocities[particleIndex], radii[particleIndex],
                                                 colliderToSolver, shape, contactsQueue, deltaTime);
                            }
                        }
                    }
                }
            }
Exemple #43
0
 internal static float4 ExpoEaseOutIn(float4 a, float4 b, float t, float d)
 {
     return(lerp(a, b, Easing.ExpoEaseOutIn(t, d)));
 }
Exemple #44
0
        public static float4x4 View(ref float4 from, ref float4 at, ref float4 world_up, float roll)
        {
            //			float4 view_dir = (at - from);  view_dir.Unit();
            //			float4 right =(world_up^view_dir);
            //			float4 up = (view_dir^right);
            float4 view_dir = (at - from); view_dir.Unit();
            float4 right = (view_dir ^ world_up); right.Unit();
            float4 up = (right ^ view_dir);

            //			up.Unit();
            /*
                    float4x4 view = new float4x4(			
                        right[0],		right[1],		right[2],		0,
                        up[0],			up[1],			up[2],			0,
                        view_dir[0],	view_dir[1],	view_dir[2],	0,
                        -(right*(from-float4.set(0, 0, 0, 1))),
                        -(up*(from-float4.set(0, 0, 0, 1))),
                        -(view_dir*(from-float4.set(0, 0, 0, 1))), 1);
        */
            float4x4 view = new float4x4(
                right[0], up[0], view_dir[0], 0,
                right[1], up[1], view_dir[1], 0,
                right[2], up[2], view_dir[2], 0,
                -(right * from),
                -(up * from),
                -(view_dir * from), 1);

            // Set roll
            if (roll != 0f)
            {
                view = float4x4.RotateZ(-roll) * view;
            }

            return view;
        }
Exemple #45
0
        protected override void OnUpdate()
        {
            var mapSettings  = GetSingleton <MapSettings>();
            var resourceOres = GetComponentDataFromEntity <ResourceOre>(true);

            var seed = (uint)DateTime.Now.GetHashCode();
            // Init random
            Random random = new Random();

            random.InitState(seed);

            Entities
            .WithReadOnly(resourceOres)
            .WithStructuralChanges()
            .ForEach((Entity e, in UnitsRequest unitsRequest) =>
            {
                // Search for positions
                NativeHashMap <MapIndex, byte> freePositionsSet = new NativeHashMap <MapIndex, byte>(unitsRequest.UnitsCount, Allocator.Temp);
                for (int i = 0; i < unitsRequest.UnitsCount; i++)
                {
                    var mapIndex = MapIndex.From(random.NextInt2(0, mapSettings.MapEdgeSize), mapSettings.MapEdgeSize);

                    while (resourceOres[mapSettings.Tiles[mapIndex.Index1D]].IsValid || freePositionsSet.ContainsKey(mapIndex))
                    {
                        mapIndex = MapIndex.From(random.NextInt2(0, mapSettings.MapEdgeSize), mapSettings.MapEdgeSize);
                    }

                    freePositionsSet.Add(mapIndex, 1);
                }
                var freePositions = freePositionsSet.GetKeyArray(Allocator.Temp);

                // Spawn units
                var unitMaterial = EntityManager.GetComponentObject <Material>(e);
                NativeArray <Entity> entities = new NativeArray <Entity>(unitsRequest.UnitsCount, Allocator.Temp);
                EntityManager.CreateEntity(_unitArchetype, entities);

                for (int i = 0; i < unitsRequest.UnitsCount; i++)
                {
                    // Unit specific
                    EntityManager.SetComponentData(entities[i], new MovementSpeed()
                    {
                        Speed = (float)unitsRequest.UnitSpeed
                    });
                    EntityManager.SetComponentData(entities[i], new MiningSpeed()
                    {
                        Speed = (float)unitsRequest.UnitMiningSpeed
                    });

                    // Position
                    var mapIndex = freePositions[i];
                    EntityManager.SetComponentData(entities[i], mapIndex);

                    var position = new float3(mapIndex.Index2D.x, 3, mapIndex.Index2D.y);
                    EntityManager.SetComponentData(entities[i], new Translation()
                    {
                        Value = position
                    });

                    // Rendering
                    EntityManager.SetSharedComponentData(entities[i], new RenderMesh {
                        material = unitMaterial, mesh = _unitMesh
                    });
                    EntityManager.SetComponentData(entities[i], new RenderBounds
                    {
                        Value = new AABB()
                        {
                            Center  = float3.zero,
                            Extents = new float3(EXTENDS, 0, EXTENDS)
                        }
                    });
                    var materialTile = new float4(random.NextInt(0, unitsRequest.TextureTiles.x), random.NextInt(0, unitsRequest.TextureTiles.y), 0, 0);
                    EntityManager.SetComponentData(entities[i], new TileMaterialProperty {
                        Tile = materialTile
                    });
                    EntityManager.SetComponentData(entities[i], new AnimationSpeedMaterialProperty {
                        Speed = 0.5f
                    });
                    EntityManager.SetComponentData(entities[i], new RowsColumns_Tex_AnimMaterialProperty {
                        Value = new float4(8, 12, 0, 3)
                    });
                }

                entities.Dispose();
                freePositionsSet.Dispose();
                freePositions.Dispose();
                EntityManager.DestroyEntity(e);
            }).Run();
        }
Exemple #46
0
        public static float4x4 ProjectiveFromToV4F(ref float4 F0, ref float4 F1, ref float4 F2, ref float4 F3, ref float4 F4,
            ref float4 T0, ref float4 T1, ref float4 T2, ref float4 T3, ref float4 T4)
        {
            float4x4 P = new float4x4(
                F1.x, F1.y, F1.z, F1.w,
                F2.x, F2.y, F2.z, F2.w,
                F3.x, F3.y, F3.z, F3.w,
                F4.x, F4.y, F4.z, F4.w
                );

            float4x4 Q = new float4x4(
                T1.x, T1.y, T1.z, T1.w,
                T2.x, T2.y, T2.z, T2.w,
                T3.x, T3.y, T3.z, T3.w,
                T4.x, T4.y, T4.z, T4.w
                );

            return float4x4.Zero;
        }
Exemple #47
0
                public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    NativeArray <Translation>          chunkPositions      = chunk.GetNativeArray(PositionType);
                    NativeArray <Rotation>             chunkRotations      = chunk.GetNativeArray(RotationType);
                    NativeArray <PhysicsVelocity>      chunkVelocities     = chunk.GetNativeArray(PhysicsVelocityType);
                    NativeArray <PhysicsMass>          chunkMasses         = chunk.GetNativeArray(PhysicsMassType);
                    NativeArray <PhysicsDamping>       chunkDampings       = chunk.GetNativeArray(PhysicsDampingType);
                    NativeArray <PhysicsGravityFactor> chunkGravityFactors = chunk.GetNativeArray(PhysicsGravityFactorType);

                    int motionStart   = firstEntityIndex;
                    int instanceCount = chunk.Count;

                    bool hasChunkPhysicsGravityFactorType = chunk.Has(PhysicsGravityFactorType);
                    bool hasChunkPhysicsDampingType       = chunk.Has(PhysicsDampingType);
                    bool hasChunkPhysicsMassType          = chunk.Has(PhysicsMassType);

                    // Note: Transform and AngularExpansionFactor could be calculated from PhysicsCollider.MassProperties
                    // However, to avoid the cost of accessing the collider we assume an infinite mass at the origin of a ~1m^3 box.
                    // For better performance with spheres, or better behavior for larger and/or more irregular colliders
                    // you should add a PhysicsMass component to get the true values
                    var defaultPhysicsMass = new PhysicsMass()
                    {
                        Transform              = RigidTransform.identity,
                        InverseMass            = 0.0f,
                        InverseInertia         = float3.zero,
                        AngularExpansionFactor = 1.0f,
                    };

                    // Create motion velocities
                    var defaultInverseInertiaAndMass = new float4(defaultPhysicsMass.InverseInertia, defaultPhysicsMass.InverseMass);

                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionVelocities[motionIndex] = new MotionVelocity
                        {
                            LinearVelocity         = chunkVelocities[i].Linear,  // world space
                            AngularVelocity        = chunkVelocities[i].Angular, // inertia space
                            InverseInertiaAndMass  = hasChunkPhysicsMassType ? new float4(chunkMasses[i].InverseInertia, chunkMasses[i].InverseMass) : defaultInverseInertiaAndMass,
                            AngularExpansionFactor = hasChunkPhysicsMassType ? chunkMasses[i].AngularExpansionFactor : defaultPhysicsMass.AngularExpansionFactor,
                        };
                    }

                    // Note: these defaults assume a dynamic body with infinite mass, hence no damping
                    var defaultPhysicsDamping = new PhysicsDamping()
                    {
                        Linear  = 0.0f,
                        Angular = 0.0f,
                    };

                    // Note: if a dynamic body infinite mass then assume no gravity should be applied
                    float defaultGravityFactor = hasChunkPhysicsMassType ? 1.0f : 0.0f;

                    // Create motion datas
                    for (int i = 0, motionIndex = motionStart; i < instanceCount; i++, motionIndex++)
                    {
                        MotionDatas[motionIndex] = CreateMotionData(
                            chunkPositions[i], chunkRotations[i],
                            hasChunkPhysicsMassType ? chunkMasses[i] : defaultPhysicsMass,
                            hasChunkPhysicsDampingType ? chunkDampings[i] : defaultPhysicsDamping,
                            hasChunkPhysicsGravityFactorType ? chunkGravityFactors[i].Value : defaultGravityFactor);
                    }
                }
Exemple #48
0
 public Plane(float3 normal, float distance)
 {
     NormalAndDistance = Normalize(new float4(normal, distance));
 }
                public static float Neg()
                {
                    var left = new float4(1.0f, 2.0f, 3.0f, 4.0f);

                    return(ConvertToFloat((-left)));
                }
Exemple #50
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var selectableColorArray = chunk.GetNativeArray(SelectableColorType);
                var selectableArray      = chunk.GetNativeArray(SelectableType);
                var colorArray           = chunk.GetNativeArray(ColorMultiplierType);
                var entityArray          = chunk.GetNativeArray(EntityType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var selectableState = selectableArray[i];

                    if (TargetToEvent.TryGetValue(entityArray[i], out Entity eventEntity))
                    {
                        var inputBuffer = PointerInputType[eventEntity];
                        for (int j = 0; j < inputBuffer.Length; j++)
                        {
                            var input = inputBuffer[j];
                            if (input.EventType == PointerEventType.Down && input.EventData.Button == PointerButton.Left)
                            {
                                selectableState.Value |= SelectableState.Pressed;
                            }
                            else if (input.EventType == PointerEventType.Up && input.EventData.Button == PointerButton.Left)
                            {
                                selectableState.Value &= (~SelectableState.Pressed);
                            }
                            else if (input.EventType == PointerEventType.Enter)
                            {
                                selectableState.Value |= SelectableState.Hovered;
                            }
                            else if (input.EventType == PointerEventType.Exit)
                            {
                                selectableState.Value &= (~SelectableState.Hovered);
                            }
                            else if (input.EventType == PointerEventType.Selected)
                            {
                                selectableState.Value |= SelectableState.Selected;
                            }
                            else if (input.EventType == PointerEventType.Deselected)
                            {
                                selectableState.Value &= (~SelectableState.Selected);
                            }
                        }
                    }

                    var    currentColor = colorArray[i].Value;
                    float4 newColor     = currentColor;
                    if ((selectableState.Value & SelectableState.Pressed) == SelectableState.Pressed)
                    {
                        newColor = selectableColorArray[i].Pressed;
                    }
                    else if ((selectableState.Value & SelectableState.Selected) == SelectableState.Selected)
                    {
                        newColor = selectableColorArray[i].Selected;
                    }
                    else if ((selectableState.Value & SelectableState.Hovered) == SelectableState.Hovered)
                    {
                        newColor = selectableColorArray[i].Hover;
                    }
                    else
                    {
                        newColor = selectableColorArray[i].Normal;
                    }

                    if (!currentColor.Equals(newColor))
                    {
                        colorArray[i] = new VertexColorMultiplier()
                        {
                            Value = newColor
                        };
                    }

                    selectableArray[i] = selectableState;
                }
            }
Exemple #51
0
 public static float4x4 Translate(ref float4 t)
 {
     return new float4x4(
         1, 0, 0, 0,
         0, 1, 0, 0,
         0, 0, 1, 0,
         t.x, t.y, t.z, 1
         );
 }
                public static float Positive()
                {
                    var left = new float4(1.0f, 2.0f, 3.0f, 4.0f);

                    return(ConvertToFloat((+left)));
                }
Exemple #53
0
 public static float4x4 Scale(ref float4 s)
 {
     return new float4x4(
         s.x, 0, 0, 0,
         0, s.y, 0, 0,
         0, 0, s.z, 0,
         0, 0, 0, 1
         );
 }
 public static int InequalityFloat4(ref float4 a, ref float4 b)
 {
     return(ConvertToInt(a != b));
 }
Exemple #55
0
        //public static float4x4 RotateAbout(ref float4 P, ref float4 V, float angle)
        //{
        //    double theta = DegreesToRadians * angle;
        //    float s = (float)Math.Sin(0.5 * theta) / V.Length;
        //    Quaternion Q = new Quaternion(s * V.x, s * V.y, s * V.z, (float)Math.Cos(0.5 * angle));
        //    return Q.GetMatrix();
        //}

        public static float4x4 AffineFromToV4F(ref float4 F0, ref float4 F1, ref float4 F2, ref float4 F3,
            ref float4 T0, ref float4 T1, ref float4 T2, ref float4 T3)
        {
            float4x4 A = new float4x4(
                F0.x, F0.y, F0.z, F0.w,
                F1.x, F1.y, F1.z, F1.w,
                F2.x, F2.y, F2.z, F2.w,
                F3.x, F3.y, F3.z, F3.w
                );

            float4x4 B = new float4x4(
                T0.x, T0.y, T0.z, T0.w,
                T1.x, T1.y, T1.z, T1.w,
                T2.x, T2.y, T2.z, T2.w,
                T3.x, T3.y, T3.z, T3.w
                );

            return A.Inverse * B;
        }
 public static int GreaterThanFloat4Float(ref float4 a, float b)
 {
     return(ConvertToInt(a > b));
 }
        public void Execute(int startIndex, int count)
        {
            for (int i = startIndex; i < startIndex + count; ++i)
            {

                //Calculate Cost of Pose Joint Positions
                float4x3 jointPosDiff = InputPoses[i].JointPositionsA - DesiredPose.JointPositionsA;

                float4 jointPosDist = ((jointPosDiff.c0 * jointPosDiff.c0) +
                                      (jointPosDiff.c1 * jointPosDiff.c1) +
                                      (jointPosDiff.c2 * jointPosDiff.c2)) * JointPositionWeightsA;

                float4x3 jointVelocities = InputPoses[i].JointVelocitiesA;

                //Calculate Cost of Pose Velocity & Joints Velocity
                float4x3 jointVelDiff = jointVelocities - DesiredPose.JointVelocitiesA;

                float4 jointVelDist = ((jointVelDiff.c0 * jointVelDiff.c0) +
                                      (jointVelDiff.c1 * jointVelDiff.c1) +
                                      (jointVelDiff.c2 * jointVelDiff.c2)) * JointVelocityWeightsA;

                //Calculate resultant pose
                float4x3 jointResultVelA = jointPosDiff / PoseInterval;
                float4x3 jointResultVelDiffA = jointVelocities - jointResultVelA;

                float4 jointResultVelDistA = ((jointResultVelDiffA.c0 * jointResultVelDiffA.c0) +
                                      (jointResultVelDiffA.c1 * jointResultVelDiffA.c1) +
                                      (jointResultVelDiffA.c2 * jointResultVelDiffA.c2)) * (JointVelocityWeightsA * ResultantVelocityWeight);

                GoalCosts[i] = jointVelDist.x + jointVelDist.y + jointVelDist.z + jointVelDist.w
                                + jointPosDist.x + jointPosDist.y + jointPosDist.z + jointPosDist.w
                                + jointResultVelDistA.x + jointResultVelDistA.y + jointResultVelDistA.z + jointResultVelDistA.w;

                float3x3 jointPosDiffB = InputPoses[i].JointPositionsB - DesiredPose.JointPositionsB;

                float3 jointPosDistB = ((jointPosDiffB.c0 * jointPosDiffB.c0) +
                                      (jointPosDiffB.c1 * jointPosDiffB.c1) +
                                      (jointPosDiffB.c2 * jointPosDiffB.c2)) * JointPositionWeightsB;

                jointVelocities = InputPoses[i].JointVelocitiesB;

                jointVelDiff = jointVelocities - DesiredPose.JointVelocitiesB;

                jointVelDist = ((jointVelDiff.c0 * jointVelDiff.c0) +
                                      (jointVelDiff.c1 * jointVelDiff.c1) +
                                      (jointVelDiff.c2 * jointVelDiff.c2)) * JointVelocityWeightsB;

                //Calculate resultant poses
                float4x3 jointResultVel = new float4x3(new float4(jointPosDiffB.c0, 0f),
                                                          new float4(jointPosDiffB.c1, 0f),
                                                          new float4(jointPosDiffB.c2, 0f)) / PoseInterval;

                float4x3 jointResultVelDiff = jointVelocities - jointResultVel;

                float4 jointResultVelDist = ((jointResultVelDiff.c0 * jointResultVelDiff.c0) +
                                      (jointResultVelDiff.c1 * jointResultVelDiff.c1) +
                                      (jointResultVelDiff.c2 * jointResultVelDiff.c2)) * (JointVelocityWeightsB * ResultantVelocityWeight);


                GoalCosts[i] += jointVelDist.x + jointVelDist.y + jointVelDist.z + jointVelDist.w
                                + jointPosDistB.x + jointPosDistB.y + jointPosDistB.z
                                + jointResultVelDist.x + jointResultVelDist.y + jointResultVelDist.z;

            }
        }
Exemple #58
0
 public Plane(float coefficientA, float coefficientB, float coefficientC, float coefficientD)
 {
     NormalAndDistance = Normalize(new float4(coefficientA, coefficientB, coefficientC, coefficientD));
 }
Exemple #59
0
 /// <summary>
 /// Create socket for parentNode. The name has to correspond to the socket name in Cycles.
 /// </summary>
 /// <param name="parentNode"></param>
 /// <param name="name"></param>
 public Float4Socket(ShaderNode parentNode, string name)
     : base(parentNode, name)
 {
     Value = new float4();
 }
        public void Execute(int startIndex, int count)
        {
            for (int i = startIndex; i < startIndex + count; ++i)
            {

                //Calculate Cost of Pose Joint Positions
                float4x3 jointPosDiff = InputPoses[i].JointPositionsA - DesiredPose.JointPositionsA;

                float4 jointPosDist = ((jointPosDiff.c0 * jointPosDiff.c0) +
                                      (jointPosDiff.c1 * jointPosDiff.c1) +
                                      (jointPosDiff.c2 * jointPosDiff.c2)) * JointPositionWeightsA;

                float4x3 jointVelocities = InputPoses[i].JointVelocitiesA;

                //Calculate Cost of Pose Velocity & Joints Velocity
                float4x3 jointVelDiff = jointVelocities - DesiredPose.JointVelocitiesA;

                float4 jointVelDist = ((jointVelDiff.c0 * jointVelDiff.c0) +
                                      (jointVelDiff.c1 * jointVelDiff.c1) +
                                      (jointVelDiff.c2 * jointVelDiff.c2)) * JointVelocityWeightsA;

                float3 bodyVel = (InputPoses[i].BodyVelocity - DesiredPose.BodyVelocity);
                float bodyVelDist = ((bodyVel.x * bodyVel.x) +
                                              (bodyVel.y * bodyVel.y) +
                                              (bodyVel.z * bodyVel.z)) * BodyVelocityWeight;

                //Calculate resultant poses
                float4x3 jointResultVel = jointPosDiff / PoseInterval;
                float4x3 jointResultVelDiff = jointVelocities - jointResultVel;

                float4 jointResultVelDist = ((jointResultVelDiff.c0 * jointResultVelDiff.c0) +
                                      (jointResultVelDiff.c1 * jointResultVelDiff.c1) +
                                      (jointResultVelDiff.c2 * jointResultVelDiff.c2)) * (JointVelocityWeightsA * ResultantVelocityWeight);

                float4 localCost = jointVelDist + jointPosDist + jointResultVelDist;

                //Calculate Cost of Pose Joint Positions
                jointPosDiff = InputPoses[i].JointPositionsB - DesiredPose.JointPositionsB;

                jointPosDist = ((jointPosDiff.c0 * jointPosDiff.c0) +
                                      (jointPosDiff.c1 * jointPosDiff.c1) +
                                      (jointPosDiff.c2 * jointPosDiff.c2)) * JointPositionWeightsB;

                jointVelocities = InputPoses[i].JointPositionsB;

                //Calculate Cost of Pose Velocity & Joints Velocity
                jointVelDiff = jointVelocities - DesiredPose.JointVelocitiesB;

                jointVelDist = ((jointVelDiff.c0 * jointVelDiff.c0) +
                                      (jointVelDiff.c1 * jointVelDiff.c1) +
                                      (jointVelDiff.c2 * jointVelDiff.c2)) * JointVelocityWeightsB;

                //Calculate resultant poses
                jointResultVel = jointPosDiff / PoseInterval;
                jointResultVelDiff = jointVelocities - jointResultVel;

                jointResultVelDist = ((jointResultVelDiff.c0 * jointResultVelDiff.c0) +
                                      (jointResultVelDiff.c1 * jointResultVelDiff.c1) +
                                      (jointResultVelDiff.c2 * jointResultVelDiff.c2)) * (JointVelocityWeightsA * ResultantVelocityWeight);


                localCost += jointVelDist + jointPosDist + jointResultVelDist;

                GoalCosts[i] = localCost.x + localCost.y + localCost.z + localCost.w + bodyVelDist;
            }
        }