/// <summary> /// Set of lines in 3D space. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public LineBall(Plane plane, LineSet lines, RenderEffect effect = RenderEffect.DEFAULT, Colormap colormap = Colormap.Parula, bool flatten = false) { _thickness = lines.Thickness * plane.PointSize; _color = lines.Color; this._vertexSizeBytes = Marshal.SizeOf(typeof(Vector4)); this._numVertices = lines.NumPoints * 2 - lines.Lines.Length * 2; // Linelist means, all points are there twice, minus the endpoints. if (_numVertices == 0) return; this._topology = PrimitiveTopology.LineList; // Setting up the vertex buffer. if (!flatten) GenerateGeometry(plane, lines); else GenerateGeometryFlatXY(plane, lines); //this._technique = _lineEffect.GetTechniqueByName("Render"); UsedMap = colormap; _planeNormal = plane.ZAxis; _planeNormal.Normalize(); _effect = _lineEffect; SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("SCALAR", 0, Format.R32_Float, 12, 0) }); }
/// <summary> /// Plane to display scalar/vector field data on. Condition: Fields domain is 2D. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public FieldPlane(Plane plane, VectorField fields, RenderEffect effect = RenderEffect.DEFAULT, Colormap map = Colormap.Parula) { #if DEBUG // Assert that the fields are 2 dimensional. foreach(Field field in fields.Scalars) System.Diagnostics.Debug.Assert(field.Size.Length >= 2); #endif this._effect = _planeEffect; this._vertexSizeBytes = 32; this._numVertices = 6; this.UsedMap = map; this._width = fields[0].Size[0]; this._height = fields[0].Size[1]; this._invalid = fields.InvalidValue ?? float.MaxValue; this._field = fields; // Setting up the vertex buffer. GenerateGeometry(plane, fields[0].Size.ToInt2(), fields.TimeSlice??0); // Generating Textures from the fields. _fieldTextures = new ShaderResourceView[fields.Scalars.Length]; for(int f = 0; f < _field.NumVectorDimensions; ++f) { Texture2D tex = ColorMapping.GenerateTextureFromField(_device, fields[f]); _fieldTextures[f] = new ShaderResourceView(_device, tex); } this.SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXTURE", 0, Format.R32G32B32A32_Float, 16, 0) }); }
/// <summary> /// Set of lines in 3D space. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public LineBall(Plane plane, LineSet lines, RenderEffect effect = RenderEffect.DEFAULT, Colormap colormap = Colormap.Parula, bool flatten = false, float flattenToTime = 0) { _thickness = lines.Thickness * plane.PointSize; _color = lines.Color; this._vertexSizeBytes = Marshal.SizeOf(typeof(Vector4)); this._numVertices = lines.NumPoints * 2 - lines.Lines.Length * 2; // Linelist means, all points are there twice, minus the endpoints. if (_numVertices == 0) { return; } this._topology = PrimitiveTopology.LineList; // Setting up the vertex buffer. if (!flatten) { GenerateGeometry(plane, lines); } else { GenerateGeometryFlatXY(plane, lines, flattenToTime); } //this._technique = _lineEffect.GetTechniqueByName("Render"); UsedMap = colormap; _planeNormal = plane.ZAxis; _planeNormal.Normalize(); _effect = _lineEffect; SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("SCALAR", 0, Format.R32_Float, 12, 0) }); }
public override void ApplyEffectPermutations(RenderEffect renderEffect) { var lightVoxel = (LightVoxel)Light.Type; var lightDiffuseVoxelColorShader = IsotropicVoxelColorSource; renderEffect.EffectValidator.ValidateParameter(lightDiffuseVoxelColorKey, lightDiffuseVoxelColorShader); }
/// <summary> /// Render all ghost effects /// </summary> /// <param name="camera"></param> private void RenderGhosts(Camera camera) { if (ghostList.Count > 0) { if (ghostList.Count > 1) { ghostList.Sort(_CompareGhostByDist); } RenderEffect was = renderEffects; renderEffects = RenderEffect.GhostPass; for (int i = 0; i < ghostList.Count; ++i) { float opacity = ghostList[i].Opacity; float glow = ghostList[i].Glow; ShaderGlobals.FixExplicitBloom(glow); ShaderGlobals.FixBloomColor(new Vector4(opacity, opacity, opacity, 1.0f)); ghostList[i].Actor.RenderObject.Render(camera); } ShaderGlobals.ReleaseExplicitBloom(); ShaderGlobals.ReleaseBloomColor(); renderEffects = was; } }
public void SetRenderEffect(RenderEffect effect) { switch (effect) { default: this._technique = _meshEffect.GetTechniqueByName("Height"); break; } }
public ModelRenderBatch(IReadOnlyList <AModel> models, IViewPoint viewPoint, TextureCube skybox) { this.Models = models; this.ViewPoint = viewPoint; this.Skybox = skybox; this.Effect = new RenderEffect(); var viewProjection = viewPoint.View * viewPoint.Projection; this.InverseViewProjection = Matrix.Invert(viewProjection); }
public LightShaderPermutationEntry(RenderEffect renderEffect) { RenderEffect = renderEffect; ParameterCollectionEntryPool = new PoolListStruct <LightParametersPermutationEntry>(1, CreateParameterCollectionEntry); DirectLightGroups = new List <LightShaderGroup>(); EnvironmentLights = new List <LightShaderGroup>(); DirectLightShaders = new ShaderSourceCollection(); EnvironmentLightShaders = new ShaderSourceCollection(); }
public void ApplyEffectPermutations(RenderEffect renderEffect) { foreach (var lightGroup in DirectLightGroupDatas) { lightGroup.ApplyEffectPermutations(renderEffect); } foreach (var lightGroup in EnvironmentLightDatas) { lightGroup.ApplyEffectPermutations(renderEffect); } }
public void SetRenderEffect(RenderEffect effect) { // Ad length texture. if (effect == RenderEffect.LIC_LENGTH && Effect != RenderEffect.LIC_LENGTH && _field != null) { VectorField length = new VectorField(_field, FieldAnalysis.VFLength, 1, false); this.AddScalar(length[0] as ScalarField); } // Remove length texture? else if (effect != RenderEffect.LIC_LENGTH && Effect == RenderEffect.LIC_LENGTH && _field != null) { ShaderResourceView[] cpy = _fieldTextures; _fieldTextures = new ShaderResourceView[cpy.Length - 1]; Array.Copy(cpy, _fieldTextures, _fieldTextures.Length); } switch (effect) { case RenderEffect.LIC: case RenderEffect.LIC_LENGTH: //Debug.Assert(_fields.Length >= 2); this._technique = _planeEffect.GetTechniqueByName("RenderLIC" + _fieldTextures.Length); break; case RenderEffect.CHECKERBOARD: this._technique = _planeEffect.GetTechniqueByName("RenderChecker"); break; case RenderEffect.CHECKERBOARD_COLORMAP: this._technique = _planeEffect.GetTechniqueByName("RenderCheckerTex" + _fieldTextures.Length); break; case RenderEffect.OVERLAY: this._technique = _planeEffect.GetTechniqueByName("Overlay" + _fieldTextures.Length); break; case RenderEffect.LAPLACE: this._technique = _planeEffect.GetTechniqueByName("Laplace" + _fieldTextures.Length); break; case RenderEffect.GRADIENT: this._technique = _planeEffect.GetTechniqueByName("Gradient" + _fieldTextures.Length); break; case RenderEffect.COLORMAP: default: this._technique = _planeEffect.GetTechniqueByName("RenderTex" + _fieldTextures.Length); break; } Effect = effect; }
public override void ApplyEffectPermutations(RenderEffect renderEffect) { var lightSkybox = (LightSkybox)Light.Type; var skybox = lightSkybox.Skybox; var diffuseParameters = skybox.DiffuseLightingParameters; var specularParameters = skybox.SpecularLightingParameters; var lightDiffuseColorShader = diffuseParameters.Get(SkyboxKeys.Shader) ?? EmptyComputeEnvironmentColorSource; var lightSpecularColorShader = specularParameters.Get(SkyboxKeys.Shader) ?? EmptyComputeEnvironmentColorSource; renderEffect.EffectValidator.ValidateParameterThreaded(lightDiffuseColorKey, lightDiffuseColorShader); renderEffect.EffectValidator.ValidateParameterThreaded(lightSpecularColorKey, lightSpecularColorShader); }
public GeometrySystem( GraphicsDevice device, EffectFactory effectFactory, IComponentContainer <Geometry> geometries, IComponentContainer <Pose> poses, IComponentContainer <Bounds> bounds) { this.Device = device; this.Geometries = geometries; this.Poses = poses; this.Bounds = bounds; this.Effect = effectFactory.Construct <RenderEffect>(); }
protected override void Dispose(bool disposing) { if (disposing) { foreach (var RenderEffect in RenderEffects) { RenderEffect.Dispose(); } TextureManager.GetInstance().Dispose(); } base.Dispose(disposing); }
/// <summary> /// 檢查對應編號特效是否使用RenderEffect. /// </summary> /// <returns>RenderEffect元件.</returns> /// <param name="nIndex">特效編號.</param> public RenderEffect CheckHasRenderEffectScript(int nIndex) { /// 取得特效物件. Transform tf = this.transform.Find(nIndex.ToString()); if (tf == null) { return(null); } /// 取得RenderEffect元件. RenderEffect renderEffect = tf.gameObject.GetComponent <RenderEffect> (); return(renderEffect); }
/// <summary> /// It assumes that this shader is not the default LPP shader, and it will use ONLY the first technique /// </summary> /// <param name="camera"></param> /// <param name="graphicsDevice"></param> /// <param name="renderStatistics"></param> public void GenericRender(Camera camera, GraphicsDevice graphicsDevice) { RenderEffect.SetMatrices(GlobalTransform, camera.EyeTransform, camera.ProjectionTransform); if (_parent.BoneMatrixes != null) { RenderEffect.SetBones(_parent.BoneMatrixes); } RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(_meshPart.VertexBuffer, _meshPart.VertexOffset); graphicsDevice.Indices = _meshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _meshPart.NumVertices, _meshPart.StartIndex, _meshPart.PrimitiveCount); }
public void SetRenderEffect(RenderEffect effect) { switch (effect) { case RenderEffect.THIN: this._technique = _lineEffect.GetTechniqueByName("Simple"); break; case RenderEffect.HEIGHT: this._technique = _lineEffect.GetTechniqueByName("Height"); break; default: this._technique = _lineEffect.GetTechniqueByName("Render"); break; } }
public virtual void RenderToGBuffer(Camera camera, GraphicsDevice graphicsDevice) { RenderEffect.SetCurrentTechnique(0); RenderEffect.SetMatrices(GlobalTransform, camera.EyeTransform, camera.ProjectionTransform); //our first pass is responsible for rendering into GBuffer RenderEffect.SetFarClip(camera.FarClip); if (_parent.BoneMatrixes != null) { RenderEffect.SetBones(_parent.BoneMatrixes); } RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(_meshPart.VertexBuffer, _meshPart.VertexOffset); graphicsDevice.Indices = _meshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _meshPart.NumVertices, _meshPart.StartIndex, _meshPart.PrimitiveCount); }
public void ReconstructShading(Camera camera, GraphicsDevice graphicsDevice) { //this pass uses the light diffuse and specular accumulation texture (already bound in the setup stage) and reconstruct the mesh's shading //our parameters were already filled in the first pass RenderEffect.SetCurrentTechnique(1); //we don't need to do this again, it was done on the previous step //_renderEffect.SetMatrices(GlobalTransform, camera.EyeTransform, camera.ProjectionTransform); // if (_parent.BoneMatrixes != null) // _renderEffect.SetBones(_parent.BoneMatrixes); RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(_meshPart.VertexBuffer, _meshPart.VertexOffset); graphicsDevice.Indices = _meshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _meshPart.NumVertices, _meshPart.StartIndex, _meshPart.PrimitiveCount); }
private void DrawModel(RenderEffectTechniques technique, AModel modelPose, Matrix world, IViewPoint viewPoint) { var model = modelPose.Model; var bones = model.Bones.Count; if (SharedBoneMatrix is null || SharedBoneMatrix.Length < bones) { SharedBoneMatrix = new Matrix[bones]; } model.CopyAbsoluteBoneTransformsTo(SharedBoneMatrix); for (var iMesh = 0; iMesh < model.Meshes.Count; iMesh++) { var mesh = model.Meshes[iMesh]; for (var iEffect = 0; iEffect < mesh.Effects.Count; iEffect++) { var effect = mesh.Effects[iEffect]; this.Effect.Wrap(effect); if (modelPose.HasAnimations && RenderEffect.TechniqueSupportsSkinning(technique)) { technique = RenderEffect.GetSkinnedTechnique(technique); this.Effect.BoneTransforms = modelPose.SkinTransforms; } this.Effect.TextureOffset = modelPose.UVOffsets[iMesh]; this.Effect.World = SharedBoneMatrix[mesh.ParentBone.Index] * world; this.Effect.View = viewPoint.View; this.Effect.Projection = viewPoint.Projection; this.Effect.InverseViewProjection = this.InverseViewProjection; this.Effect.Skybox = this.Skybox; this.Effect.CameraPosition = viewPoint.Position; this.Effect.TextureScale = modelPose.TextureScale; this.Effect.Apply(technique); } mesh.Draw(); } }
public override void ApplyEffectPermutations(RenderEffect renderEffect) { if (traceAttribute != null) { ShaderSourceCollection collection = new ShaderSourceCollection { traceAttribute.GetSamplingShader() }; renderEffect.EffectValidator.ValidateParameter(attributeSamplersKey, collection); if (((LightVoxel)Light.Type).DiffuseMarcher != null) { renderEffect.EffectValidator.ValidateParameter(diffuseMarcherKey, ((LightVoxel)Light.Type).DiffuseMarcher.GetMarchingShader(0)); } if (((LightVoxel)Light.Type).SpecularMarcher != null) { renderEffect.EffectValidator.ValidateParameter(specularMarcherKey, ((LightVoxel)Light.Type).SpecularMarcher.GetMarchingShader(0)); } } }
//private Buffer _indices; /// <summary> /// Set of lines in 3D space. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public Mesh(Plane plane, TileSurface surf, RenderEffect effect = RenderEffect.DEFAULT, Colormap colormap = Colormap.Parula) { _color = surf.Color; this._vertexSizeBytes = Marshal.SizeOf(typeof(Vector4)); this._topology = PrimitiveTopology.TriangleList; this. // Setting up the vertex buffer. UsedMap = colormap; _planeNormal = plane.ZAxis; _planeNormal.Normalize(); _effect = _meshEffect; SetRenderEffect(effect); GenerateGeometry(plane, surf); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("SCALAR", 0, Format.R32_Float, 12, 0) }); }
public virtual void RenderShadowMap(ref Matrix viewProj, GraphicsDevice graphicsDevice) { //render to shadow map RenderEffect.SetCurrentTechnique(2); RenderEffect.SetLightViewProj(viewProj); //we need to set this every frame, there are situations where the object is not on screen but it still cast shadows _renderEffect.SetWorld(GlobalTransform); if (_parent.BoneMatrixes != null) { _renderEffect.SetBones(_parent.BoneMatrixes); } RenderEffect.Apply(); graphicsDevice.SetVertexBuffer(_meshPart.VertexBuffer, _meshPart.VertexOffset); graphicsDevice.Indices = _meshPart.IndexBuffer; graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _meshPart.NumVertices, _meshPart.StartIndex, _meshPart.PrimitiveCount); }
public FieldPlane(Plane plane, Texture2D field, Int2 texSize, float timeSlice = 0, float invalidValue = float.MaxValue, RenderEffect effect = RenderEffect.DEFAULT, Colormap map = Colormap.Parula) { this._effect = _planeEffect; this._vertexSizeBytes = 32; this._numVertices = 6; this.UsedMap = map; this._width = texSize.X; this._height = texSize.Y; this._invalid = invalidValue; // Setting up the vertex buffer. GenerateGeometry(plane, texSize, timeSlice); // Generating Textures from the fields. _fieldTextures = new ShaderResourceView[1]; _fieldTextures[0] = new ShaderResourceView(_device, field); this.SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXTURE", 0, Format.R32G32B32A32_Float, 16, 0) }); }
private LightShaderPermutationEntry CreateShaderPermutationEntry(RenderEffect renderEffect) { var shaderEntry = new LightShaderPermutationEntry(renderEffect); // Direct Lights (with or without shadows) for (int i = 0; i < directLightShaderGroupEntryKeys.Count; i++) { var shaderGroupEntry = directLightShaderGroupEntryKeys.Items[i]; int lightCount = shaderGroupEntry.Key.LightCount; ILightShadowMapShaderGroupData shadowGroupData = null; if (shaderGroupEntry.ShadowRenderer != null) { // TODO: Cache ShaderGroupData shadowGroupData = shaderGroupEntry.ShadowRenderer.CreateShaderGroupData(DirectLightGroupsCompositionNames[i], shaderGroupEntry.Key.ShadowType, lightCount); } // TODO: Cache LightShaderGroup var lightShaderGroup = shaderGroupEntry.LightGroupRenderer.CreateLightShaderGroup(DirectLightGroupsCompositionNames[i], lightCount, shadowGroupData); shaderEntry.DirectLightGroups.Add(lightShaderGroup); shaderEntry.DirectLightShaders.Add(lightShaderGroup.ShaderSource); } // All Environment lights for (int i = 0; i < environmentLightShaderGroupEntryKeys.Count; i++) { var shaderGroupEntry = environmentLightShaderGroupEntryKeys.Items[i]; // TODO: Cache LightShaderGroup var lightShaderGroup = shaderGroupEntry.LightGroupRenderer.CreateLightShaderGroup(EnvironmentLightGroupsCompositionNames[i], shaderGroupEntry.Key.LightCount, null); shaderEntry.EnvironmentLights.Add(lightShaderGroup); shaderEntry.EnvironmentLightShaders.Add(lightShaderGroup.ShaderSource); } return(shaderEntry); }
/// <summary> /// Initialize everything Direct3D needs to run /// </summary> protected override void InitD3D() { base.InitD3D(); FillColor = new Color4(0.5f, 0.5f, 0.9f); // Create default scene CreateNewScene(); // Initialize our picker ObjectPicker = new ObjectPicker(); ObjectSpawner = new ObjectSpawner(); Subscribe(ObjectSpawner); InitEffects(); // Use the first valid render effect, if exists if (RenderEffects.Count == 0) { throw new Exception("No render effects could be loaded!"); } ActiveRenderEffect = RenderEffects[1]; }
/// <summary> /// Plane to display scalar/vector field data on. Condition: Fields domain is 2D. /// </summary> /// <param name="origin"></param> /// <param name="xAxis"></param> /// <param name="yAxis"></param> /// <param name="scale">Scaling the field extent.</param> /// <param name="field"></param> public FieldPlane(Plane plane, VectorField fields, RenderEffect effect = RenderEffect.DEFAULT, Colormap map = Colormap.Parula) { #if DEBUG // Assert that the fields are 2 dimensional. foreach (Field field in fields.Scalars) { System.Diagnostics.Debug.Assert(field.Size.Length >= 2); } #endif this._effect = _planeEffect; this._vertexSizeBytes = 32; this._numVertices = 6; this.UsedMap = map; this._width = fields[0].Size[0]; this._height = fields[0].Size[1]; this._invalid = fields.InvalidValue ?? float.MaxValue; this._field = fields; // Setting up the vertex buffer. GenerateGeometry(plane, fields[0].Size.ToInt2(), fields.TimeSlice ?? 0); // Generating Textures from the fields. _fieldTextures = new ShaderResourceView[fields.Scalars.Length]; for (int f = 0; f < _field.NumVectorDimensions; ++f) { Texture2D tex = ColorMapping.GenerateTextureFromField(_device, fields[f]); _fieldTextures[f] = new ShaderResourceView(_device, tex); } this.SetRenderEffect(effect); this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXTURE", 0, Format.R32G32B32A32_Float, 16, 0) }); }
public ModelRenderBatch(IReadOnlyList <AModel> models, IViewPoint viewPoint) { this.Models = models; this.ViewPoint = viewPoint; this.Effect = new RenderEffect(); }
public override void ApplyEffectPermutations(RenderEffect renderEffect) { var lightSkybox = (LightSkybox)light.Type; var skyboxComponent = lightSkybox.SkyboxComponent; var skybox = skyboxComponent.Skybox; var diffuseParameters = skybox.DiffuseLightingParameters; var specularParameters = skybox.SpecularLightingParameters; var lightDiffuseColorShader = diffuseParameters.Get(SkyboxKeys.Shader) ?? EmptyComputeEnvironmentColorSource; var lightSpecularColorShader = specularParameters.Get(SkyboxKeys.Shader) ?? EmptyComputeEnvironmentColorSource; renderEffect.EffectValidator.ValidateParameter(lightDiffuseColorKey, lightDiffuseColorShader); renderEffect.EffectValidator.ValidateParameter(lightSpecularColorKey, lightSpecularColorShader); }
/// <summary> /// Applies effect permutations. /// </summary> /// <param name="renderEffect"></param> public virtual void ApplyEffectPermutations(RenderEffect renderEffect) { }
public override void OnInspectorGUI() { bool bShowAll = false; bool bHideAll = false; EffectController effectCtrl = target as EffectController; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(effectCtrl.m_bLockNums); effectCtrl.m_nNumOfEffects = EditorGUILayout.IntField("Effect Count", effectCtrl.m_nNumOfEffects); EditorGUI.EndDisabledGroup(); effectCtrl.m_bLockNums = EditorGUILayout.Toggle(effectCtrl.m_bLockNums); if (GUILayout.Button("One Click Expansion")) { bShowAll = true; } else { bShowAll = false; } if (GUILayout.Button("One Click Close")) { bHideAll = true; } else { bHideAll = false; } EditorGUILayout.EndHorizontal(); int nCnt = 0; for (; nCnt < effectCtrl.m_nNumOfEffects; nCnt++) { if (nCnt >= effectCtrl.m_kEffectGenList.Count) { effectCtrl.m_kEffectGenList.Add(new EffectData()); } EffectData effectData = effectCtrl.m_kEffectGenList [nCnt]; if (effectData == null) { continue; } if (bShowAll) { effectData.m_bFoldoutOpen = true; } if (bHideAll) { effectData.m_bFoldoutOpen = false; } effectData.m_bFoldoutOpen = EditorGUILayout.Foldout(effectData.m_bFoldoutOpen, ("Effect " + nCnt + " Setting")); if (effectData.m_bFoldoutOpen) { effectData.m_fTimeSec = EditorGUILayout.FloatField("Shot Time", effectData.m_fTimeSec); effectData.m_goEffect = EditorGUILayout.ObjectField("Obj", effectData.m_goEffect, typeof(GameObject), true) as GameObject; EditorGUI.indentLevel++; /// Transform panel. effectData.m_bTransformFoldout = EditorGUILayout.Foldout(effectData.m_bTransformFoldout, "Transform"); if (effectData.m_bTransformFoldout) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); if (GUILayout.Button("P", GUILayout.Width(25), GUILayout.ExpandWidth(false))) { effectData.m_goPos = new Vector3(0, 0, 0); } effectData.m_goPos = EditorGUILayout.Vector3Field("", effectData.m_goPos); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("R", GUILayout.Width(25), GUILayout.ExpandWidth(false))) { effectData.m_goRotation = new Vector3(0, 0, 0); } effectData.m_goRotation = EditorGUILayout.Vector3Field("", effectData.m_goRotation); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("S", GUILayout.Width(25), GUILayout.ExpandWidth(false))) { effectData.m_goScale = new Vector3(0, 0, 0); } effectData.m_goScale = EditorGUILayout.Vector3Field("", effectData.m_goScale); GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { effectCtrl.UpdateEffectTransformByIndex(nCnt); } EditorGUI.indentLevel--; } ParticleSystem particleSystem = effectCtrl.CheckHasParticleSystem(nCnt); RenderEffect renderEffect = effectCtrl.CheckHasRenderEffectScript(nCnt); if (particleSystem == null) { effectData.m_bSortingFoldout = EditorGUILayout.Foldout(effectData.m_bSortingFoldout, "Sorting Layer"); /// Sorting panel. if (effectData.m_bSortingFoldout) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sorting Layer"); effectData.m_SortingLayerID = EditorGUILayout.IntPopup(effectData.m_SortingLayerID, m_LayerName, m_LayerID); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sorting Order"); effectData.m_SortingOrder = EditorGUILayout.IntField(effectData.m_SortingOrder); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { if (renderEffect != null) { renderEffect.m_SortingLayerID = effectData.m_SortingLayerID; renderEffect.m_SortingOrder = effectData.m_SortingOrder; renderEffect.m_EnableSetSortLayer = true; renderEffect.UpdateRenderLayer(); } else { effectCtrl.UPdateRenderLayerByIndex(nCnt); } } EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; } if (nCnt != effectCtrl.m_nNumOfEffects - 1) { EditorGUILayout.LabelField("", GUILayout.Height(2)); GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); EditorGUILayout.LabelField("", GUILayout.Height(2)); } } for (; nCnt < effectCtrl.m_kEffectGenList.Count; nCnt++) { effectCtrl.m_kEffectGenList.RemoveAt(nCnt); } EditorGUILayout.EndVertical(); }
public static unsafe bool UpdateMaterial(RenderSystem renderSystem, RenderDrawContext context, MaterialInfoBase materialInfo, int materialSlotIndex, RenderEffect renderEffect, ParameterCollection materialParameters) { var resourceGroupDescription = renderEffect.Reflection.ResourceGroupDescriptions[materialSlotIndex]; if (resourceGroupDescription.DescriptorSetLayout == null) { return(false); } // Check if this material was encountered for the first time this frame and mark it as used if (Interlocked.Exchange(ref materialInfo.LastFrameUsed, renderSystem.FrameCounter) == renderSystem.FrameCounter) { return(true); } // First time we use the material with a valid effect, let's update layouts if (materialInfo.PerMaterialLayout == null || materialInfo.PerMaterialLayout.Hash != renderEffect.Reflection.ResourceGroupDescriptions[materialSlotIndex].Hash) { materialInfo.PerMaterialLayout = ResourceGroupLayout.New(renderSystem.GraphicsDevice, resourceGroupDescription, renderEffect.Effect.Bytecode); var parameterCollectionLayout = materialInfo.ParameterCollectionLayout = new ParameterCollectionLayout(); parameterCollectionLayout.ProcessResources(resourceGroupDescription.DescriptorSetLayout); materialInfo.ResourceCount = parameterCollectionLayout.ResourceCount; // Process material cbuffer (if any) if (resourceGroupDescription.ConstantBufferReflection != null) { materialInfo.ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection; parameterCollectionLayout.ProcessConstantBuffer(resourceGroupDescription.ConstantBufferReflection); } materialInfo.ParametersChanged = true; } // If the parameters collection instance changed, we need to update it if (materialInfo.ParametersChanged) { materialInfo.ParameterCollection.UpdateLayout(materialInfo.ParameterCollectionLayout); materialInfo.ParameterCollectionCopier = new ParameterCollection.Copier(materialInfo.ParameterCollection, materialParameters); materialInfo.ParametersChanged = false; } // Copy back to ParameterCollection // TODO GRAPHICS REFACTOR directly copy to resource group? materialInfo.ParameterCollectionCopier.Copy(); // Allocate resource groups context.ResourceGroupAllocator.PrepareResourceGroup(materialInfo.PerMaterialLayout, BufferPoolAllocationType.UsedMultipleTime, materialInfo.Resources); // Set resource bindings in PerMaterial resource set for (int resourceSlot = 0; resourceSlot < materialInfo.ResourceCount; ++resourceSlot) { materialInfo.Resources.DescriptorSet.SetValue(resourceSlot, materialInfo.ParameterCollection.ObjectValues[resourceSlot]); } // Process PerMaterial cbuffer if (materialInfo.ConstantBufferReflection != null) { var mappedCB = materialInfo.Resources.ConstantBuffer.Data; fixed(byte *dataValues = materialInfo.ParameterCollection.DataValues) Utilities.CopyMemory(mappedCB, (IntPtr)dataValues, materialInfo.Resources.ConstantBuffer.Size); } return(true); }
public override void OnInspectorGUI() { RenderEffect renderEffect = target as RenderEffect; ParticleSystem particleSystem = renderEffect.gameObject.GetComponent <ParticleSystem>(); EditorGUILayout.BeginVertical(); if (particleSystem == null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Open BillBoardOption"); renderEffect.m_EnableBillBoard = EditorGUILayout.Toggle(renderEffect.m_EnableBillBoard); EditorGUILayout.EndHorizontal(); if (renderEffect.m_EnableBillBoard) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("BillBoard Type"); renderEffect.m_BillBoardType = (RenderBillBoardType)EditorGUILayout.EnumPopup(renderEffect.m_BillBoardType); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; } } if (particleSystem == null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Open Sort Layer Option"); renderEffect.m_EnableSetSortLayer = EditorGUILayout.Toggle(renderEffect.m_EnableSetSortLayer); EditorGUILayout.EndHorizontal(); if (renderEffect.m_EnableSetSortLayer) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sorting Layer"); renderEffect.m_SortingLayerID = EditorGUILayout.IntPopup(renderEffect.m_SortingLayerID, m_LayerName, m_LayerID); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sorting Order"); renderEffect.m_SortingOrder = EditorGUILayout.IntField(renderEffect.m_SortingOrder); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { renderEffect.UpdateRenderLayer(); } EditorGUI.indentLevel--; } } Renderer render = renderEffect.gameObject.GetComponent <Renderer>(); if (render != null) { if (GUILayout.Button("Refresh Material")) { renderEffect.RefreshMaterial(); } EditorGUILayout.LabelField("Materials"); } EditorGUI.indentLevel++; int index = 0; foreach (MaterialEffect matEffect in renderEffect.m_MaterialEffects) { string strIndex = "Element:" + index + " "; if (matEffect.m_EffectMaterial == null) { GUILayout.Button(strIndex + "Material Not Assign"); index++; continue; } else { if (GUILayout.Button(strIndex + matEffect.m_EffectMaterial.name)) { matEffect.m_EditorExtend = !matEffect.m_EditorExtend; } index++; if (matEffect.m_EditorExtend) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Main Texture WrapMode"); matEffect.m_MainTexWrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup(matEffect.m_MainTexWrapMode); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Cutoff Texture WrapMode"); matEffect.m_MaskTexWrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup(matEffect.m_MaskTexWrapMode); EditorGUILayout.EndHorizontal(); } } } EditorGUI.indentLevel--; if (render != null && particleSystem == null) { EditorGUI.indentLevel++; EditorGUILayout.LabelField("Switch Render Type"); if (render.GetType() != typeof(LineRenderer)) { if (GUILayout.Button("Switch To Line Render")) { LineRenderer lineRender = renderEffect.gameObject.AddComponent <LineRenderer>(); renderEffect.m_Render = lineRender; lineRender.sharedMaterials = render.sharedMaterials; UnityEngine.Object.DestroyImmediate(render); MeshFilter meshFilter = renderEffect.gameObject.GetComponent <MeshFilter>(); if (meshFilter != null) { UnityEngine.Object.DestroyImmediate(meshFilter); } Collider meshCollider = renderEffect.gameObject.GetComponent <Collider>(); if (meshCollider != null) { UnityEngine.Object.DestroyImmediate(meshCollider); } EditorGUIUtility.ExitGUI(); } } if (render.GetType() != typeof(MeshRenderer)) { if (GUILayout.Button("Switch To Mesh Render")) { MeshRenderer lineRender = renderEffect.gameObject.AddComponent <MeshRenderer>(); lineRender.sharedMaterials = render.sharedMaterials; renderEffect.m_Render = lineRender; UnityEngine.Object.DestroyImmediate(render); MeshFilter meshFilter = renderEffect.gameObject.GetComponent <MeshFilter>(); if (meshFilter == null) { renderEffect.gameObject.AddComponent <MeshFilter>(); } Collider Collider = renderEffect.gameObject.GetComponent <Collider>(); if (Collider != null) { UnityEngine.Object.DestroyImmediate(Collider); } MeshCollider meshCollider = renderEffect.gameObject.GetComponent <MeshCollider>(); if (meshCollider == null) { renderEffect.gameObject.AddComponent <MeshCollider>(); } EditorGUIUtility.ExitGUI(); } } if (render.GetType() != typeof(TrailRenderer)) { if (GUILayout.Button("Switch To Trail Render")) { TrailRenderer lineRender = renderEffect.gameObject.AddComponent <TrailRenderer>(); lineRender.sharedMaterials = render.sharedMaterials; renderEffect.m_Render = lineRender; UnityEngine.Object.DestroyImmediate(render); MeshFilter meshFilter = renderEffect.gameObject.GetComponent <MeshFilter>(); if (meshFilter != null) { UnityEngine.Object.DestroyImmediate(meshFilter); } Collider Collider = renderEffect.gameObject.GetComponent <Collider>(); if (Collider != null) { UnityEngine.Object.DestroyImmediate(Collider); } EditorGUIUtility.ExitGUI(); } } if (render.GetType() == typeof(TrailRenderer)) { if (GUILayout.Button("Clear Trail")) { TrailRenderer trailRender = render.GetComponent <TrailRenderer> (); trailRender.Clear(); } } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); }
public static unsafe bool UpdateMaterial(RenderSystem renderSystem, RenderDrawContext context, MaterialInfoBase materialInfo, int materialSlotIndex, RenderEffect renderEffect, ParameterCollection materialParameters) { // Check if encountered first time this frame if (materialInfo.LastFrameUsed == renderSystem.FrameCounter) return true; // First time we use the material with a valid effect, let's update layouts if (materialInfo.PerMaterialLayout == null || materialInfo.PerMaterialLayout.Hash != renderEffect.Reflection.ResourceGroupDescriptions[materialSlotIndex].Hash) { var resourceGroupDescription = renderEffect.Reflection.ResourceGroupDescriptions[materialSlotIndex]; if (resourceGroupDescription.DescriptorSetLayout == null) return false; materialInfo.PerMaterialLayout = ResourceGroupLayout.New(renderSystem.GraphicsDevice, resourceGroupDescription, renderEffect.Effect.Bytecode); var parameterCollectionLayout = materialInfo.ParameterCollectionLayout = new ParameterCollectionLayout(); parameterCollectionLayout.ProcessResources(resourceGroupDescription.DescriptorSetLayout); materialInfo.ResourceCount = parameterCollectionLayout.ResourceCount; // Process material cbuffer (if any) if (resourceGroupDescription.ConstantBufferReflection != null) { materialInfo.ConstantBufferReflection = resourceGroupDescription.ConstantBufferReflection; parameterCollectionLayout.ProcessConstantBuffer(resourceGroupDescription.ConstantBufferReflection); } materialInfo.ParametersChanged = true; } // If the parameters collection instance changed, we need to update it if (materialInfo.ParametersChanged) { materialInfo.ParameterCollection.UpdateLayout(materialInfo.ParameterCollectionLayout); materialInfo.ParameterCollectionCopier = new ParameterCollection.Copier(materialInfo.ParameterCollection, materialParameters); materialInfo.ParametersChanged = false; } // Mark this material as used during this frame materialInfo.LastFrameUsed = renderSystem.FrameCounter; // Copy back to ParameterCollection // TODO GRAPHICS REFACTOR directly copy to resource group? materialInfo.ParameterCollectionCopier.Copy(); // Allocate resource groups context.ResourceGroupAllocator.PrepareResourceGroup(materialInfo.PerMaterialLayout, BufferPoolAllocationType.UsedMultipleTime, materialInfo.Resources); // Set resource bindings in PerMaterial resource set for (int resourceSlot = 0; resourceSlot < materialInfo.ResourceCount; ++resourceSlot) { materialInfo.Resources.DescriptorSet.SetValue(resourceSlot, materialInfo.ParameterCollection.ObjectValues[resourceSlot]); } // Process PerMaterial cbuffer if (materialInfo.ConstantBufferReflection != null) { var mappedCB = materialInfo.Resources.ConstantBuffer.Data; fixed (byte* dataValues = materialInfo.ParameterCollection.DataValues) Utilities.CopyMemory(mappedCB, (IntPtr)dataValues, materialInfo.Resources.ConstantBuffer.Size); } return true; }
public void SetRenderEffect(RenderEffect effect) { // Ad length texture. if(effect == RenderEffect.LIC_LENGTH && Effect != RenderEffect.LIC_LENGTH && _field != null) { VectorField length = new VectorField(_field, FieldAnalysis.VFLength, 1, false); this.AddScalar(length[0] as ScalarField); } // Remove length texture? else if (effect != RenderEffect.LIC_LENGTH && Effect == RenderEffect.LIC_LENGTH && _field != null) { ShaderResourceView[] cpy = _fieldTextures; _fieldTextures = new ShaderResourceView[cpy.Length - 1]; Array.Copy(cpy, _fieldTextures, _fieldTextures.Length); } switch (effect) { case RenderEffect.LIC: case RenderEffect.LIC_LENGTH: //Debug.Assert(_fields.Length >= 2); this._technique = _planeEffect.GetTechniqueByName("RenderLIC" + _fieldTextures.Length); break; case RenderEffect.CHECKERBOARD: this._technique = _planeEffect.GetTechniqueByName("RenderChecker"); break; case RenderEffect.CHECKERBOARD_COLORMAP: this._technique = _planeEffect.GetTechniqueByName("RenderCheckerTex" + _fieldTextures.Length); break; case RenderEffect.OVERLAY: this._technique = _planeEffect.GetTechniqueByName("Overlay" + _fieldTextures.Length); break; case RenderEffect.LAPLACE: this._technique = _planeEffect.GetTechniqueByName("Laplace" + _fieldTextures.Length); break; case RenderEffect.GRADIENT: this._technique = _planeEffect.GetTechniqueByName("Gradient" + _fieldTextures.Length); break; case RenderEffect.COLORMAP: default: this._technique = _planeEffect.GetTechniqueByName("RenderTex" + _fieldTextures.Length); break; } Effect = effect; }
protected Graphics.Effect ComputeMeshFallbackEffect(RenderObject renderObject, [NotNull] RenderEffect renderEffect, RenderEffectState renderEffectState) { try { var renderMesh = (RenderMesh)renderObject; bool hasDiffuseMap = renderMesh.MaterialPass.Parameters.ContainsKey(MaterialKeys.DiffuseMap); var fallbackMaterial = hasDiffuseMap ? fallbackTextureMaterial : fallbackColorMaterial; // High priority var compilerParameters = new CompilerParameters { EffectParameters = { TaskPriority = -1 } }; // Support skinning if (renderMesh.Mesh.Skinning != null && renderMesh.Mesh.Skinning.Bones.Length <= 56) { compilerParameters.Set(MaterialKeys.HasSkinningPosition, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningPosition)); compilerParameters.Set(MaterialKeys.HasSkinningNormal, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningNormal)); compilerParameters.Set(MaterialKeys.HasSkinningTangent, renderMesh.Mesh.Parameters.Get(MaterialKeys.HasSkinningTangent)); compilerParameters.Set(MaterialKeys.SkinningMaxBones, 56); } // Set material permutations compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageSurfaceShaders)); compilerParameters.Set(MaterialKeys.PixelStageStreamInitializer, fallbackMaterial.Passes[0].Parameters.Get(MaterialKeys.PixelStageStreamInitializer)); // Set lighting permutations (use custom white light, since this effect will not be processed by the lighting render feature) compilerParameters.Set(LightingKeys.EnvironmentLights, new ShaderSourceCollection { new ShaderClassSource("LightConstantWhite") }); // Initialize parameters with material ones (need a CopyTo?) renderEffect.FallbackParameters = new ParameterCollection(renderMesh.MaterialPass.Parameters); // Don't show selection wireframe/highlights as compiling var ignoreState = renderEffect.EffectSelector.EffectName.EndsWith(".Wireframe") || renderEffect.EffectSelector.EffectName.EndsWith(".Highlight") || renderEffect.EffectSelector.EffectName.EndsWith(".Picking"); // Also set a value so that we know something is loading (green glowing FX) or error (red glowing FX) if (!ignoreState) { if (renderEffectState == RenderEffectState.Compiling) { compilerParameters.Set(SceneEditorParameters.IsEffectCompiling, true); } else if (renderEffectState == RenderEffectState.Error) { compilerParameters.Set(SceneEditorParameters.IsEffectError, true); } } if (renderEffectState == RenderEffectState.Error) { // Retry every few seconds renderEffect.RetryTime = DateTime.UtcNow + TimeSpan.FromSeconds(5); } return(EffectSystem.LoadEffect(renderEffect.EffectSelector.EffectName, compilerParameters).WaitForResult()); } catch { // TODO: Log or rethrow? renderEffect.State = RenderEffectState.Error; return(null); } }