public void Dispose() { RsDebug?.Dispose(); _rsCw?.Dispose(); _rsCcw?.Dispose(); LightRenderer.Dispose(); LightMapRenderer.Dispose(); ShadowRenderer.Dispose(); }
public ShadowMappingGame() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; _graphics.PreferredBackBufferWidth = WindowWidth; _graphics.PreferredBackBufferHeight = WindowHeight; const float aspectRatio = (float)WindowWidth / (float)WindowHeight; _projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, aspectRatio, 1.0f, 1000.0f); _shadowRenderer = new ShadowRenderer(); }
public void Load(GraphicsDevice device, GraphicsDeviceManager deviceManager, GameWindow window, Effect fxHull, Effect fxLight, Effect fxShadow, Effect fxTexture) { Device = device; DeviceManager = deviceManager; Window = window; BuildGraphicsResources(); // Load providers. Camera.Load(this); Textures.Load(this); // Load renderers. LightMapRenderer.Load(this, fxTexture); ShadowRenderer.Load(this, fxShadow, fxHull); LightRenderer.Load(this, fxLight); }
void Update() { Shader.SetGlobalVector("preview_LightPos", _pointLight1.transform.position); Shader.SetGlobalColor("preview_LightColor", _pointLight1.color); Shader.SetGlobalFloat("preview_LightGloss", _gloss); Shader.SetGlobalVector("preview_LightPos2", _pointLight2.transform.position); Shader.SetGlobalColor("preview_LightColor2", _pointLight2.color); Shader.SetGlobalFloat("preview_LightGloss2", _gloss); Shader.SetGlobalColor("preview_AmbientColor", _ambient); if (_shadowEnable) { Matrix4x4 shadowmatrix = ShadowRenderer.UpdateShadowMatrix(_shadowPlane.up, _shadowPlane.position.y, _shadowLight.position, 1.0f); Shader.SetGlobalMatrix("preview_shadowmat", shadowmatrix); Shader.SetGlobalColor("preview_shadowcolor", _shadowColor); } }
public void CreateShadows() { Shadows = new ShadowRenderer(GraphicsDevice, 512, 512); }
public void Render() { // Update hulls internal data structures. Hulls.Update(); // We want to use clamping sampler state throughout the lightmap rendering process. // This is required when drawing lights. Since light rendering and alpha clearing is done // in a single step, light is rendered with slightly larger quad where tex coords run out of the [0..1] range. Device.SamplerStates[0] = SamplerState.LinearClamp; // Switch render target to lightmap. Device.SetRenderTargets(Textures.LightmapBindings); // Clear lightmap color, depth and stencil data. Device.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, _ambientColor, 1f, 0); // Set per frame shader data. ShadowRenderer.PreRender(); // Generate lightmap. For each light, mask the shadowed areas determined by hulls and render light. int lightCount = Lights.Count; for (int i = 0; i < lightCount; i++) { Light light = Lights[i]; // Continue only if light is enabled and not inside any hull. if (!light.Enabled || Hulls.Contains(light)) { continue; } // Update light's internal data structures. light.Update(); // Continue only if light is within camera view. if (!light.Intersects(Camera)) { continue; } // Set scissor rectangle to clip any shadows outside of light's range. BoundingRectangle scissor; Camera.GetScissorRectangle(light, out scissor); Device.SetScissorRectangle(ref scissor); // Mask shadowed areas by reducing alpha. ShadowRenderer.Render(light); // Draw light and clear alpha (reset it to 1 [fully lit] for next light). LightRenderer.Render(light); // Clear light's dirty flag. light.Dirty = false; } // Switch render target back to default. Device.SetRenderTargets(Textures.GetOriginalRenderTargetBindings()); // Blend original scene and lightmap and present to backbuffer. LightMapRenderer.Present(); // Clear hulls dirty flag. Hulls.Dirty = false; }
public void UpdateShadowMatrix(Vector3 lightDir, float pointLight, Vector4 shadowRange) { Matrix4x4 shadowMatrix = ShadowRenderer.UpdateShadowMatrix(Vector3.up, -_thisTransform.position.y, lightDir, pointLight); _materialInst.SetShadowMatrix(shadowMatrix, shadowRange); }
// Use this for initialization void Start() { _transform = transform; _effectAnimation = gameObject.transform.FindChild("CameraEffects").gameObject.GetComponent <Animation>(); string cameraPath = _forwardCameraPath; if (GameSettings.Instance.IsDeferredShadingActived()) { cameraPath = _deferredCameraPath; } GameObject camObj = InJoy.AssetBundles.AssetBundles.Load(cameraPath, typeof(GameObject)) as GameObject; camObj = GameObject.Instantiate(camObj) as GameObject; camObj.transform.parent = _cameraParent; camObj.transform.localPosition = Vector3.zero; camObj.transform.localRotation = Quaternion.identity; camObj.transform.localScale = Vector3.one; _coreCamera = camObj.gameObject.GetComponent <Camera>(); _timer = 0.0f; _duration = 1000.0f; _fovFactor = GameSettings.Instance.FovFactor; _shakeCamera = new ShakeCamera(); _shakeCamera.SetAnim(_effectAnimation, _effectAnimation.clip.name); if (_currentCamera == null) { Assertion.Check(_cameraModes.Length > 0); SetCurrentCamera(CameraMode.Standard); } _oldCamera = null; _coreCamera.backgroundColor = RenderSettings.fogColor; LevelLightInfo level = GameObject.FindObjectOfType(typeof(LevelLightInfo)) as LevelLightInfo; Renderer [] sceneRenderers = new Renderer[0]; if (level != null) { sceneRenderers = level.GetComponentsInChildren <Renderer>(); } if (!GameSettings.Instance.IsFullSceneDisplay()) { int layer = LayerMask.NameToLayer("NONE"); foreach (Renderer r in sceneRenderers) { string shaderName = r.sharedMaterial.shader.name; if (shaderName.Contains("(noshadow)")) { r.gameObject.layer = layer; } } } if (GameSettings.Instance.IsDirectionalShadowActived()) { _shadowRT = RenderTexture.GetTemporary(800, 800, 0, RenderTextureFormat.ARGB32); GameObject cameraObj = GameObject.Instantiate(_shadowCamera) as GameObject; _shadowCameraInstance = cameraObj.GetComponentInChildren <Camera>(); if (_shadowCameraInstance != null) { _shadowCameraInstance.targetTexture = _shadowRT; _shadowCameraInstance.enabled = false; _shadowCameraInstance.SetReplacementShader(_shadowShader, ""); _shadowCameraInstance.Render(); _shadowCameraInstance.aspect = 1.0f; foreach (Renderer r in sceneRenderers) { if (null != r && null != r.sharedMaterial) { r.sharedMaterial.SetTexture("_shadowTex", _shadowRT); } } } _shadowCameraTransform = cameraObj.GetComponent <Transform>(); _shadowRenderer = _shadowCameraInstance.GetComponentInChildren <ShadowRenderer>(); GameObject mainLight = GameObject.FindWithTag("MainLight"); if (mainLight != null && _shadowRenderer != null) { _shadowRenderer.SetDirectionalLight(mainLight.transform); } Shader.SetGlobalTexture("_shadowBorder", _shadowBorder); } }
public void ClearLightsVaos() { ShadowRenderer.ClearLightVaos(); }