Skip to content

Commit badbcd3

Browse files
Initial Stars Feature (o3de#8624)
Signed-off-by: Alex Peterson <[email protected]>
1 parent d6c21dd commit badbcd3

38 files changed

+1748
-4
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
*.smtl filter=lfs diff=lfs merge=lfs -text
105105
*.so filter=lfs diff=lfs merge=lfs -text
106106
*.sprite filter=lfs diff=lfs merge=lfs -text
107+
*.stars filter=lfs diff=lfs merge=lfs -text
107108
*.sub filter=lfs diff=lfs merge=lfs -text
108109
*.tga filter=lfs diff=lfs merge=lfs -text
109110
*.tif filter=lfs diff=lfs merge=lfs -text

AutomatedTesting/Gem/Code/enabled_gems.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ set(ENABLED_GEMS
5959
Multiplayer
6060
DevTextures
6161
PrimitiveAssets
62+
Stars
6263
)

Gems/Atom/RPI/Assets/ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultSceneSrg.azsli

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
partial ShaderResourceGroup SceneSrg
1414
{
15-
float m_time;
15+
float m_time; // number of seconds since the application started
1616
}
1717

Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Pass.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ namespace AZ
155155
bool HasDrawListTag() const;
156156
bool HasPipelineViewTag() const;
157157

158+
// Searches this pass's attachment bindings for one with the provided Name (nullptr if none found)
159+
PassAttachmentBinding* FindAttachmentBinding(const Name& slotName);
160+
158161
//! Return the set of attachment bindings
159162
PassAttachmentBindingListView GetAttachmentBindings() const;
160163

@@ -307,9 +310,6 @@ namespace AZ
307310
// Search order: 1.This -> 2.Parent -> 3.Siblings -> 4.Children
308311
Ptr<Pass> FindAdjacentPass(const Name& passName);
309312

310-
// Searches this pass's attachment bindings for one with the provided Name (nullptr if none found)
311-
PassAttachmentBinding* FindAttachmentBinding(const Name& slotName);
312-
313313
// Searches this pass's attachment bindings for one with the provided Name (nullptr if none found)
314314
const PassAttachmentBinding* FindAttachmentBinding(const Name& slotName) const;
315315

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) Contributors to the Open 3D Engine Project.
3+
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0 OR MIT
6+
*
7+
*/
8+
9+
#include <Atom/Features/ColorManagement/TransformColor.azsli>
10+
#include <Atom/Features/SrgSemantics.azsli>
11+
#include <scenesrg.srgi>
12+
#include <viewsrg.srgi>
13+
14+
ShaderResourceGroup PerDrawSrg : SRG_PerDraw
15+
{
16+
float3x3 m_rotation;
17+
18+
struct StarShaderConstants
19+
{
20+
float2 m_scale;
21+
float m_exposureFactor;
22+
float m_twinkleRate;
23+
};
24+
StarShaderConstants m_starParams;
25+
}
26+
27+
struct VSInput
28+
{
29+
float3 m_position : POSITION;
30+
float4 m_color : COLOR0;
31+
32+
uint m_vertexID : SV_VertexID;
33+
};
34+
35+
struct VSOutput
36+
{
37+
float4 m_position : SV_Position;
38+
float4 m_color : COLOR0;
39+
float2 m_quadPos : TEXCOORD;
40+
};
41+
42+
float GetFlickerAmount(in float3 pos)
43+
{
44+
const float2 StarShimmerTab[8] =
45+
{
46+
float2(0.897907815,-0.347608525), float2(0.550299290, 0.273586675),
47+
float2(0.823885965, 0.098853070), float2(0.922739035,-0.122108860),
48+
float2(0.800630175,-0.088956800), float2(0.711673375, 0.158864420),
49+
float2(0.870537795, 0.085484560), float2(0.956022355,-0.058114540)
50+
};
51+
52+
const float2 hash = frac(pos.xy * 256);
53+
const float timeInSeconds = SceneSrg::m_time;
54+
float index = frac(hash.x + (hash.y + 1) * PerDrawSrg::m_starParams.m_twinkleRate * timeInSeconds);
55+
index *= 8;
56+
57+
const float f = frac(index);
58+
const int i = int(index);
59+
return StarShimmerTab[i].x + f * StarShimmerTab[i].y;
60+
}
61+
62+
VSOutput MainVS(VSInput IN)
63+
{
64+
VSOutput OUT;
65+
66+
const float4 colorAndMagnitude = IN.m_color;
67+
68+
// Set the w component to 0 in order to project the stars out to infinity.
69+
const float4 pos = float4(mul(PerDrawSrg::m_rotation, IN.m_position), 0.0);
70+
OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, pos);
71+
72+
// using reverse z, so push depth out to the far plane
73+
// if can gaurantee the draw order, then can disable depth check entirely
74+
OUT.m_position.z = 0.0;
75+
76+
// apparent magnitude is how bright a star appears from earth
77+
// magnitude is a logarithmic scale and brighter objects have lower numbers
78+
// a star of magnitude 2.0 is 2.512 times as bright as a star of magnitude of 3.0
79+
// Sirius has a magnitude of -1.46
80+
// humans typically see stars with apparent magnitude ranging from -1.44 .. 6.5
81+
const float humanMinMag = -1.44;
82+
const float humanMaxMag = 6.5;
83+
84+
// scale colorAndMagnitude.w from 0..1 to 6.5..-1.44
85+
const float apparentMagnitude = humanMaxMag + colorAndMagnitude.w * (humanMinMag - humanMaxMag);
86+
87+
// scale the range from 6.5..-1.44 to 0..1 with a logarithmic scale approximation
88+
// e.g. 6.5 = 0.006, 1 = 0.2, 0 = 0.39, -1.44 = 1
89+
// and dim with animated flicker amount
90+
const float brightness = GetFlickerAmount(IN.m_position) * pow(5.0, (-apparentMagnitude + humanMinMag) / 2.5);
91+
OUT.m_color = float4(brightness * colorAndMagnitude.xyz, brightness);
92+
93+
const float2 expansion[6] =
94+
{
95+
float2( 1, 1),
96+
float2(-1, 1),
97+
float2( 1, -1),
98+
float2( 1, -1),
99+
float2(-1, 1),
100+
float2(-1, -1)
101+
};
102+
103+
const float2 texcoord[6] =
104+
{
105+
float2(1, 0),
106+
float2(0, 0),
107+
float2(1, 1),
108+
float2(1, 1),
109+
float2(0, 0),
110+
float2(0, 1)
111+
};
112+
113+
const uint vertexIndex = uint(IN.m_vertexID) % uint(6);
114+
OUT.m_position.xy += expansion[vertexIndex] * PerDrawSrg::m_starParams.m_scale;
115+
OUT.m_quadPos = texcoord[vertexIndex];
116+
return OUT;
117+
};
118+
119+
struct PSOutput
120+
{
121+
float4 m_diffuse : SV_Target0;
122+
};
123+
124+
PSOutput MainPS(VSOutput IN)
125+
{
126+
PSOutput OUT;
127+
128+
const float2 pos = IN.m_quadPos.xy;
129+
const float2 distCenter = 3.5 * pos.xy - 3.5 * float2(0.5, 0.5);
130+
const float scale = exp(-dot(distCenter, distCenter));
131+
132+
const float3 coolColor = IN.m_color.xyz;
133+
const float3 hotColor = IN.m_color.www; // always grayscale
134+
135+
const float3 color = PerDrawSrg::m_starParams.m_exposureFactor * (coolColor * scale + 5.0 * hotColor * pow(scale, 10.0));
136+
137+
OUT.m_diffuse = float4(color, scale);
138+
139+
return OUT;
140+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"Source": "Stars.azsl",
3+
"DepthStencilState": {
4+
"Depth": {
5+
"Enable": true,
6+
"CompareFunc": "GreaterEqual"
7+
}
8+
},
9+
"BlendState" : {
10+
"Enable" : true,
11+
"BlendSource" : "AlphaSource",
12+
"BlendDest" : "One",
13+
"BlendOp" : "Add"
14+
},
15+
"DrawList": "forward",
16+
"ProgramSettings": {
17+
"EntryPoints": [
18+
{
19+
"name": "MainVS",
20+
"type": "Vertex"
21+
},
22+
{
23+
"name": "MainPS",
24+
"type": "Fragment"
25+
}
26+
]
27+
}
28+
}

Gems/Stars/Assets/Stars/default.stars

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:7a1aeecd89902230c98fbeea34ab0a41f2473d493a037572c5b97d7ffcf06ffb
3+
size 106956

Gems/Stars/Assets/seedList.seed

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<ObjectStream version="3">
2+
<Class name="AZStd::vector" type="{82FC5264-88D0-57CD-9307-FC52E4DAD550}">
3+
<Class name="SeedInfo" field="element" version="2" type="{FACC3682-2ACA-4AA4-B85A-07AD276D18A0}">
4+
<Class name="AssetId" field="assetId" version="1" type="{652ED536-3402-439B-AEBE-4A5DBC554085}">
5+
<Class name="AZ::Uuid" field="guid" value="{A2640D6F-A59B-579A-A433-13844CA44859}" type="{E152C105-A133-4D03-BBF8-3D4B2FBA3E2A}"/>
6+
<Class name="unsigned int" field="subId" value="0" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
7+
</Class>
8+
<Class name="unsigned int" field="platformFlags" value="1" type="{43DA906B-7DEF-4CA8-9790-854106D3F983}"/>
9+
<Class name="AZStd::string" field="pathHint" value="shaders/stars/stars.azshader" type="{03AAAB3F-5C47-5A66-9EBC-D5FA4DB353C9}"/>
10+
</Class>
11+
</Class>
12+
</ObjectStream>
13+

Gems/Stars/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
# Copyright (c) Contributors to the Open 3D Engine Project.
3+
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0 OR MIT
6+
#
7+
#
8+
9+
set(gem_path ${CMAKE_CURRENT_LIST_DIR})
10+
set(gem_json ${gem_path}/gem.json)
11+
o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)
12+
13+
ly_add_external_target_path(${CMAKE_CURRENT_LIST_DIR}/3rdParty)
14+
15+
add_subdirectory(Code)

Gems/Stars/Code/CMakeLists.txt

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#
2+
# Copyright (c) Contributors to the Open 3D Engine Project.
3+
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0 OR MIT
6+
#
7+
#
8+
9+
ly_add_target(
10+
NAME Stars.Static STATIC
11+
NAMESPACE Gem
12+
FILES_CMAKE
13+
stars_files.cmake
14+
INCLUDE_DIRECTORIES
15+
PUBLIC
16+
Include
17+
PRIVATE
18+
Source
19+
BUILD_DEPENDENCIES
20+
PUBLIC
21+
AZ::AzCore
22+
AZ::AzFramework
23+
Gem::Atom_RHI.Public
24+
Gem::Atom_RPI.Public
25+
Gem::Atom_Utils.Static
26+
)
27+
28+
ly_add_target(
29+
NAME Stars.API HEADERONLY
30+
NAMESPACE Gem
31+
FILES_CMAKE
32+
stars_headers_files.cmake
33+
INCLUDE_DIRECTORIES
34+
INTERFACE
35+
include
36+
)
37+
38+
ly_add_target(
39+
NAME Stars ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
40+
NAMESPACE Gem
41+
FILES_CMAKE
42+
stars_shared_files.cmake
43+
INCLUDE_DIRECTORIES
44+
PUBLIC
45+
Include
46+
PRIVATE
47+
Source
48+
BUILD_DEPENDENCIES
49+
PRIVATE
50+
Gem::Stars.Static
51+
)
52+
53+
ly_create_alias(NAME Stars.Clients NAMESPACE Gem TARGETS Gem::Stars)
54+
55+
if(PAL_TRAIT_BUILD_HOST_TOOLS)
56+
ly_add_target(
57+
NAME Stars.Editor.Static STATIC
58+
NAMESPACE Gem
59+
FILES_CMAKE
60+
stars_editor_files.cmake
61+
INCLUDE_DIRECTORIES
62+
PRIVATE
63+
Source
64+
PUBLIC
65+
Include
66+
BUILD_DEPENDENCIES
67+
PUBLIC
68+
AZ::AzToolsFramework
69+
Gem::Stars.Static
70+
Gem::Atom_Feature_Common.Static
71+
Gem::Atom_Feature_Common.Public
72+
)
73+
74+
ly_add_target(
75+
NAME Stars.Editor GEM_MODULE
76+
NAMESPACE Gem
77+
AUTOMOC
78+
FILES_CMAKE
79+
stars_editor_shared_files.cmake
80+
INCLUDE_DIRECTORIES
81+
PRIVATE
82+
Source
83+
PUBLIC
84+
Include
85+
BUILD_DEPENDENCIES
86+
PUBLIC
87+
Gem::Stars.Editor.Static
88+
)
89+
90+
ly_create_alias(NAME Stars.Tools NAMESPACE Gem TARGETS Gem::Stars.Editor)
91+
# A Builders alias must exist for Gem Assets to be seen by the Asset Processor.
92+
# A Builders alias target must exist for the Prefab .spawnable builder to be able to
93+
# load the .dll so the builder can serialize StarComponents to .spawnable files
94+
# which are needed in the game launcher.
95+
ly_create_alias(NAME Stars.Builders NAMESPACE Gem TARGETS Gem::Stars.Editor)
96+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) Contributors to the Open 3D Engine Project.
3+
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0 OR MIT
6+
*
7+
*/
8+
9+
#pragma once
10+
11+
#include <Atom/RPI.Public/FeatureProcessor.h>
12+
13+
namespace AZ::Render
14+
{
15+
static const float StarsDefaultExposure = 1.0f;
16+
static const float StarsDefaultTwinkleRate = 0.5f;
17+
static const float StarsDefaultRadiusFactor = 7.0f;
18+
19+
class StarsFeatureProcessorInterface
20+
: public RPI::FeatureProcessor
21+
{
22+
public:
23+
AZ_RTTI(AZ::Render::StarsFeatureProcessorInterface, "{7ECE8A5E-366B-4942-B6F9-370DC6017927}");
24+
25+
struct StarVertex
26+
{
27+
AZStd::array<float, 3> m_position;
28+
uint32_t m_color;
29+
};
30+
31+
virtual void SetStars(const AZStd::vector<StarVertex>& starVertexData) = 0;
32+
virtual void SetExposure(float exposure) = 0;
33+
virtual void SetRadiusFactor(float radiusFactor) = 0;
34+
virtual void SetOrientation(AZ::Quaternion orientation) = 0;
35+
virtual void SetTwinkleRate(float rate) = 0;
36+
};
37+
}

0 commit comments

Comments
 (0)