Skip to content

Commit 1b5aeae

Browse files
committed
RibbonMeshCreateParams.
1 parent ac46cd7 commit 1b5aeae

File tree

6 files changed

+198
-68
lines changed

6 files changed

+198
-68
lines changed

OpenMLTD.MilliSim.Graphics/res/fx/simple_texture.fx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ SamplerState samLinear {
2929
AddressV = WRAP;
3030
};
3131

32+
// https://blogs.msdn.microsoft.com/shawnhar/2009/02/18/depth-sorting-alpha-blended-objects/
33+
BlendState PrepassBlend {
34+
BlendEnable[0] = false;
35+
SrcBlend = SRC_ALPHA;
36+
DestBlend = INV_SRC_ALPHA;
37+
BlendOp = ADD;
38+
SrcBlendAlpha = ONE;
39+
DestBlendAlpha = ZERO;
40+
BlendOpAlpha = ADD;
41+
RenderTargetWriteMask[0] = 0x00;
42+
};
43+
44+
DepthStencilState PrepassDepthStencil {
45+
DepthEnable = true;
46+
DepthFunc = LESS_EQUAL;
47+
DepthWriteMask = ALL;
48+
};
49+
3250
// Using standard alpha blend.
3351
// Equivalent to FrequentlyUsedStates.AlphaBlend.
3452
BlendState AlphaBlend {
@@ -50,18 +68,20 @@ BlendState AlphaBlend {
5068
};
5169

5270
// Enable depth copmarison, but the comparison always passes.
53-
// Equivalent to FrequentlyUsedStates.NoDepth.
54-
DepthStencilState NoDepth {
71+
DepthStencilState NaiveDepth {
5572
DepthEnable = true;
5673
DepthFunc = ALWAYS;
57-
DepthWriteMask = ZERO;
74+
//DepthFunc = LESS_EQUAL;
75+
DepthWriteMask = ALL;
76+
//DepthWriteMask = ZERO;
5877
};
5978

6079
// No culling.
6180
// Equivalent to FrequentlyUsedStates.NoCull.
6281
RasterizerState NoCull {
6382
FillMode = SOLID;
64-
CullMode = NONE;
83+
//CullMode = NONE;
84+
CullMode = BACK;
6585
FrontCounterClockwise = false;
6686
DepthClipEnable = true;
6787
};
@@ -120,12 +140,20 @@ float4 PS(PS_IN pin, uniform bool gUseTexure, uniform bool gAlphaClip) : SV_Targ
120140
}
121141

122142
technique11 SimpleTexture {
123-
pass P0 {
143+
//pass P0 {
144+
// SetGeometryShader(NULL);
145+
// SetVertexShader(CompileShader(vs_4_0, VS()));
146+
// SetPixelShader(CompileShader(ps_4_0, PS(true, false)));
147+
// SetBlendState(PrepassBlend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xffffffff);
148+
// SetDepthStencilState(PrepassDepthStencil, 0);
149+
// SetRasterizerState(NoCull);
150+
//}
151+
pass P1 {
124152
SetGeometryShader(NULL);
125153
SetVertexShader(CompileShader(vs_4_0_level_9_1, VS()));
126154
SetPixelShader(CompileShader(ps_4_0_level_9_1, PS(true, false)));
127155
SetBlendState(AlphaBlend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xffffffff);
128-
SetDepthStencilState(NoDepth, 0);
156+
SetDepthStencilState(NaiveDepth, 0);
129157
SetRasterizerState(NoCull);
130158
}
131159
}

OpenMLTD.MilliSim.Theater/Elements/Visual/Gaming/RibbonsLayer.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public RibbonsLayer(GameBase game)
2828
: base(game) {
2929
}
3030

31-
internal static readonly float LayerDepth = 0.1f;
32-
3331
protected override void OnUpdate(GameTime gameTime) {
3432
base.OnUpdate(gameTime);
3533
_camera.UpdateViewMatrix();
@@ -113,6 +111,7 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
113111
OnStageStatus thisStatus, nextStatus;
114112
RuntimeNote nextNote;
115113
NoteMetrics visualNoteMetrics;
114+
RibbonMeshCreateParams rmcp;
116115

117116
if (note.HasNextHold()) {
118117
thisStatus = NoteAnimationHelper.GetOnStageStatusOf(note, now, animationMetrics);
@@ -137,7 +136,8 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
137136
var ribbonParams = traceCalculator.GetHoldRibbonParameters(note, nextNote, now, visualNoteMetrics, animationMetrics);
138137

139138
if (ribbonParams.Visible) {
140-
using (var mesh = new RibbonMesh(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextHold) }, visualNoteMetrics, animationMetrics)) {
139+
rmcp = new RibbonMeshCreateParams(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextHold) }, visualNoteMetrics, animationMetrics);
140+
using (var mesh = new RibbonMesh(rmcp)) {
141141
context.DrawRibbon(mesh, _textureEffect, _ribbonMaterial, _camera.ViewProjectionMatrix, _ribbonTextureSrv);
142142
}
143143

@@ -194,7 +194,8 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
194194
}
195195

196196
if (ribbonParamArray.Any(rp => rp.Visible)) {
197-
using (var mesh = new RibbonMesh(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, ribbonParamArray, traceCalculator, now, flickNotePairs, visualNoteMetrics, animationMetrics)) {
197+
rmcp = new RibbonMeshCreateParams(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, ribbonParamArray, traceCalculator, now, flickNotePairs, visualNoteMetrics, animationMetrics);
198+
using (var mesh = new RibbonMesh(rmcp)) {
198199
context.DrawRibbon(mesh, _textureEffect, _ribbonMaterial, _camera.ViewProjectionMatrix, _ribbonTextureSrv);
199200
}
200201

@@ -204,7 +205,8 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
204205
var ribbonParams = traceCalculator.GetSlideRibbonParameters(note, nextNote, now, visualNoteMetrics, animationMetrics);
205206

206207
if (ribbonParams.Visible) {
207-
using (var mesh = new RibbonMesh(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextSlide) }, visualNoteMetrics, animationMetrics)) {
208+
rmcp = new RibbonMeshCreateParams(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextSlide) }, visualNoteMetrics, animationMetrics);
209+
using (var mesh = new RibbonMesh(rmcp)) {
208210
context.DrawRibbon(mesh, _textureEffect, _ribbonMaterial, _camera.ViewProjectionMatrix, _ribbonTextureSrv);
209211
}
210212

@@ -262,7 +264,8 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
262264
}
263265

264266
if (ribbonParamArray.Any(rp => rp.Visible)) {
265-
using (var mesh = new RibbonMesh(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, ribbonParamArray, traceCalculator, now, slideNotePairs, visualNoteMetrics, animationMetrics)) {
267+
rmcp = new RibbonMeshCreateParams(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, ribbonParamArray, traceCalculator, now, slideNotePairs, visualNoteMetrics, animationMetrics);
268+
using (var mesh = new RibbonMesh(rmcp)) {
266269
context.DrawRibbon(mesh, _textureEffect, _ribbonMaterial, _camera.ViewProjectionMatrix, _ribbonTextureSrv);
267270
}
268271

@@ -272,7 +275,8 @@ protected override void OnDraw(GameTime gameTime, RenderContext context) {
272275
var ribbonParams = traceCalculator.GetSlideRibbonParameters(note, nextNote, now, visualNoteMetrics, animationMetrics);
273276

274277
if (ribbonParams.Visible) {
275-
using (var mesh = new RibbonMesh(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextSlide) }, visualNoteMetrics, animationMetrics)) {
278+
rmcp = new RibbonMeshCreateParams(context.Direct3DDevice, SliceCount, topYRatio, bottomYRatio, z, LayerDepth, new[] { ribbonParams }, traceCalculator, now, new[] { (note, note.NextSlide) }, visualNoteMetrics, animationMetrics);
279+
using (var mesh = new RibbonMesh(rmcp)) {
276280
context.DrawRibbon(mesh, _textureEffect, _ribbonMaterial, _camera.ViewProjectionMatrix, _ribbonTextureSrv);
277281
}
278282

@@ -295,7 +299,7 @@ protected override void OnGotContext(RenderContext context) {
295299
throw new InvalidOperationException();
296300
}
297301

298-
_camera = new OrthoCamera(context.ClientSize.Width, context.ClientSize.Height, -1, 1000);
302+
_camera = new OrthoCamera(context.ClientSize.Width, context.ClientSize.Height, 0.1f, ViewFrustrumDepth);
299303
var centerPoint = new PointF(context.ClientSize.Width / 2f, context.ClientSize.Height / 2f);
300304
_camera.Position = new Vector3(centerPoint.X, centerPoint.Y, 1);
301305
_camera.LookAt(new Vector3(centerPoint.X, centerPoint.Y, 0), -Vector3.UnitY);
@@ -339,6 +343,8 @@ protected override void OnInitialize() {
339343
}
340344

341345
private static readonly int SliceCount = 48;
346+
private static readonly float LayerDepth = 1f;
347+
private static readonly float ViewFrustrumDepth = 100f;
342348

343349
private OrthoCamera _camera;
344350

0 commit comments

Comments
 (0)