Skip to content

Commit

Permalink
Confetti
Browse files Browse the repository at this point in the history
  • Loading branch information
gleblebedev committed Dec 5, 2023
1 parent 4f53423 commit 55d51c9
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 12 deletions.
24 changes: 24 additions & 0 deletions Content/Common/Data/Materials/Confetti.material
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<material>
<technique name="Techniques/Confetti.xml" quality="0" loddistance="0.000000" />
<parameter name="VOffset" value="0 1 0 0" />
<parameter name="AlphaCutoff" value="0.500000" />
<parameter name="UOffset" value="1 0 0 0" />
<parameter name="MatSpecColor" value="0 0 0 1" />
<parameter name="NormalScale" value="1.000000" />
<parameter name="DielectricReflectance" value="0.500000" />
<parameter name="MatEnvMapColor" value="1 1 1" />
<parameter name="MatEmissiveColor" value="0 0 0" />
<parameter name="MatDiffColor" value="1 1 1 1" />
<parameter name="AnimationPhase" value="0.000000" />
<parameter name="Roughness" value="1.000000" />
<parameter name="Metallic" value="1.000000" />
<cull value="none" />
<shadowcull value="ccw" />
<fill value="solid" />
<depthbias constant="0.000000" slopescaled="0.000000" normaloffset="0.000000" />
<alphatocoverage enable="false" />
<lineantialias enable="false" />
<renderorder value="128" />
<occlusion enable="true" />
</material>
Binary file added Content/Common/Data/Models/Particles.mdl
Binary file not shown.
100 changes: 100 additions & 0 deletions Content/Common/Data/Objects/Confetti.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"components": [
{
"_typeName": "Octree"
}
],
"nodes": [
{
"components": [
{
"_typeName": "StaticModel",
"attributes": [
{
"name": "Model",
"type": "ResourceRef",
"value": "Model;Models/Particles.mdl"
},
{
"name": "Material",
"type": "ResourceRefList",
"value": "Material;Materials/Confetti.material"
},
{
"name": "Cast Shadows",
"type": "Bool",
"value": true
}
]
}
]
},
{
"attributes": [
{
"name": "Name",
"type": "String",
"value": "Default Skybox"
}
],
"components": [
{
"_typeName": "Skybox",
"attributes": [
{
"name": "Model",
"type": "ResourceRef",
"value": "Model;Models/Box.mdl"
},
{
"name": "Material",
"type": "ResourceRefList",
"value": "Material;Materials/DefaultSkybox.xml"
}
]
}
]
},
{
"attributes": [
{
"name": "Name",
"type": "String",
"value": "Default Zone"
}
],
"components": [
{
"_typeName": "Zone",
"attributes": [
{
"name": "Bounding Box Min",
"type": "Vector3",
"value": "-1000 -1000 -1000"
},
{
"name": "Bounding Box Max",
"type": "Vector3",
"value": "1000 1000 1000"
},
{
"name": "Ambient Color",
"type": "Color",
"value": "0 0 0 1"
},
{
"name": "Background Brightness",
"type": "Float",
"value": 1.0
},
{
"name": "Zone Texture",
"type": "ResourceRef",
"value": "TextureCube;Textures/DefaultSkybox.xml"
}
]
}
]
}
]
}
28 changes: 25 additions & 3 deletions Content/Common/Data/Scenes/Scene.scene
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
<resource _id="1">
<attributes>
<attribute name="Next Node ID" type="Int" value="21" />
<attribute name="Next Component ID" type="Int" value="42" />
<attribute name="Elapsed Time" type="Float" value="242.906815" />
<attribute name="Next Node ID" type="Int" value="29" />
<attribute name="Next Component ID" type="Int" value="52" />
</attributes>
<components>
<component _id="1" _typeName="Octree" />
Expand Down Expand Up @@ -56,7 +57,7 @@
<attributes>
<attribute name="Light Type" type="String" value="Directional" />
<attribute name="Brightness Multiplier" type="Float" value="0.500000" />
<attribute name="Cast Shadows" type="Bool" value="true" />
<attribute name="CSM Splits" type="Vector4" value="2 10 0 0" />
</attributes>
</component>
</components>
Expand Down Expand Up @@ -105,6 +106,27 @@
</component>
</components>
</node>
<node _id="28">
<attributes>
<attribute name="Is Enabled" type="Bool" value="false" />
<attribute name="Name" type="String" value="Confetti" />
<attribute name="Tags" type="StringVector">
<value>
<element value="Confetti" />
</value>
</attribute>
<attribute name="Position" type="Vector3" value="0 0 1" />
<attribute name="Rotation" type="Quaternion" value="0.707107 0.707107 0 0" />
<attribute name="Scale" type="Vector3" value="6 6 6" />
</attributes>
<components>
<component _id="51" _typeName="PrefabReference">
<attributes>
<attribute name="Prefab" type="ResourceRef" value="PrefabResource;Objects/Confetti.prefab" />
</attributes>
</component>
</components>
</node>
</nodes>
<auxiliary />
</resource>
110 changes: 110 additions & 0 deletions Content/Common/Data/Shaders/GLSL/v2/M_Confetti.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#define URHO3D_PIXEL_NEED_TEXCOORD

#ifndef URHO3D_VERTEX_HAS_TEXCOORD0
#define URHO3D_VERTEX_HAS_TEXCOORD0
#endif

#ifndef URHO3D_VERTEX_HAS_COLOR
#define URHO3D_VERTEX_HAS_COLOR
#endif


#define URHO3D_MATERIAL_ALBEDO URHO3D_TEXTURE_ALBEDO
#define URHO3D_MATERIAL_NORMAL URHO3D_TEXTURE_NORMAL
#define URHO3D_MATERIAL_PROPERTIES URHO3D_TEXTURE_PROPERTIES
#define URHO3D_MATERIAL_EMISSION URHO3D_TEXTURE_EMISSION
#define URHO3D_CUSTOM_MATERIAL_UNIFORMS

#include "_Config.glsl"
#include "_Uniforms.glsl"
#include "_DefaultSamplers.glsl"

UNIFORM_BUFFER_BEGIN(4, Material)
DEFAULT_MATERIAL_UNIFORMS
UNIFORM(half cAnimationPhase)
UNIFORM_BUFFER_END(4, Material)

#include "_Material.glsl"

#ifdef URHO3D_VERTEX_SHADER

mat3 FromAngleAxis(float angle, vec3 normAxis)
{
float sinAngle = sin(angle);
float cosAngle = cos(angle);
float _cosAngle = 1.0 - cosAngle;

return mat3(
cosAngle + normAxis.x * normAxis.x * _cosAngle,
normAxis.y * normAxis.x * _cosAngle + normAxis.z * sinAngle,
normAxis.z * normAxis.x * _cosAngle - normAxis.y * sinAngle,

normAxis.x * normAxis.y * _cosAngle - normAxis.z * sinAngle,
cosAngle + normAxis.y * normAxis.y * _cosAngle,
normAxis.z * normAxis.y * _cosAngle + normAxis.x * sinAngle,

normAxis.x * normAxis.z * _cosAngle + normAxis.y * sinAngle,
normAxis.y * normAxis.z * _cosAngle - normAxis.x * sinAngle,
cosAngle + normAxis.z * normAxis.z * _cosAngle);
}

void main()
{
mat4 modelMatrix = GetModelMatrix();

float t = cAnimationPhase;
float _t = 1.0 - t;
vec3 bernsteinCoefficients = vec3(_t*_t, 2.0*t*_t, t*t);

vec3 offset = FromAngleAxis(iColor.w + t * 10.0, iNormal) * vec3(iTexCoord.x-0.5, 0.0, -iTexCoord.y+0.5);

float up = dot(bernsteinCoefficients, vec3(0.0, 0.0, -0.5));
float size = dot(bernsteinCoefficients, vec3(0.0, 0.1, 0.0));
float dist = dot(bernsteinCoefficients, vec3(0.0, 1.0, 1.0));

VertexTransform vertexTransform;
vertexTransform.position = vec4(iPos.xyz*dist + offset.xyz*size + vec3(0.0, up, 0.0), 1.0) * modelMatrix;

#ifdef URHO3D_VERTEX_NEED_NORMAL
mediump mat3 normalMatrix = GetNormalMatrix(modelMatrix);
vertexTransform.normal = normalize(iNormal * normalMatrix);

ApplyShadowNormalOffset(result.position, result.normal);

#ifdef URHO3D_VERTEX_NEED_TANGENT
vertexTransform.tangent = normalize(iTangent.xyz * normalMatrix);
vertexTransform.bitangent = cross(result.tangent, result.normal) * iTangent.w;
#endif
#endif

Vertex_SetAll(vertexTransform, cNormalScale, cUOffset, cVOffset, cLMOffset);
}
#endif

#ifdef URHO3D_PIXEL_SHADER
void main()
{
#ifdef URHO3D_DEPTH_ONLY_PASS
Pixel_DepthOnly(sAlbedo, vTexCoord);
#else
SurfaceData surfaceData;

Surface_SetCommon(surfaceData);
Surface_SetAmbient(surfaceData, sEmission, vTexCoord2);
Surface_SetNormal(surfaceData, vNormal, sNormal, vTexCoord, vTangent, vBitangentXY);
Surface_SetPhysicalProperties(surfaceData, cRoughness, cMetallic, cDielectricReflectance, sProperties, vTexCoord);
Surface_SetLegacyProperties(surfaceData, cMatSpecColor.a, sEmission, vTexCoord);
Surface_SetCubeReflection(surfaceData, sReflection0, sReflection1, vReflectionVec, vWorldPos);
Surface_SetPlanarReflection(surfaceData, sReflection0, cReflectionPlaneX, cReflectionPlaneY);
Surface_SetBackground(surfaceData, sEmission, sDepthBuffer);
Surface_SetBaseAlbedo(surfaceData, cMatDiffColor, cAlphaCutoff, vColor, sAlbedo, vTexCoord, URHO3D_MATERIAL_ALBEDO);
Surface_SetBaseSpecular(surfaceData, cMatSpecColor, cMatEnvMapColor, sProperties, vTexCoord);
Surface_SetAlbedoSpecular(surfaceData);
Surface_SetEmission(surfaceData, cMatEmissiveColor, sEmission, vTexCoord, URHO3D_MATERIAL_EMISSION);
Surface_ApplySoftFadeOut(surfaceData, vWorldDepth, cFadeOffsetScale);

half3 surfaceColor = GetSurfaceColor(surfaceData);
gl_FragColor = GetFragmentColorAlpha(surfaceColor, surfaceData.albedo.a, surfaceData.fogFactor);
#endif
}
#endif
6 changes: 6 additions & 0 deletions Content/Common/Data/Techniques/Confetti.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<technique vs="M_Confetti" ps="M_Confetti">
<pass name="base" />
<pass name="deferred" />
<pass name="depth" vs="M_Confetti" ps="M_Confetti" />
<pass name="shadow" vs="M_Confetti" ps="M_Confetti" />
</technique>
29 changes: 22 additions & 7 deletions Content/Common/Data/UI/GameScreen.rml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@
}
/* Style of the root panel element */
dev.menu-panel {
width: 50%;
width: 50%;
max-height: 90%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.levelblock {
display: inline-block;
border-width: 1px;
border-color: #fff;
margin: 2px;
padding: 2px;
}
</style>
</head>
Expand All @@ -42,10 +50,17 @@
<img sprite="icon-settings"></img>
</input>
</div>
<div style="float: right">
<!--<div style="float: right">
<img sprite="icon-diamond"></img> 0
</div>
</div>-->
<div style="text-align: center">{{Level}}</div>
<div style="text-align: center">
<div class="levelblock" style="">{{CurrentLevel > BaseLevel ? 'V' : BaseLevel}}</div>
<div class="levelblock" style="">{{CurrentLevel > BaseLevel+1 ? 'V' : BaseLevel+1}}</div>
<div class="levelblock" style="">{{CurrentLevel > BaseLevel+2 ? 'V' : BaseLevel+2}}</div>
<div class="levelblock" style="">{{CurrentLevel > BaseLevel+3 ? 'V' : BaseLevel+3}}</div>
<div class="levelblock" style="">{{CurrentLevel > BaseLevel+4 ? 'V' : BaseLevel+4}}</div>
</div>
</div>

<div data-visible="Victory" class="" style="background: #000000A0; padding:10px; top: 50%; left: 50%; position: absolute; transform: translate(-50%, -50%); width: 50%; max-height: 90%">
Expand Down
16 changes: 14 additions & 2 deletions RbfxTemplate/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public sealed class GameState : RmlUIStateBase
private Vector2 _areaSize = new Vector2(1, 1);

private int _levelIndex;
private int _hintsLeft = 1;
private int _hintsLeft = 2;
private bool _victory;
private readonly FiniteTimeAction _confettiAnimation;

public GameState(UrhoPluginApplication app) : base(app, "UI/GameScreen.rml")
{
Expand Down Expand Up @@ -86,6 +87,8 @@ public GameState(UrhoPluginApplication app) : base(app, "UI/GameScreen.rml")
_dragState = new DragState(this);
_victoryState = new VictoryState(this);

_confettiAnimation = new ActionBuilder(Context).Enable().ShaderParameterFromTo(1.0f, "AnimationPhase", 0.0f, 1.0f).Disable().Build();

NextLevel(null);

Deactivate();
Expand All @@ -108,6 +111,8 @@ public StateBase State
public override void OnDataModelInitialized(GameRmlUIComponent component)
{
component.BindDataModelProperty("Level", _ => _.Set("Level " + _levelIndex), _ => { });
component.BindDataModelProperty("BaseLevel", _ => _.Set(1+((_levelIndex-1)/5)*5), _ => { });
component.BindDataModelProperty("CurrentLevel", _ => _.Set(_levelIndex), _ => { });
component.BindDataModelProperty("Victory", _ => _.Set(_victory), _ => { });
component.BindDataModelEvent("Next", NextLevel);
component.BindDataModelEvent("Settings", Settings);
Expand Down Expand Up @@ -253,7 +258,8 @@ public void StartPicking()
if (tile.LinkedTile != tile.ValidLink)
{
isCorrect = false;
hint = tile;
if (hint == null)
hint = tile;
}
}

Expand Down Expand Up @@ -304,6 +310,12 @@ protected override void Dispose(bool disposing)

private void Victory()
{
var nodeList = new NodeList();
_scene.Ptr.GetNodesWithTag(nodeList, "Confetti");
foreach (var node in nodeList)
{
ActionManager.AddAction(_confettiAnimation, node);
}
State = _victoryState;
_victory = true;
RmlUiComponent.UpdateProperties();
Expand Down

0 comments on commit 55d51c9

Please sign in to comment.