Jump to content

ColorOscillate


Josh
 Share

Recommended Posts

Here's an example of a script that will make the entity's color oscillate over time:

function actor:Start()
self.speed = 1
self.color = Vec4(1)
end

function actor:Draw()
local luminance = (math.sin(Millisecs()*self.speed) / 2 + 0.5)
self.entity:SetColor(self.color * luminance)
end

Basically, I am thinking in terms of what Michael Betke could use. Not to pick on him, but programming is not his area of discipline, nor should it be. With scripts he can attach behaviors to entities and watch it go.

 

Add a couple of these scripts with different speeds set, and you get a random but smooth change in brightness.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

This version blends between two colors. I actually have it working in the render loop now:

function actor:Start()
self.speed = 1
self.color = {}
self.color[0] = Vec4(1,0.5,0.5,1)
self.color[1] = Vec4(0.25,1,1,1)
end

function actor:Draw()
local luminance = (math.sin(Millisecs()*self.speed*0.001) / 2 + 0.5)
local color = (self.color[0] * luminance) + (self.color[1] * (1-luminance))
self.entity:SetColor(color)
end

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Don't you need to multiply motion values with AppSpeed(). Most hardcore gamers have vsync forced off in the nvidia control panel (John Carmack told us not to use vsync ever, it's evil and bad), so Flip(1) won't do anything for them.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

You'd actually want to use AppTime() instead of Millisecs(), and everything would be fine. If you were gradually adding to a value, you would want to modulate it by AppSpeed().

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Now it's getting cool:

	teapot = LoadModel("models/teapot.mdl");
Actor* actor;

actor = teapot->AttachScript("ColorOscillate.lua");
actor->SetFloat("speed",4.0);

actor = teapot->AttachScript("Mover.lua");
actor->SetVec3("turnspeed",Vec3(0,1,0));
actor->SetBool("global",true);

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...