Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f576c59
Fumbling toward a transformation on CoronaTotalTime, so far the comma…
ggcrunchy Feb 7, 2019
6626191
Moved some of the time transform stuff into ShaderResource with link …
ggcrunchy Feb 8, 2019
e59f04a
Better argument checking for time transforms
ggcrunchy Feb 9, 2019
e05f972
Whoops, wasn't always linking Program back to ShaderResource
ggcrunchy Feb 10, 2019
c7af750
Removed notes to self about changes
ggcrunchy Feb 11, 2019
9058c1f
timeTransform ignored if no time dependency
ggcrunchy Feb 11, 2019
c01d916
Minor changes
ggcrunchy May 29, 2020
08dc3b6
Maintenance Revert Test
scottrules44 Sep 20, 2021
05b91fb
Simulator: Adding Samsung Galaxy 21 as a skin
scottrules44 Sep 22, 2021
f44be24
Maintenance
scottrules44 Sep 22, 2021
581d844
Android: adding rest of media intents for Android 11
scottrules44 Sep 22, 2021
265be3c
Merge
ggcrunchy Sep 23, 2021
e217c80
Merge
ggcrunchy Oct 4, 2021
ca300c1
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Oct 19, 2021
0b5e1e9
First go at graphics.undefineEffect()
ggcrunchy Nov 9, 2021
b41e624
Revert "First go at graphics.undefineEffect()"
ggcrunchy Nov 10, 2021
5be6193
Merging upstream
ggcrunchy Aug 18, 2022
f38ecec
Merge branch 'master' of https://github.com/ggcrunchy/corona
ggcrunchy Aug 18, 2022
bb395b8
Merge branch 'master' of https://github.com/coronalabs/corona
ggcrunchy Dec 16, 2022
0bf47a5
Merge remote-tracking branch 'upstream/master'
ggcrunchy Jun 12, 2025
8deb2bf
First go at some time improvements in shaders (mostly GL backend, so …
ggcrunchy Sep 14, 2025
a2ce309
Removed leftover include from testing
ggcrunchy Sep 16, 2025
dc7ca45
Still needs a bit of testing, but redid Vulkan transforms to follow l…
ggcrunchy Sep 23, 2025
4caa1f2
A couple more bits of cleanup
ggcrunchy Sep 23, 2025
aa405ff
Whoops, more cleanup
ggcrunchy Sep 23, 2025
5c662c3
Realized time transform could be misapplied if total time uniform was…
ggcrunchy Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions librtt/Display/Rtt_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,61 @@ Scene::Render( Renderer& renderer, PlatformSurface& rTarget, ProfilingEntryRAII*

// When shader code depends on time, then frame is time-dependent.
// So only set valid when frame is *in*dependent of time.

// N.B. rather than requiring an explicit isTimeDependent flag to
// graphics.defineEffect(), a program is now queried about whether
// it has time-related state; this is captured in the ShaderResource's
// "uses time" flag, as before. The catch is that the resources in
// question first become available in either renderer.Swap() or
// renderer.Render(), too late for the check done here.
if ( ! renderer.IsFrameTimeDependent() )
{
fIsValid = true;
}

// Some further analysis:

// If DEFER_CREATION / DEFER_VK_CREATION are disabled, a new program's
// GPUResource will come into being in renderer.Swap(), and the shader
// objects for every ShaderVersion are immediately Create()'d.

// Normally, however, we lazily create a given ProgramVersion's shader
// objects in its first Bind(), during renderer.Render().

// These operations, in either scenario, are strictly serial; the
// ShaderResource's flag may be set directly. (This would need rework
// if, say, a multithreaded renderer were adopted.)

// The conventional logic will pick up the flag the next time around.
// However, the relevant time-dependent objects might be the only cause
// for the scene to be invalid. A compromise here is to give the scene
// a kick, explicitly invalidating it if ANY shader resource was just
// assigned the "uses time" flag.

// The sanest CPU-side semantics--consistent with the isTimeDependent
// and ShaderResource flags--seems to be that if any ProgramVersion is
// time-dependent, all of them are interpreted this way. (This policy
// accounts for some corner cases, for instance only the fragment side
// might be time-dependent, but not be present in wireframe mode; this
// is cumbersome to convey precisely on the CPU side.)

ADD_ENTRY( "Scene: Issue Draw Commands" );

renderer.Swap(); // Swap back and front command buffers

ADD_ENTRY( "Scene: Swap" );

renderer.Render(); // Render front command buffer

// renderer.GetFrameStatistics().Log();

ADD_ENTRY( "Scene: Process Render Commands" );

if ( renderer.AddedUsesTime() ) // n.b. clears the flag
{
Invalidate();
}

rTarget.Flush();

ADD_ENTRY( "Scene: Flush" );
Expand Down
13 changes: 2 additions & 11 deletions librtt/Display/Rtt_ShaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ ShaderFactory::BindTimeTransform(lua_State *L, int index, const SharedPtr< Shade
{
const char *func = TimeTransform::FindFunc( L, -1, "graphics.defineEffect()" );

if (lua_isstring( L, -1 ))
if (func)
{
TimeTransform *transform = Rtt_NEW( fAllocator, TimeTransform );

Expand Down Expand Up @@ -762,11 +762,7 @@ ShaderFactory::InitializeBindings( lua_State *L, int shaderIndex, const SharedPt
BindDetails( L, shaderIndex, resource );
BindShellTransform( L, shaderIndex, resource );
BindVertexExtension( L, shaderIndex, resource );

if (resource->UsesTime())
{
BindTimeTransform( L, shaderIndex, resource );
}
BindTimeTransform( L, shaderIndex, resource );

bool has_vertex_data = BindVertexDataMap( L, shaderIndex, resource );
if( has_vertex_data )
Expand Down Expand Up @@ -1018,11 +1014,6 @@ ShaderFactory::NewShaderBuiltin( ShaderTypes::Category category, const char *nam

if (resource.NotNull())
{
lua_getfield( L, tableIndex, "isTimeDependent" );
bool usesTime = lua_toboolean( L, -1 ) ? true : false;
resource->SetUsesTime( usesTime );
lua_pop( L, 1 );

Shader *prototype = NULL;
prototype = NewShaderPrototype( L, tableIndex, resource );
result = (ShaderComposite*)prototype->Clone( fAllocator );
Expand Down
78 changes: 20 additions & 58 deletions librtt/Display/Rtt_ShaderResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,37 @@ namespace Rtt

// ----------------------------------------------------------------------------

bool
TimeTransform::Apply( Uniform *time, Real *old, U32 now )
Real
TimeTransform::Apply( Real value ) const
{
if (NULL != func && NULL != time)
{
if (timestamp != now)
{
timestamp = now;

time->GetValue(cached);

if (NULL != old)
{
*old = cached;
}

func( &cached, arg1, arg2, arg3 );
}

time->SetValue(cached);

return true;
}
Rtt_ASSERT( func );

return false;
return func( value, arg1, arg2, arg3 );
}

static void
Modulo( Real *x, Real range, Real, Real )
static Real
Modulo( Real x, Real range, Real, Real )
{
*x = fmod( *x, range ); // TODO?: Rtt_RealFmod
return fmod( x, range ); // TODO?: Rtt_RealFmod
}

static void
PingPong( Real *x, Real range, Real, Real )
static Real
PingPong( Real x, Real range, Real, Real )
{
Real pos = fmod( *x, Rtt_REAL_2 * range ); // TODO?: Rtt_RealFmod
Real pos = fmod( x, Rtt_REAL_2 * range ); // TODO?: Rtt_RealFmod

if (pos > range)
{
pos = Rtt_REAL_2 * range - pos;
}

*x = pos;
return pos;
}

static void
Sine( Real *x, Real amplitude, Real speed, Real shift )
static Real
Sine( Real x, Real amplitude, Real speed, Real shift )
{
Real t = *x;

*x = amplitude * Rtt_RealSin( speed * t + shift );
return amplitude * Rtt_RealSin( speed * x + shift );
}

int
Expand All @@ -105,7 +84,7 @@ TimeTransform::Push( lua_State *L ) const
lua_pushnumber( L, (Rtt_REAL_2 * M_PI) / arg2 );
lua_setfield( L, -2, "period" );
lua_pushnumber( L, arg3 );
lua_setfield( L, -2, "shift" );
lua_setfield( L, -2, "phase" );
}

else
Expand Down Expand Up @@ -191,16 +170,16 @@ TimeTransform::SetFunc( lua_State *L, int arg, const char *what, const char *fna

case 's': // sine
{
Real amplitude = Rtt_REAL_1, period = Rtt_REAL_2 * M_PI, shift = Rtt_REAL_0;
Real amplitude = Rtt_REAL_1, period = Rtt_REAL_2 * M_PI, phase = Rtt_REAL_0;

GetNumberArg( L, arg, &amplitude, fname, "amplitude", what );
GetPositiveNumberArg( L, arg, &period, fname, "period", what );
GetNumberArg( L, arg, &shift, fname, "shift", what );
GetNumberArg( L, arg, &phase, fname, "phase", what );

func = &Sine;
arg1 = amplitude;
arg2 = (Rtt_REAL_2 * M_PI) / period;
arg3 = shift;
arg3 = phase;
}
break;

Expand All @@ -209,25 +188,6 @@ TimeTransform::SetFunc( lua_State *L, int arg, const char *what, const char *fna
}
}

bool
TimeTransform::Matches( const TimeTransform *xform1, const TimeTransform *xform2 )
{
if (xform1 == xform2)
{
return true;
}

else if (NULL == xform1 || NULL == xform2)
{
return false;
}

else
{
return xform1->func == xform2->func && xform1->arg1 == xform2->arg1 && xform1->arg2 == xform2->arg2 && xform1->arg3 == xform2->arg3;
}
}

const char*
TimeTransform::FindFunc( lua_State *L, int arg, const char *what )
{
Expand Down Expand Up @@ -465,6 +425,8 @@ ShaderResource::SetDefaultData( ShaderData *defaultData )
}
}

bool ShaderResource::sAddedUsesTime;

// ----------------------------------------------------------------------------

} // namespace Rtt
Expand Down
16 changes: 10 additions & 6 deletions librtt/Display/Rtt_ShaderResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@ class FormatExtensionList;

struct TimeTransform
{
typedef void (*Func)( Real *time, Real arg1, Real arg2, Real arg3 );
typedef Real (*Func)( Real time, Real arg1, Real arg2, Real arg3 );

TimeTransform() : func( NULL ), arg1( 0 ), arg2( 0 ), arg3( 0 ), timestamp( ~0 )
TimeTransform() : func( NULL ), arg1( 0 ), arg2( 0 ), arg3( 0 )
{
}

bool Apply( Uniform *time, Real *old, U32 now );
Real Apply( Real value ) const;
int Push( lua_State *L ) const;
void SetDefault();
void SetFunc( lua_State *L, int arg, const char *what, const char *fname );

static bool Matches( const TimeTransform *xform1, const TimeTransform *xform2 );
static const char* FindFunc( lua_State *L, int arg, const char *what );

Func func;
Real arg1, arg2, arg3, cached;
U32 timestamp;
Real arg1, arg2, arg3;
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -139,6 +137,10 @@ class ShaderResource
void SetProgramMod(ProgramMod mod, Program *program);
Program *GetProgramMod(ProgramMod mod) const;

public:
static void SetAddedUsesTime( bool newValue ) { sAddedUsesTime = newValue; }
static bool GetAddedUsesTime() { return sAddedUsesTime; }

private:
void Init(Program *defaultProgram);

Expand All @@ -159,6 +161,8 @@ class ShaderResource
TimeTransform *fTimeTransform;
bool fUsesUniforms;
bool fUsesTime;

static bool sAddedUsesTime; // has ANY ShaderResource added the "uses time" flag?

};

Expand Down
11 changes: 10 additions & 1 deletion librtt/Display/Shader/kernel_filter_wobble_gl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ kernel.category = "filter"

kernel.name = "wobble"

kernel.isTimeDependent = true
--kernel.isTimeDependent = true
kernel.timeTransform = {
func = "modulo",
range = ( 2 / 3 ) * math.pi -- cf. VertexKernel()
}

kernel.vertexData =
{
Expand All @@ -23,6 +27,11 @@ kernel.vertex =
[[
P_POSITION vec2 VertexKernel( P_POSITION vec2 position )
{
// sine is periodic, so we can use a short modular range
// at t = 0, sin( 3 * 0 ) = 0 (ignoring phase)
// this will next happen as sin( 2 * pi ) = 0, i.e. when 3 * t = 2 * pi
// rearranging, t = ( 2 / 3 ) * pi

position.y += sin( 3.0 * u_TotalTime + a_TexCoord.x ) * a_UserData.x * a_TexCoord.y;

return position;
Expand Down
10 changes: 9 additions & 1 deletion librtt/Display/Shader/kernel_generator_marchingAnts_gl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ kernel.category = "generator"

kernel.name = "marchingAnts"

kernel.isTimeDependent = true
--kernel.isTimeDependent = true
kernel.timeTransform = {
func = "modulo",

-- the pattern is very regular, thus being able to mod the time
-- the range is two bar lengths (on, then off), divided by speed
-- the content scaling cancels out
range = (6 + 6) / 16
}

kernel.unsupportedPlatforms =
{
Expand Down
5 changes: 3 additions & 2 deletions librtt/Display/Shader/kernel_generator_random_gl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ kernel.category = "generator"

kernel.name = "random"

kernel.isTimeDependent = true
--kernel.isTimeDependent = true
kernel.timeTransform = { func = "modulo", range = 1 }

kernel.fragment =
[[
Expand All @@ -23,7 +24,7 @@ P_RANDOM float rand( P_RANDOM vec2 seed )
P_COLOR vec4 FragmentKernel( P_UV vec2 texCoord )
{
#if FRAGMENT_SHADER_SUPPORTS_HIGHP
P_RANDOM float time = fract( u_TotalTime );
P_RANDOM float time = u_TotalTime;//fract( u_TotalTime );

P_RANDOM float v0 = rand( vec2( ( time + texCoord.x ),
( time + texCoord.y ) ) );
Expand Down
Loading