Exemplo n.º 1
0
        public override void UpdateTransform()
        {
            tmpMpos.Set(modelPos);
            tmpMpos.MultiplyStore(-1f);
            rotMatrix.SetToTranslation(tmpMpos);

            tmpRot.Set(modelRot);
            tmpRot.MultiplyStore(poseRot);
            tmpRot.MultiplyStore(localRotation);
            tmpRot.MultiplyStore(invBindRot);

            tmpMatrix.SetToRotation(tmpRot);
            rotMatrix.MultiplyStore(tmpMatrix);
            tmpMpos.MultiplyStore(-1f);
            tmpMatrix.SetToTranslation(tmpMpos);
            rotMatrix.MultiplyStore(tmpMatrix);
            tmpMatrix.SetToTranslation(localTranslation);
            rotMatrix.MultiplyStore(tmpMatrix);
            boneMatrix.Set(rotMatrix);
            if (parentBone != null)
            {
                boneMatrix.MultiplyStore(parentBone.boneMatrix);
            }
            for (int i = 0; i < children.Count; i++)
            {
                if (children[i] is Bone)
                {
                    Bone b = (Bone)children[i];
                    b.UpdateTransform();
                }
            }
        }
Exemplo n.º 2
0
        public override void Update()
        {
            this.shadowMap0 = parent.ShadowCams[0].ShadowMap;
            this.shadowMap1 = parent.ShadowCams[1].ShadowMap;
            this.shadowMap2 = parent.ShadowCams[2].ShadowMap;
            this.shadowMap3 = parent.ShadowCams[3].ShadowMap;
            this.shadowMapViewProjTrans0 = parent.ShadowCams[0].ViewProjectionMatrix;
            this.shadowMapViewProjTrans1 = parent.ShadowCams[1].ViewProjectionMatrix;
            this.shadowMapViewProjTrans2 = parent.ShadowCams[2].ViewProjectionMatrix;
            this.shadowMapViewProjTrans3 = parent.ShadowCams[3].ViewProjectionMatrix;
            this.splits = parent.Splits;

            camMat.SetToLookAt(cam.Translation, cam.Translation.Add(new Vector3f(0, 0, -1)), cam.Up);
            camMat.MultiplyStore(cam.ProjectionMatrix);
            shader.SetUniform("u_camMat", camMat);
            Texture.ActiveTextureSlot(0);
            shadowMap0.Use();
            Texture.ActiveTextureSlot(1);
            shadowMap1.Use();
            Texture.ActiveTextureSlot(2);
            shadowMap2.Use();
            Texture.ActiveTextureSlot(3);
            shadowMap3.Use();
            Texture.ActiveTextureSlot(4);
            depthTexture.Use();
            Texture.ActiveTextureSlot(5);
            colorTexture.Use();
            Texture.ActiveTextureSlot(6);
            noiseMap.Use();

            shader.SetUniform("u_shadowMap0", 0);
            shader.SetUniform("u_shadowMap1", 1);
            shader.SetUniform("u_shadowMap2", 2);
            shader.SetUniform("u_shadowMap3", 3);
            shader.SetUniform("u_depthTexture", 4);
            shader.SetUniform("u_sceneTexture", 5);
            shader.SetUniform("u_noiseTexture", 6);
            shader.SetUniform("u_shadowMapViewProjTrans0", shadowMapViewProjTrans0);
            shader.SetUniform("u_shadowMapViewProjTrans1", shadowMapViewProjTrans1);
            shader.SetUniform("u_shadowMapViewProjTrans2", shadowMapViewProjTrans2);
            shader.SetUniform("u_shadowMapViewProjTrans3", shadowMapViewProjTrans3);
            shader.SetUniform("u_cameraPosition", cam.Translation);
            shader.SetUniform("u_invViewProj", cam.InverseViewProjectionMatrix);
            shader.SetUniform("u_view", cam.ViewMatrix);
            shader.SetUniform("u_proj", cam.ProjectionMatrix);

            if (debugMode)
            {
                shader.SetUniform("B_debugMode", 1);
            }
            else
            {
                shader.SetUniform("B_debugMode", 0);
            }
            for (int i = 0; i < splits.Length; i++)
            {
                shader.SetUniform("splits[" + i + "]", splits[i]);
            }
        }
Exemplo n.º 3
0
 public void Update()
 {
     UpdateFrustumPoints(fPoints);
     centerPos.Set(0, 0, 0);
     frustumCornersWS = fPoints;
     for (int i = 0; i < 8; i++)
     {
         centerPos.AddStore(frustumCornersWS[i]);
     }
     centerPos.DivideStore(8f);
     newView.SetToLookAt(tmpVec.Set(centerPos).SubtractStore(lightDirection), centerPos, Vector3f.UnitY);
     Transform(ref frustumCornersWS, ref frustumCornersLS, ref newView);
     maxes.Set(float.MinValue, float.MinValue, float.MinValue);
     mins.Set(float.MaxValue, float.MaxValue, float.MaxValue);
     for (int i = 0; i < frustumCornersLS.Length; i++)
     {
         if (frustumCornersLS[i].x > maxes.x)
         {
             maxes.x = frustumCornersLS[i].x;
         }
         else if (frustumCornersLS[i].x < mins.x)
         {
             mins.x = frustumCornersLS[i].x;
         }
         if (frustumCornersLS[i].y > maxes.y)
         {
             maxes.y = frustumCornersLS[i].y;
         }
         else if (frustumCornersLS[i].y < mins.y)
         {
             mins.y = frustumCornersLS[i].y;
         }
         if (frustumCornersLS[i].z > maxes.z)
         {
             maxes.z = frustumCornersLS[i].z;
         }
         else if (frustumCornersLS[i].z < mins.z)
         {
             mins.z = frustumCornersLS[i].z;
         }
     }
     s_cam.ViewMatrix = newView;
     s_cam.ProjectionMatrix.SetToOrtho(mins.x, maxes.x, mins.y, maxes.y, -splits[3], splits[3]);
     viewProjectionMatrix.Set(s_cam.ViewMatrix);
     viewProjectionMatrix.MultiplyStore(s_cam.ProjectionMatrix);
     s_cam.ViewProjectionMatrix.Set(s_cam.ViewMatrix);
     s_cam.ViewProjectionMatrix.MultiplyStore(s_cam.ProjectionMatrix);
     s_cam.InverseViewProjectionMatrix.Set(s_cam.ViewProjectionMatrix);
     s_cam.InverseViewProjectionMatrix.InvertStore();
 }