Jump to content

Blinking Shader


OCD2

Recommended Posts

 

Hello,

I'm working on some shaders today,  which is an aspect of modding where I still have a lot learn. 

I wanted to ask some preemptive questions before getting to work.   

One of the shaders I will need to make is intended to be a slow strobe light - which ideally would come from my existing shader that has an alpha channel and glow.        

Questions:

Would I be able keep the glow keyword on the shader, and would it show the glow when it is strobing on - or would it show at all times, even when it's "off"?

Is there a keyword function that would allow a shader to strobe?

One idea I had to possibly make a shader strobe, would be to use an 2 stage ani map, with an animation that changes the color of the alpha channel for a brief moment to simulate a strobe light.

Any input appreciated.

Link to comment

 

Blinking shaders are mega easy. In your case, since you just want a light to appear, use blendFunc GL_ONE GL_ONE on the glow stage. Then use rgbGen const wave to make the blinking happen. The wave function adds an oscillator to the shader stage.

I'll try and give a basic summary of it, but the waveform functions can be found in the Q3 shader manual, section 2.4.8, "Waveform Functions"
http://toolz.nexuizninjaz.com/shader/

 

The final line in your shader will consist of rgbGen const wave <waveform> <base> <amplitude> <frequency> <phase>.

<waveform> can be sin, triangle, square, sawtooth, or inversesawtooth - in your case, inversesawtooth will give you the most control.

<base> Generally this is 0. This is the lowest point of your oscillator.

<amplitude> This is the lowest point of your oscillation, generally 1 but it can vary based on what you're doing.

<frequency> This is how many times per second the waveform oscillates.

<phase> This is how far along in the first cycle the oscillator will start. This is useful for timing several shaders to be synchronized.

 

Because all of the numeric values are normalized between 0 and 1, anything that exceeds that range will be treated as the maximum value. You can abuse this to make the strobe blink. I would suggest starting with something like this so you can see what the oscillator is doing:

{
	map textures/colors/white
	blendfunc GL_ONE GL_ONE
	rgbgen const wave inversesawtooth 0 1 0 1
}

Once you've seen how it works, change the rgbgen line to something like this and see what happens:

rgbgen const wave inversesawtooth -20 23 0 1

 

Spoiler

For fun, here's an example of something I made years ago using rgbGen const wave to the extreme, coupled with basic scripting so you can see what it does:

https://storage.nab622.com/nab622/Stayin_alive_disco.wmv

 

OCD2 likes this
Link to comment
57 minutes ago, NAB622 said:

 

Blinking shaders are mega easy. In your case, since you just want a light to appear, use blendFunc GL_ONE GL_ONE on the glow stage. Then use rgbGen const wave to make the blinking happen. The wave function adds an oscillator to the shader stage.

I'll try and give a basic summary of it, but the waveform functions can be found in the Q3 shader manual, section 2.4.8, "Waveform Functions"
http://toolz.nexuizninjaz.com/shader/

 

The final line in your shader will consist of rgbGen const wave <waveform> <base> <amplitude> <frequency> <phase>.


<waveform> can be sin, triangle, square, sawtooth, or inversesawtooth - in your case, inversesawtooth will give you the most control.

<base> Generally this is 0. This is the lowest point of your oscillator.

<amplitude> This is the lowest point of your oscillation, generally 1 but it can vary based on what you're doing.

<frequency> This is how many times per second the waveform oscillates.

<phase> This is how far along in the first cycle the oscillator will start. This is useful for timing several shaders to be synchronized.

 

Because all of the numeric values are normalized between 0 and 1, anything that exceeds that range will be treated as the maximum value. You can abuse this to make the strobe blink. I would suggest starting with something like this so you can see what the oscillator is doing:


{
	map textures/colors/white
	blendfunc GL_ONE GL_ONE
	rgbgen const wave inversesawtooth 0 1 0 1
}

Once you've seen how it works, change the rgbgen line to something like this and see what happens:


rgbgen const wave inversesawtooth -20 23 0 1

 

  Hide contents

For fun, here's an example of something I made years ago using this rgbGen const wave to the extreme, coupled with basic scripting so you can see what it does:

https://storage.nab622.com/nab622/stayin alive disco.wmv

 

Ah, I would have never thought of something like that as a solution!   (At least parttly because I've not done anything with waveforms yet lol)

One question about using the method you recommend. 

I would like the shader to have two "settings"  -   always on, and then triggered to strobe.     Could I simply trigger the always on shader to remap to the strobing waveform shader to make it work?      (Trigger, use script, switch to the waveform shader)

PS. The link to your disco example is a 404 error.

Link to comment
3 hours ago, NAB622 said:

Sorry, copy/paste fail. Fixed the link.

https://storage.nab622.com/nab622/Stayin_alive_disco.wmv

 

Edit: To make your strobe toggle on/off, just attach it to a func_wall, and fire the func_wall to toggle the strobe. That's what I did in my example video.

I added the waveform stage to my shader file glow stage, and nothing happened as far as I could tell.

I tried making a little cube with the example white waveform shader texture, and still nothing.     Well, the map hung up for a bit on devmap load, with the map image only showing up on about 1/4 of the screen.    It remedied after it eventually loaded, but that was new...

{
	map textures/colors/white
	blendfunc GL_ONE GL_ONE
	rgbgen const wave inversesawtooth 0 1 0 1
}

 

I tried using the color green in the shader file, and applying it to the text cube and nothing.

I tried the different values to see if that changed anything, but still nothing.
 

Do I have to enable anything while using devmap to see the effect?

 

Here is my current shader file after those attempts, if that helps:

Spoiler

gfx/automap/nrps3
    {
    nopicmip
    nomipmaps
    {
    clampmap gfx/automap/nrps3
    depthfunc equal
    blendfunc blend
    rgbGen identity
    alphaGen const 0.85
    }
}

gfx/mp/mplevels/nrps2/obj1r
{
    nopicmip
    {
        map gfx/mp/mplevels/nrps2/obj1r
        blendfunc blend
        rgbGen vertex
    }
}

textures/mytextures/hlight
{
    {
        map $lightmap
    }
    {
        map textures/mytextures/hlight
        blendFunc GL_DST_COLOR GL_ZERO
    }
    {
        map textures/mytextures/hlightglow
        blendFunc GL_ONE GL_ONE
        glow
        rgbgen identity
    }
}
textures/mytextures/tlight
{
    {
        map $lightmap
    }
    {
        map textures/mytextures/tlight
        blendFunc GL_DST_COLOR GL_ZERO
    }
    {
        map textures/mytextures/tlightglow
        blendFunc GL_ONE GL_ONE
        glow
        rgbGen identity
    }
    {
    map textures/colors/green
    blendfunc GL_ONE GL_ONE
    rgbgen const wave inversesawtooth -20 23 0 1
}

}

I tried a bunch of combinations, no luck getting anything out of the effect, im doing something wrong.

Link to comment
On 12/22/2020 at 12:13 PM, NAB622 said:

Sorry, copy/paste fail. Fixed the link.

https://storage.nab622.com/nab622/Stayin_alive_disco.wmv

 

Edit: To make your strobe toggle on/off, just attach it to a func_wall, and fire the func_wall to toggle the strobe. That's what I did in my example video.

What aspect of the disco shows the effect you are trying to teach me with the keyword and values rgbgen const wave inversesawtooth 0 1 0 1 ?  There's a lot going on there lol.   

Is it the dance floor with the lights that bloom one at a time in colors?

Link to comment
On 12/22/2020 at 1:03 PM, fullkevlar said:

no luck getting anything out of the effect, im doing something wrong.

I just looked up my shaders from years ago. I was actually using alphagen wave and not rgbgen wave, and blendFunc GL_SRC_ALPHA GL_ONE. See if that helps. Sorry, my bad! Memory is fuzzy, this was more than 12 years ago and I'm having to look through 3 computers of archived data...

 

1 hour ago, fullkevlar said:

What aspect of the disco shows the effect you are trying to teach me with the keyword and values rgbgen const wave inversesawtooth 0 1 0 1 ?  There's a lot going on there lol.   

Is it the dance floor with the lights that bloom one at a time in colors?

It's literally everything. The blinking shaders are applied to func_wall entities, and during runtime the script is simply toggling those func_walls on and off, which essentially enables and disables patterns of lights on the disco floor, or toggles the sequential lights around the room. Each of those items can also be toggled in red, green or blue, which can be used to mix and match colors.

Here's a couple of shaders to illustrate what's happening with the sequential lights, since that's the simplest part to show:

Spoiler

textures/dread_e/discolight_green_1
{
	qer_editorimage	textures/dread_e/imp_insignia
	q3map_nolightmap
    {
        map $whiteimage
        blendFunc GL_SRC_ALPHA GL_ONE
        rgbGen const ( 0.000000 0.900000 0.000000 )
        alphaGen wave triangle -0.285 1.5 0 2.5
    }
}

textures/dread_e/discolight_green_2
{
	qer_editorimage	textures/dread_e/imp_insignia
	q3map_nolightmap
    {
        map $whiteimage
        blendFunc GL_SRC_ALPHA GL_ONE
        rgbGen const ( 0.000000 0.900000 0.000000 )
        alphaGen wave triangle -0.285 1.5 0.33 2.5
    }
}

textures/dread_e/discolight_green_3
{
	qer_editorimage	textures/dread_e/imp_insignia
	q3map_nolightmap
    {
        map $whiteimage
        blendFunc GL_SRC_ALPHA GL_ONE
        rgbGen const ( 0.000000 0.900000 0.000000 )
        alphaGen wave triangle -0.285 1.5 0.66 2.5
    }
}

 

In your case, since you're looking for a strobe effect, you'll probably want to use wave inversesawtooth instead of wave triangle, and of course you'll want to tweak the numeric values to match what your needs are.

Sorry for how complicated this is....this is quite an extreme example. Unfortunately I do not have any other examples to show. :/

I should have mentioned this at the start, but this is only really useful for a decorative strobe. If you're looking to make a strobe light that casts light on the room around it, this method cannot be used. The best way to do that would be 100% scripts, but it won't be very strobe-like...more like a random blink. (In the video I linked, there is such an effect at the end.)

OCD2 likes this
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...