Repository navigation
Add Tr2Sprite2dEffect, a sprite that draws an effect over its rect #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright © 2026 CCP ehf. | ||
|
|
||
| #include "StdAfx.h" | ||
| #include "Tr2Sprite2dEffect.h" | ||
| #include "Tr2Sprite2dScene.h" | ||
| #include "Tr2Sprite2dPickingMask.h" | ||
| #include "Shader/Tr2Effect.h" | ||
|
|
||
| static unsigned short s_quadIndices[6] = { 0, 1, 3, 3, 1, 2 }; | ||
|
|
||
| Tr2Sprite2dEffect::Tr2Sprite2dEffect( IRoot* lockobj /*= NULL */ ) : | ||
| m_color( 1.0f, 1.0f, 1.0f, 1.0f ), | ||
| m_glowBrightness( 1.0f ), | ||
| m_target( Tr2SpriteTarget::COLOR ) | ||
| { | ||
| } | ||
|
|
||
| void Tr2Sprite2dEffect::GatherSprites( Tr2Sprite2dScene* renderer ) | ||
| { | ||
| TRINITY_STATS_ZONE( __FUNCTION__ ); | ||
|
|
||
| if( !m_display || !m_effect ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| static const Vector2 s_corners[4] = { | ||
| Vector2( 0.0f, 0.0f ), | ||
| Vector2( 1.0f, 0.0f ), | ||
| Vector2( 1.0f, 1.0f ), | ||
| Vector2( 0.0f, 1.0f ) | ||
| }; | ||
|
|
||
| // Every field is set here, from the sprite or as a default Tr2SpriteObject | ||
| // would set it, so the effect gets the same vertices whatever the sprites | ||
| // before it left | ||
| renderer->SetDepth( 0.0f ); | ||
|
|
||
| Tr2Sprite2dD3DVertex vertices[4]; | ||
| for( int i = 0; i < 4; ++i ) | ||
| { | ||
| Tr2Sprite2dD3DVertex& vertex = vertices[i]; | ||
| vertex.position = Vector3( m_translation.x + s_corners[i].x * m_displayWidth, m_translation.y + s_corners[i].y * m_displayHeight, 0.0f ); | ||
| vertex.color = m_color; | ||
| vertex.texCoord[0] = s_corners[i]; | ||
| vertex.texCoord[1] = Vector2( m_displayWidth, m_displayHeight ); | ||
| vertex.glowBrightness = m_glowBrightness; | ||
| vertex.transformIndex = 0; | ||
| vertex.blendMode = PackBlendMode( TR2_SBM_NONE, m_target ); | ||
| vertex.spriteEffect = TR2_SFX_FILL; | ||
| vertex.tileMode = S2D_TS_NONE; | ||
| vertex.outlineColor = Color( 0.0f, 0.0f, 0.0f, 1.0f ); | ||
| vertex.outlineThreshold = 0.0f; | ||
| } | ||
|
|
||
| renderer->RenderTriangleVerts( *m_effect, vertices, 4, s_quadIndices, 6 ); | ||
| } | ||
|
|
||
| ITr2SpriteObject* Tr2Sprite2dEffect::PickPoint( float x, float y, Tr2Sprite2dScene* renderer ) | ||
| { | ||
| if( !m_display ) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| if( m_pickState == TR2_SPS_ON ) | ||
| { | ||
| if( renderer->IsInside( Vector2( x, y ), m_translation, m_displayWidth, m_displayHeight, 0.0f ) ) | ||
| { | ||
| if( !m_pickingMask || m_pickingMask->SampleMask( renderer->InverseTransformPoint( Vector2( x, y ) ), m_translation, m_displayWidth, m_displayHeight ) ) | ||
| { | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return NULL; | ||
| } | ||
|
|
||
| unsigned int Tr2Sprite2dEffect::GetVertexCount() | ||
| { | ||
| return ( m_display && m_effect ) ? 4 : 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright © 2026 CCP ehf. | ||
|
|
||
| #pragma once | ||
| #ifndef Tr2Sprite2dEffect_h | ||
| #define Tr2Sprite2dEffect_h | ||
|
|
||
| #include "ITr2SpriteObject.h" | ||
| #include "Tr2SpriteObject.h" | ||
|
|
||
| BLUE_DECLARE( Tr2Effect ); | ||
| BLUE_DECLARE( Tr2Sprite2dEffect ); | ||
|
|
||
| // A leaf sprite that draws one effect over its rect, in order with the other | ||
| // sprites, as a draw call of its own. The effect draws the sprite's quad in | ||
| // place of the scene's own shaders, so it gets the same vertices and | ||
| // constants (UIVertexInput, g_uiTransforms and UIViewportSize in | ||
| // Carbon/UI/UI.fxh), clips and transforms them as they do, and should write | ||
| // glow to SV_Target1 like them. Texcoord 0 runs 0 to 1 over the quad, texcoord | ||
| // 1 is the quad's width and height, and the vertex color is the sprite's color | ||
| // with its ancestors' opacity multiplied into alpha. The glow brightness and | ||
| // sprite target are the sprite's own, and the other vertex fields hold a | ||
| // default sprite's values, whatever was drawn before. The effect gets none of | ||
| // the scene's textures. | ||
| class Tr2Sprite2dEffect : public Tr2SpriteObjectBase | ||
| { | ||
| public: | ||
| EXPOSE_TO_BLUE(); | ||
|
|
||
| Tr2Sprite2dEffect( IRoot* lockobj = NULL ); | ||
|
|
||
| ////////////////////////////////////////////////////////////////////////// | ||
| // ITr2SpriteObject | ||
| unsigned int GetVertexCount(); | ||
| void GatherSprites( Tr2Sprite2dScene* renderer ) override; | ||
| ITr2SpriteObject* PickPoint( float x, float y, Tr2Sprite2dScene* renderer ) override; | ||
|
|
||
| private: | ||
| Tr2EffectPtr m_effect; | ||
| Color m_color; | ||
| float m_glowBrightness; | ||
| Tr2SpriteTarget m_target; | ||
| }; | ||
|
|
||
| TYPEDEF_BLUECLASS( Tr2Sprite2dEffect ); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright © 2026 CCP ehf. | ||
|
|
||
| #include "StdAfx.h" | ||
| #include "Tr2Sprite2dEffect.h" | ||
|
|
||
| BLUE_DEFINE( Tr2Sprite2dEffect ); | ||
|
|
||
| const Be::ClassInfo* Tr2Sprite2dEffect::ExposeToBlue() | ||
| { | ||
| EXPOSURE_BEGIN( Tr2Sprite2dEffect, "" ) | ||
| MAP_INTERFACE( ITr2SpriteObject ) | ||
| MAP_INTERFACE( Tr2Sprite2dEffect ) | ||
|
|
||
| MAP_ATTRIBUTE( | ||
| "effect", | ||
| m_effect, | ||
| "The effect drawn over the sprite's quad in place of the scene's shaders, or None. It gets the\n" | ||
| "scene's vertices and constants (see Carbon/UI/UI.fxh), with texcoord 0 running 0 to 1 over the quad,\n" | ||
| "texcoord 1 holding the quad's width and height, and the sprite's color in the vertex color.", | ||
| Be::READWRITE | Be::NOTIFY ) | ||
|
|
||
| MAP_ATTRIBUTE( | ||
| "color", | ||
| m_color, | ||
| "Color of the sprite, passed to the effect as the vertex color. Its alpha is multiplied with its ancestors' opacity.", | ||
| Be::READWRITE | Be::NOTIFY ) | ||
|
|
||
| MAP_ATTRIBUTE( | ||
| "glowBrightness", | ||
| m_glowBrightness, | ||
| "Glow brightness passed to the effect in the vertices. See spriteTarget.", | ||
| Be::READWRITE | Be::NOTIFY ) | ||
|
|
||
| MAP_ATTRIBUTE_WITH_CHOOSER( | ||
| "spriteTarget", | ||
| m_target, | ||
| "Render target passed to the effect in the vertices: either color or glow target", | ||
| Be::READWRITE | Be::ENUM | Be::NOTIFY, | ||
| Tr2SpriteTargetChooser ) | ||
| EXPOSURE_CHAINTO( Tr2SpriteObjectBase ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.