private void SetCamera() { Camera cam = ResourceManager.Instance.CurrentScene.Cam; if (cam == null) { return; } else if (!varsSet) { myProjs[0] = Matrix.CreatePerspectiveFieldOfView(cam.FOV, cam.Ratio, cam.Near, CAM_DIRECTIONAL_BOUNDARIES[0]); myProjs[1] = Matrix.CreatePerspectiveFieldOfView(cam.FOV, cam.Ratio, CAM_DIRECTIONAL_BOUNDARIES[0], CAM_DIRECTIONAL_BOUNDARIES[1]); myProjs[2] = Matrix.CreatePerspectiveFieldOfView(cam.FOV, cam.Ratio, CAM_DIRECTIONAL_BOUNDARIES[1], CAM_DIRECTIONAL_BOUNDARIES[2]); bfs[0] = new BoundingFrustumExtended(cam.ViewMatrix * myProjs[0]); bfs[1] = new BoundingFrustumExtended(cam.ViewMatrix * myProjs[1]); bfs[2] = new BoundingFrustumExtended(cam.ViewMatrix * myProjs[2]); varsSet = true; } for (int i = 0; i < CAMERA_COUNT; ++i) { bfs[i].Matrix = cam.ViewMatrix * myProjs[i]; Vector3[] corners = bfs[i].GetCorners(); uint cornerCount = (uint)corners.Count(); Vector3 middlePoint = Vector3.Zero; for (uint j = 0; j < cornerCount; ++j) { middlePoint.X += corners[j].X; middlePoint.Y += corners[j].Y; middlePoint.Z += corners[j].Z; } middlePoint.X /= cornerCount; middlePoint.Y = Math.Max(middlePoint.Y, 0.0f); middlePoint.Y /= cornerCount; middlePoint.Z /= cornerCount; shadowDrawCameras[i].Position = middlePoint + CAM_DIRECTIONAL_DISTANCE * new Vector3(-LightDirection.X, -LightDirection.Y, -LightDirection.Z); shadowDrawCameras[i].Target = middlePoint; shadowDrawCameras[i].Update(null); } }
public override void UpdateEffect(Effect effect, Microsoft.Xna.Framework.Matrix world, Microsoft.Xna.Framework.Matrix worldViewProj, LightAmbient amb, LightDirectional[] dirs, List <LightPoint> points, Texture dSM, TextureCube point0SM, Microsoft.Xna.Framework.Vector3 eyeVector, BoundingFrustumExtended frustum, Microsoft.Xna.Framework.Matrix[] bones, Microsoft.Xna.Framework.GameTime gameTime) { if (epCubeMap1 != null) { epCubeMap1.SetValue(CubeMap1); } if (epCubeMap2 != null) { epCubeMap2.SetValue(CubeMap2); } if (epCubeMap3 != null) { epCubeMap3.SetValue(CubeMap3); } if (epProbes != null) { epProbes.SetValue(Probes); } base.UpdateEffect(effect, world, worldViewProj, amb, dirs, points, dSM, point0SM, eyeVector, frustum, bones, gameTime); }
public override void UpdateEffect(Effect effect, Matrix world, Matrix worldViewProj, LightAmbient amb, LightDirectional[] dirs, List <LightPoint> points, Texture dSM, TextureCube point0SM, Vector3 eyeVector, BoundingFrustumExtended frustum, Matrix[] bones, GameTime gameTime) { if (epMirrorMap != null) { epMirrorMap.SetValue(ResourceManager.Instance.Textures["DefaultDiffuse"]); } if (!isRendering && TrashSoupGame.Instance.ActualRenderTarget == TrashSoupGame.Instance.DefaultRenderTarget && effect == null) { isRendering = true; TrashSoupGame.Instance.ActualRenderTarget = MirrorRenderTarget; SetupCamera(world); //tempCamera = ResourceManager.Instance.CurrentScene.Cam; //ResourceManager.Instance.CurrentScene.Cam = myCamera; bool currentShadows = ResourceManager.Instance.CurrentScene.Params.Shadows; ResourceManager.Instance.CurrentScene.Params.Shadows = false; ResourceManager.Instance.CurrentScene.DrawAll(myCamera, effect, TrashSoupGame.Instance.TempGameTime, false); ResourceManager.Instance.CurrentScene.Params.Shadows = currentShadows; //ResourceManager.Instance.CurrentScene.Cam = tempCamera; TrashSoupGame.Instance.ActualRenderTarget = TrashSoupGame.Instance.DefaultRenderTarget; isRendering = false; this.MirrorMap = MirrorRenderTarget; if (epMirrorMap != null) { epMirrorMap.SetValue(this.MirrorMap); } } base.UpdateEffect(effect, world, worldViewProj, amb, dirs, points, dSM, point0SM, eyeVector, frustum, bones, gameTime); }
public virtual void UpdateEffect(Effect effect, Matrix world, Matrix worldViewProj, LightAmbient amb, LightDirectional[] dirs, List <LightPoint> points, Texture dSM, TextureCube point0SM, Vector3 eyeVector, BoundingFrustumExtended frustum, Matrix[] bones, GameTime gameTime) { if (effect != null && tempEffect == null) { tempEffect = MyEffect; MyEffect = effect; AssignParamsInitialize(); } if (epWorld != null) { epWorld.SetValue(world); } if (epWorldInverseTranspose != null) { epWorldInverseTranspose.SetValue(Matrix.Transpose(Matrix.Invert(world))); } if (epWorldViewProj != null) { epWorldViewProj.SetValue(worldViewProj); } if (epDiffuseMap != null) { epDiffuseMap.SetValue(DiffuseMap); } if (epNormalMap != null) { epNormalMap.SetValue(NormalMap); } if (epCubeMap != null) { epCubeMap.SetValue(CubeMap); } if (epDiffuseColor != null) { epDiffuseColor.SetValue(diffuseColor); } if (epSpecularColor != null) { epSpecularColor.SetValue(specularColor); } if (epGlossiness != null) { epGlossiness.SetValue(glossiness); } if (epReflectivityColor != null) { epReflectivityColor.SetValue(reflectivityColor); } if (epReflectivityBias != null) { epReflectivityBias.SetValue(reflectivityBias); } if (epTransparency != null) { epTransparency.SetValue(transparency); } if (epPerPixelLighting != null) { epPerPixelLighting.SetValue(perPixelLighting); } if (epAmbientLightColor != null && amb != null) { epAmbientLightColor.SetValue(amb.LightColor); } if (dirs != null) { if (dirs[0] != null) { if (epDirLight0Direction != null) { epDirLight0Direction.SetValue(dirs[0].LightDirection); } if (epDirLight0DiffuseColor != null) { epDirLight0DiffuseColor.SetValue(dirs[0].LightColor); } if (epDirLight0SpecularColor != null) { epDirLight0SpecularColor.SetValue(dirs[0].LightSpecularColor); } if (dirs[0].CastShadows) { if (epDirLight0ShadowMap0 != null && dSM != null) { epDirLight0ShadowMap0.SetValue(dSM); } if (epDirLight0WorldViewProj != null && dirs[0].ShadowDrawCameras[0] != null) { epDirLight0WorldViewProj.SetValue(world * dirs[0].ShadowDrawCameras[0].ViewProjMatrix); } if (epDirLight0WorldViewProj1 != null && dirs[0].ShadowDrawCameras[1] != null) { epDirLight0WorldViewProj1.SetValue(world * dirs[0].ShadowDrawCameras[1].ViewProjMatrix); } if (epDirLight0WorldViewProj2 != null && dirs[0].ShadowDrawCameras[2] != null) { epDirLight0WorldViewProj2.SetValue(world * dirs[0].ShadowDrawCameras[2].ViewProjMatrix); } } } if (dirs[1] != null) { if (epDirLight1Direction != null) { epDirLight1Direction.SetValue(dirs[1].LightDirection); } if (epDirLight1DiffuseColor != null) { epDirLight1DiffuseColor.SetValue(dirs[1].LightColor); } if (epDirLight1SpecularColor != null) { epDirLight1SpecularColor.SetValue(dirs[1].LightSpecularColor); } } if (dirs[2] != null) { if (epDirLight2Direction != null) { epDirLight2Direction.SetValue(dirs[2].LightDirection); } if (epDirLight2DiffuseColor != null) { epDirLight2DiffuseColor.SetValue(dirs[2].LightColor); } if (epDirLight2SpecularColor != null) { epDirLight2SpecularColor.SetValue(dirs[2].LightSpecularColor); } } } if (points != null) { for (int i = 0; i < ResourceManager.POINT_MAX_LIGHTS_PER_OBJECT; ++i) { tempPLColors[i] = new Vector3(0.0f, 0.0f, 0.0f); tempPLSpeculars[i] = new Vector3(0.0f, 0.0f, 0.0f); tempPLPositions[i] = new Vector3(0.0f, 0.0f, 0.0f); tempPLAttenuations[i] = 0.00000001f; } int pCount = points.Count; if (epSSA != null) { epSSA.SetValue(1.0f); } for (int i = 0; i < pCount && i < ResourceManager.POINT_MAX_LIGHTS_PER_OBJECT; ++i) { if (points[i].CastShadows && epSSA != null) { epSSA.SetValue(0.0f); } tempPLColors[i] = points[i].LightColor; tempPLSpeculars[i] = points[i].LightSpecularColor; tempPLPositions[i] = points[i].MyTransform.PositionGlobal; tempPLAttenuations[i] = points[i].Attenuation; } if (epPointLightDiffuseColors != null) { epPointLightDiffuseColors.SetValue(tempPLColors); } if (epPointLightSpecularColors != null) { epPointLightSpecularColors.SetValue(tempPLSpeculars); } if (epPointLightPositions != null) { epPointLightPositions.SetValue(tempPLPositions); } if (epPointLightAttenuations != null) { epPointLightAttenuations.SetValue(tempPLAttenuations); } if (epPointLightCount != null) { epPointLightCount.SetValue(points.Count); } if (epPoint0ShadowMap != null && point0SM != null) { epPoint0ShadowMap.SetValue(point0SM); } } if (epEyePosition != null) { epEyePosition.SetValue(eyeVector); } // bounding frustum tempFrustumArray[0].W = -frustum.Top.D + BoundingFrustumExtended.CLIP_MARGIN; tempFrustumArray[0].X = -frustum.Top.Normal.X; tempFrustumArray[0].Y = -frustum.Top.Normal.Y; tempFrustumArray[0].Z = -frustum.Top.Normal.Z; tempFrustumArray[1].W = -frustum.Bottom.D + BoundingFrustumExtended.CLIP_MARGIN; tempFrustumArray[1].X = -frustum.Bottom.Normal.X; tempFrustumArray[1].Y = -frustum.Bottom.Normal.Y; tempFrustumArray[1].Z = -frustum.Bottom.Normal.Z; tempFrustumArray[2].W = -frustum.Left.D + BoundingFrustumExtended.CLIP_MARGIN; tempFrustumArray[2].X = -frustum.Left.Normal.X; tempFrustumArray[2].Y = -frustum.Left.Normal.Y; tempFrustumArray[2].Z = -frustum.Left.Normal.Z; tempFrustumArray[3].W = -frustum.Right.D + BoundingFrustumExtended.CLIP_MARGIN; tempFrustumArray[3].X = -frustum.Right.Normal.X; tempFrustumArray[3].Y = -frustum.Right.Normal.Y; tempFrustumArray[3].Z = -frustum.Right.Normal.Z; if (epBoundingFrustum != null) { epBoundingFrustum.SetValue(tempFrustumArray); } additionalClipPlane.W = -frustum.AdditionalClip.D; additionalClipPlane.X = -frustum.AdditionalClip.Normal.X; additionalClipPlane.Y = -frustum.AdditionalClip.Normal.Y; additionalClipPlane.Z = -frustum.AdditionalClip.Normal.Z; if (epCustomClippingPlane != null) { epCustomClippingPlane.SetValue(additionalClipPlane); } if (epBones != null && bones != null) { epBones.SetValue(bones); this.MyEffect.CurrentTechnique = etSkinned; } // setting up techniques bool shadows = ResourceManager.Instance.CurrentScene.Params.Shadows; bool softShadows = ResourceManager.Instance.CurrentScene.Params.SoftShadows; if (tempBEref == null && tempSEref == null) { bool forShadows = ((dirs != null && dirs[0] != null && dirs[0].CastShadows) || (point0SM != null)) && RecieveShadows && shadows; if ((Unlit || TrashSoupGame.Instance.EditorMode) && etUnlit != null) { MyEffect.CurrentTechnique = etUnlit; } else if (bones != null && forShadows && etSkinnedBlurredShadows != null && softShadows) { MyEffect.CurrentTechnique = etSkinnedBlurredShadows; } else if (bones == null && forShadows && etMainBlurredShadows != null && softShadows) { MyEffect.CurrentTechnique = etMainBlurredShadows; } else if (bones != null && forShadows && etSkinnedShadows != null) { MyEffect.CurrentTechnique = etSkinnedShadows; } else if (bones == null && forShadows && etMainShadows != null) { MyEffect.CurrentTechnique = etMainShadows; } else if (bones != null && etSkinned != null) { MyEffect.CurrentTechnique = etSkinned; } else { MyEffect.CurrentTechnique = etMain; } } ////////////////////// ////////////////////// if (tempBEref != null) { // do shit for basicEffect tempBEref.PreferPerPixelLighting = perPixelLighting; } if (tempSEref != null) { // do shit for skinnedEffect tempSEref.PreferPerPixelLighting = perPixelLighting; } }
public override void UpdateEffect(Effect effect, Matrix world, Matrix worldViewProj, LightAmbient amb, LightDirectional[] dirs, List <LightPoint> points, Texture dSM, TextureCube point0SM, Vector3 eyeVector, BoundingFrustumExtended frustum, Matrix[] bones, GameTime gameTime) { if (effect != null) { base.UpdateEffect(null, new Matrix(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), new Matrix(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), null, null, null, null, null, Vector3.Zero, new BoundingFrustumExtended(Matrix.Identity), null, null); return; } if (!isRendering && TrashSoupGame.Instance.ActualRenderTarget == TrashSoupGame.Instance.DefaultRenderTarget && effect == null) { isRendering = true; DrawRefractionMap(effect, world); DrawReflectionMap(effect, world); if (!TrashSoupGame.Instance.EditorMode) { tempWind += ResourceManager.Instance.CurrentScene.Params.Wind * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f; } if (epWindVector != null) { epWindVector.SetValue(tempWind); } isRendering = false; } base.UpdateEffect(effect, world, worldViewProj, amb, dirs, points, dSM, point0SM, eyeVector, frustum, bones, gameTime); }