public bool Render(SceneRenderer renderer, SceneNode root) { if (this.Geometry != null && renderer.ActiveShaderProgram != null) { if (renderer.ActiveCamera != null && this.Geometry.IsCreated(renderer) && !renderer.ActiveCamera.IsInViewFrustum(this, root)) { // geometry is not in the view frustum of the camera return(false); } // upload model matrix IConstantBuffer trans = this.GetWorldTransformBuffer(root); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelTransformation", trans.GetBuffer(renderer)); if (renderer.ActiveCamera != null) { // upload model-view and normal matrix trans = this.GetModelViewTransformBuffer(root, renderer.ActiveCamera); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelViewTransformation", trans.GetBuffer(renderer)); } // render the geometry this.Geometry.Render(renderer); return(true); } return(false); }
public override void Bind(SceneRenderer renderer, SceneNode root) { renderer.ActiveLight = this; if (renderer.ActiveShaderProgram != null && renderer.ActiveCamera != null) { renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightParameters", _lightParamsBuffer.GetBuffer(renderer)); Matrix4 worldTrans = this.GetWorldTransform(root) ?? Matrix4.Identity; Matrix4 invCamTrans = renderer.ActiveCamera.GetInverseWorldTransform(root) ?? Matrix4.Identity; Matrix4 finalTrans = invCamTrans * worldTrans; Vector4 position = finalTrans * new Vector4(0, 0, 0, 1); position /= position.W; Vector3 spotDir = (finalTrans * new Vector4(SpotDirection, 0)).Normalized.XYZ; if (_lightTransBuffer.Value.Position != position || _lightTransBuffer.Value.SpotDirection != spotDir) { _lightTransBuffer.Value = new LightTransformation() { Position = position, SpotDirection = spotDir }; } renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightTransformation", _lightTransBuffer.GetBuffer(renderer)); } }
public void Bind(SceneRenderer renderer, SceneNode root) { if (renderer.ActiveShaderProgram != null) { ClipPlaneParameters parameters = new ClipPlaneParameters(); parameters.ClipPlaneWorldMatrix = this.GetWorldTransform(root).Value; parameters.UseClipPlane = true; _cbuffer.Value = parameters; renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ClipPlaneParameters", _cbuffer.GetBuffer(renderer)); } }
public void Bind(SceneRenderer renderer, SceneNode root) { renderer.ActiveCamera = this; if (renderer.ActiveShaderProgram != null) { // upload projection matrix renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraProjection", _projectionMatrixBuffer.GetBuffer(renderer)); // upload view matrix IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer)); } }
public void BindLightCamera(SceneRenderer renderer, SceneNode root, int shadowMapIdx) { renderer.ActiveCamera = this; _currentShadowMapIdx = shadowMapIdx; if (renderer.ActiveShaderProgram != null) { // upload projection matrix _shadowCascades[_currentShadowMapIdx].BindProjection(renderer); // upload view matrix IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer)); } }
public override void Bind(SceneRenderer renderer, SceneNode root) { renderer.ActiveLight = this; if (renderer.ActiveShaderProgram != null && renderer.ActiveCamera != null) { renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightParameters", _lightParamsBuffer.GetBuffer(renderer)); Matrix4 worldTrans = this.GetWorldTransform(root) ?? Matrix4.Identity; Matrix4 invCamTrans = renderer.ActiveCamera.GetInverseWorldTransform(root) ?? Matrix4.Identity; Matrix4 finalTrans = invCamTrans * worldTrans; Vector4 position = finalTrans * new Vector4(0, 0, -1, 0); Matrix4 viewProj = _projectionMatrix * GetInverseWorldTransform(root) ?? Matrix4.Identity; if (_lightTransBuffer.Value.Position != position || _lightTransBuffer.Value.ViewProjection != viewProj) { _lightTransBuffer.Value = new LightTransformation() { Position = position, ViewProjection = viewProj, }; } renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightTransformation", _lightTransBuffer.GetBuffer(renderer)); if (this.CastShadow) { if (_shadowParametersBuffer.Value != _shadowParameters) { _shadowParametersBuffer.Value = _shadowParameters; } renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightShadowParameters", _shadowParametersBuffer.GetBuffer(renderer)); for (int i = 0; i < this._shadowCascades.Count; i++) { _shadowCascades[i].BindShadowMap(renderer); } } } }
public bool RenderInstanced(SceneRenderer renderer, SceneNode root, int numInstances) { if (this.Geometry != null && renderer.ActiveShaderProgram != null) { // upload model matrix IConstantBuffer trans = this.GetWorldTransformBuffer(root); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelTransformation", trans.GetBuffer(renderer)); if (renderer.ActiveCamera != null) { // upload model-view and normal matrix trans = this.GetModelViewTransformBuffer(root, renderer.ActiveCamera); renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelViewTransformation", trans.GetBuffer(renderer)); } // render the geometry this.Geometry.RenderInstanced(renderer, numInstances); return(true); } return(false); }
public abstract void Bind(SceneRenderer renderer, SceneNode root);