public void GetHighlightLod(int i, out MyLod lod, out MyInstanceLodState stateId, out float stateData) { int lodNum; m_lodStrategy.GetLod(MyPassIdResolver.DefaultGBufferPassId, i, out lodNum, out stateId, out stateData); lod = Models.HighlightModel.GetLod(lodNum); }
public void Set(int lodsCount, int lodNum, MyInstanceLodState state, float stateData) { LodsCount = lodsCount; LodNum = lodNum; State = state; StateData = stateData; }
public static void UpdateSingleLod(List <MyLodStrategyCachedResult> results, int passId, int currentLod, MyInstanceLodState currentState, float currentStateData) { MyLodStrategyCachedResult result = new MyLodStrategyCachedResult(); result.Set(1, currentLod, currentState, currentStateData); results[passId * 2] = result; }
public int GetDirectOffset(int lodId, MyInstanceLodState state) { int stateId = (int)state; MyRenderProxy.Assert(lodId <= (int)m_maxLodId); MyRenderProxy.Assert(stateId < (int)MyInstanceLodState.StatesCount); int stride = m_maxLodId + 1; return(stride * stateId + lodId); }
public static void UpdateTwoLods(List <MyLodStrategyCachedResult> results, int passId, int currentLod, MyInstanceLodState currentState, float currentStateData, int theOtherLod, MyInstanceLodState theOtherState, float theOtherStateData) { MyLodStrategyCachedResult result = new MyLodStrategyCachedResult(); result.Set(2, currentLod, currentState, currentStateData); results[passId * 2] = result; result.Set(2, theOtherLod, theOtherState, theOtherStateData); results[passId * 2 + 1] = result; }
public static void GetLod(List <MyLodStrategyCachedResult> results, int passId, int i, out int lod, out MyInstanceLodState state, out float stateData) { MyRenderProxy.Assert(passId < MyPassIdResolver.AllPassesCount); MyRenderProxy.Assert(i < 2); // more lods than 2 are not supported MyLodStrategyCachedResult result = results[passId * 2 + i]; lod = result.LodNum; state = result.State; stateData = result.StateData; }
public void SetExplicitLodState(MyLodStrategyInfo strategyInfo, MyInstanceLodState state, float stateData) { m_explicitState = state; m_explicitStateData = stateData; int maxLod = 0; if (!strategyInfo.IsEmpty) { maxLod = strategyInfo.GetLodsCount() - 1; } UpdateCachedResults(maxLod, m_allPassIds); }
public void Init() { m_currentLod = 0; m_transitionLod = -1; m_transition = 0; m_transitionStartedAtDistance = 0; m_explicitState = MyInstanceLodState.Solid; m_explicitStateData = 0; m_updatedAtFrameId = 0; m_cachedResultsPool.AllocateOrCreate(out m_cachedResults); MyLodStrategyCachedResultsUtils.InitList(m_cachedResults); }
public void GetLod(int passId, int i, out MyLod lod, out MyInstanceLodState stateId, out float stateData) { int lodNum; m_lodStrategy.GetLod(passId, i, out lodNum, out stateId, out stateData); if (passId == 0) { lod = Models.StandardModel.GetLod(lodNum); } else { lod = Models.DepthModel.GetLod(lodNum); } }
static void DrawHighlightedPart(MyRenderContext RC, MyPart part, MyInstanceLodState state) { // settings per part (using MyPart.cs): MyShaderBundle shaderBundle = part.GetShaderBundle(state); RC.SetInputLayout(shaderBundle.InputLayout); RC.VertexShader.Set(shaderBundle.VertexShader); RC.PixelShader.Set(shaderBundle.PixelShader); // (using MyHighlightPass.cs): RC.SetRasterizerState(null); RC.DrawIndexed(part.IndicesCount, part.StartIndex, part.StartVertex); }
void AddMacrosState(MyInstanceLodState state, ref List <ShaderMacro> macros) { if (state == MyInstanceLodState.Solid) { // nothing } else if (state == MyInstanceLodState.Transition) { macros.Add(new ShaderMacro("DITHERED", null)); macros.Add(new ShaderMacro("DITHERED_LOD", null)); } else if (state == MyInstanceLodState.Hologram) { // this is not good, but nothing... } else if (state == MyInstanceLodState.Dithered) { macros.Add(new ShaderMacro("DITHERED", null)); } }
public MyShaderBundle GetShaderBundle(MyRenderPassType pass, MyMeshDrawTechnique technique, MyInstanceLodState state, bool isCm, bool isNg, bool isExt) { // Modify input: switch (technique) { case MyMeshDrawTechnique.DECAL: case MyMeshDrawTechnique.DECAL_CUTOUT: case MyMeshDrawTechnique.DECAL_NOPREMULT: break; default: isCm = true; isNg = true; isExt = true; break; } MyShaderBundleKey key = new MyShaderBundleKey { Pass = pass, Technique = technique, IsCm = isCm, IsNg = isNg, IsExt = isExt, State = state, }; if (m_cache.ContainsKey(key)) { return(m_cache[key]); } MyVertexInputComponent[] viComps = GetVertexInputComponents(pass); VertexLayoutId vl = MyVertexLayouts.GetLayout(viComps); string vsFilepath = GetShaderDirpath(technique) + "Vertex.hlsl"; string psFilepath = GetShaderDirpath(technique) + "Pixel.hlsl"; List <ShaderMacro> macros = new List <ShaderMacro>(); AddMacrosForRenderingPass(pass, ref macros); AddMacrosForTechnique(technique, isCm, isNg, isExt, ref macros); AddMacrosVertexInputComponents(viComps, ref macros); AddMacrosState(state, ref macros); VertexShaderId vs = MyShaders.CreateVs(vsFilepath, macros.ToArray()); ((VertexShader)vs).DebugName = GetVsDebugName(pass, technique, macros); PixelShaderId ps = MyShaders.CreatePs(psFilepath, macros.ToArray()); ((PixelShader)ps).DebugName = GetPsDebugName(pass, technique, macros);; InputLayoutId il = MyShaders.CreateIL(vs.BytecodeId, vl); MyShaderBundle shaderBundle = new MyShaderBundle(ps, vs, il); m_cache.Add(key, shaderBundle); return(shaderBundle); }
void IDrawableGroupStrategy.Fill(int bufferOffset, MyInstanceComponent instance, MyLod lod, int multiTransformI, int instanceMaterialOffsetInData, MyInstanceLodState state, float stateData) { HalfVector4 packedColorMultEmissivity = MyInstanceMaterial.Default.PackedColorMultEmissivity; if (instanceMaterialOffsetInData != -1) // if instance material is defined { MyInstanceMaterial instanceMaterial = instance.GetInstanceMaterial(instanceMaterialOffsetInData); packedColorMultEmissivity = instanceMaterial.PackedColorMultEmissivity; } else { packedColorMultEmissivity = instance.GlobalColorMultEmissivity; } HalfVector4 packedKeyColorDithering = instance.KeyColor.ToHalfVector4(); HalfVector4 dithering = new HalfVector4(); dithering.PackedValue = (ulong)HalfUtils.Pack(stateData); packedKeyColorDithering.PackedValue = packedKeyColorDithering.PackedValue | dithering.PackedValue << 48; MyVbConstantElement element = new MyVbConstantElement { //WorldMatrixRow0 = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14), //WorldMatrixRow1 = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24), //WorldMatrixRow2 = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34), KeyColorDithering = packedKeyColorDithering, ColorMultEmissivity = packedColorMultEmissivity, }; // much faster approach than naive: instance.GetMatrixCols(multiTransformI, out element.WorldMatrixRow0, out element.WorldMatrixRow1, out element.WorldMatrixRow2); m_vbData[bufferOffset] = element; m_validElements++; }
void IDrawableGroupStrategy.Fill(int bufferOffset, MyInstanceComponent instance, MyLod lod, int multiTransformI, int instanceMaterialOffsetInData, MyInstanceLodState state, float stateData) { MyVbConstantElement element = new MyVbConstantElement { //WorldMatrixRow0 = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14), //WorldMatrixRow1 = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24), //WorldMatrixRow2 = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34), }; //Much faster approach than naive: instance.GetMatrixCols(multiTransformI, out element.WorldMatrixRow0, out element.WorldMatrixRow1, out element.WorldMatrixRow2); m_vbData[bufferOffset] = element; m_validElements++; }
public void Add(int lodId, MyInstanceLodState state, int value) { int offset = GetDirectOffset(lodId, state); m_instancesCounters[offset] += value; }
public void GetDetailsFromDirectOffset(int directOffset, out int lodId, out MyInstanceLodState state) { MyRenderProxy.Assert(directOffset < m_instancesCountersCount); lodId = directOffset % (m_maxLodId + 1); state = (MyInstanceLodState)(directOffset / (m_maxLodId + 1)); }
public int At(int lodId, MyInstanceLodState state) { int offset = GetDirectOffset(lodId, state); return(m_instancesCounters[offset]); }
public bool IsEmpty(int lodId, MyInstanceLodState state) { int offset = GetDirectOffset(lodId, state); return(m_instancesCounters[offset] == 0); }
public void GetLod(int passId, int i, out int lodNum, out MyInstanceLodState stateId, out float stateData) { MyLodStrategyCachedResultsUtils.GetLod(m_cachedResults, passId, i, out lodNum, out stateId, out stateData); }
public MyShaderBundle GetShaderBundle(MyInstanceLodState state) { MyRenderProxy.Assert((int)state < m_shaderBundles.Length, "Shader bundle is not correctly initialised"); MyRenderProxy.Assert(m_shaderBundles[(int)state] != null, "Shader bundle is not defined for the state"); return(m_shaderBundles[(int)state]); }
static void DrawInstanceComponent(MyInstanceComponent instanceComponent, List <MyHighlightDesc> highlightDescs) { MyRenderContext RC = MyRender11.RC; // common settings (combination of MyHighlightPass.cs and MyRenderingPass.cs): MyMapping mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); Matrix matrix = MyRender11.Environment.Matrices.ViewProjectionAt0; matrix = Matrix.Transpose(matrix); mapping.WriteAndPosition(ref matrix); mapping.Unmap(); RC.VertexShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.VertexShader.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); RC.PixelShader.SetSrv(MyCommon.DITHER_8X8_SLOT, MyGeneratedTextureManager.Dithering8x8Tex); //RC.AllShaderStages.SetConstantBuffer(MyCommon.ALPHAMASK_VIEWS_SLOT, MyCommon.AlphamaskViewsConstants); // not used! Maybe impostors? RC.SetDepthStencilState(MyDepthStencilStateManager.WriteHighlightStencil, MyHighlight.HIGHLIGHT_STENCIL_MASK); RC.SetBlendState(null); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetScreenViewport(); RC.PixelShader.SetConstantBuffer(4, MyCommon.HighlightConstants); MyLod lod = instanceComponent.GetHighlightLod(); MyInstanceLodState stateId = MyInstanceLodState.Solid; float stateData = 0; RC.SetIndexBuffer(lod.IB); RC.SetVertexBuffer(0, lod.VB0); IConstantBuffer objectCB = GetObjectCB(RC, instanceComponent, stateData); RC.VertexShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, objectCB); RC.PixelShader.SetConstantBuffer(MyCommon.OBJECT_SLOT, objectCB); foreach (MyHighlightDesc desc in highlightDescs) { MyHighlightDesc descRef = desc; WriteHighlightConstants(ref descRef); if (string.IsNullOrEmpty(desc.SectionName)) { foreach (var part in lod.Parts) { DrawHighlightedPart(RC, part, stateId); } } else { if (lod.HighlightSections != null && lod.HighlightSections.ContainsKey(desc.SectionName)) { foreach (var part in lod.HighlightSections[desc.SectionName].Parts) { DrawHighlightedPart(RC, part, stateId); } } } } }