Author Topic: Having some Difficulties with Shaders  (Read 9654 times)

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Having some Difficulties with Shaders
« on: July 09, 2009, 08:41:16 pm »
Ok, I'm just starting to figure out this whole shader thing, but I'm trying to figure out what do I have to put into the .shader file to make it glow, changing from 104;34;139(Or 68228B if you like Hex) to 148;0;211 (Or 9400D3 if you like hex) and back again (Sine Wave, I suppose).
Could I get some help from someone who actually knows how to write shaders?
Thanks
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #1 on: July 14, 2009, 01:06:26 am »
Ok, Face pointed me in the righ direction sorta, but now I get some kinda of fail(I get the notex grey on white >.>)
Here's mah shader atm:
Code: [Select]
textures/spork/crystal_glow //Defines when to load if selected from texture menu

{

qer_editorimage textures/spork/crystal.jpg //image displayed in radiant

q3map_lightimage textures/spork/crystal.jpg //emitting pattern

q3map_surfacelight 750 //This is the setting that makes the texture emit light

{

map textures/spork/crystal.jpg //Texture displayed in map

}

{

map $lightmap //maps lightmap in

tcGen lightmap //generates lightmap

}

{

map textures/spork/crystal.jpg //Overlay source, kinda

blendfunc add //Adds previous image ignoring the darker parts.

{
map textures/spork/crystal_glow.jpg
blendfunc add
rgbgen wave sin 0.580392 0 1
}

}

}

Halp?
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

Knowitall66

  • Posts: 492
  • Turrets: +70/-52
Re: Having some Difficulties with Shaders
« Reply #2 on: July 14, 2009, 01:21:53 am »
Im gunna test some stuff my self but first things theres a } missing (Well it was put in the wrong place)
Code: [Select]
textures/spork/crystal_glow //Defines when to load if selected from texture menu
{
qer_editorimage textures/spork/crystal.jpg //image displayed in radiant
q3map_lightimage textures/spork/crystal.jpg //emitting pattern
q3map_surfacelight 750 //This is the setting that makes the texture emit light

{
map textures/spork/crystal.jpg //Texture displayed in map

}

{
map $lightmap //maps lightmap in
tcGen lightmap //generates lightmap
}

{
map textures/spork/crystal.jpg //Overlay source, kinda
blendfunc add //Adds previous image ignoring the darker parts.
}
{
map textures/spork/crystal_glow.jpg
blendfunc add
rgbgen wave sin 0.580392 0 1
}

}
EDIT: After a quick test it should to work fine now.
And one other thing PLEASE NEATEN UP YOUR SHADERS!!!
« Last Edit: July 14, 2009, 01:29:04 am by Knowitall66 »

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #3 on: July 14, 2009, 04:26:28 pm »
Doesn't Work For me......
An as for neatness, I just copy-pasted most of that and altered the file names. As I said, I'm still new to this
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #4 on: July 14, 2009, 08:58:25 pm »
Isn't there also a value missing in the rgbgen line ? It should be
Code: [Select]
  rgbgen wave sin <base> <amplitude> <phase> <frequency>

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #5 on: July 14, 2009, 09:18:39 pm »
I Haven't a clue, like I said, I'm still very new to this.
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #6 on: July 19, 2009, 11:20:33 pm »
*awkward silence*
So Does no one know?
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #7 on: July 21, 2009, 11:39:20 pm »
Ok, I Just Changed it a bit, so now I actually see something!
Unfortunately Its glowing white(Which makes the texture ugly) and doesn't alter the color at all.
Heres The Code Right now:
Code: [Select]
textures/spork/crystal_glow //Defines when to load if selected from texture menu
{
qer_editorimage textures/spork/crystal.jpg //image displayed in radiant
q3map_lightimage textures/spork/crystal.jpg //emitting pattern
q3map_surfacelight 750 //This is the setting that makes the texture emit light

{
map textures/spork/crystal.jpg //Texture displayed in map

}

{
map $lightmap //maps lightmap in
tcGen lightmap //generates lightmap
}

{
map textures/spork/crystal.jpg //Overlay source, kinda
blendfunc add //Adds previous image ignoring the darker parts.
}
{
map textures/spork/crystal.jpg
blendfunc add
rgbgen wave sin 0.580392 0 1 0.5
}

}
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

Knowitall66

  • Posts: 492
  • Turrets: +70/-52
Re: Having some Difficulties with Shaders
« Reply #8 on: July 21, 2009, 11:53:51 pm »
The colour of the light/glow it produce comes from the colour (average) of the texture.

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #9 on: July 22, 2009, 12:22:17 am »
Obviously not, cuz the texture is a dark purple, and I'm getting white light
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #10 on: July 22, 2009, 06:22:38 am »
You add the texture 3 times, that makes it very bright. Try without the 3rd step (the one with the Overlay source comment), that should make it darker.

Also your sine wave has amplitude 0, which means that the light value is constant 0.58..., if you want a wave that covers e.g. the range 0.2 to 0.8 you have to specify base 0.5 (= the middle value) and amplitude 0.3 (= the distance from middle to the corners).


Redman

  • Posts: 103
  • Turrets: +6/-6
Re: Having some Difficulties with Shaders
« Reply #11 on: July 22, 2009, 12:37:45 pm »
Code: [Select]
textures/spork/crystal_glow
{
qer_editorimage textures/spork/crystal.jpg
q3map_lightimage textures/spork/crystal.jpg
q3map_surfacelight 750
{
map textures/spork/crystal_2.jpg
blendfunc add
rgbGen wave sin 0 1 0.5 1
}
{
map textures/spork/crystal_1.jpg
blendfunc add
rgbGen wave sin 0 1 0.25 1
}
{
map textures/spork/crystal_2.jpg
blendfunc add
rgbGen wave sin 0 1 0 1
}
{
map textures/spork/crystal_1.jpg
blendfunc add
rgbGen wave sin 0 1 0.75 1
}
}

crystal_1.jpg - coloured crystal.jpg to 9400D3
crystal_2.jpg - coloured crystal.jpg to 68228B
(you need some good image editing software, such as GIMP or Photoshop)

If you want to change colours slower, decrease last number in every rgbGen.
And I think you don't need mapping lightmap on texture that lights.

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #12 on: July 22, 2009, 04:35:51 pm »
You, Sir, Are AWESOME!!!!!!!!!!


Now where is the karma up.....
anyways, SOLVED!

EDIT:

Errr...Not.

It would seem I have 2 slight problems.
1) The Crystal Texture is Now Semi-Transparent.
2) I can see through A Wall I shouldn't be able to that is just across the hall from the crystal that I've tested this on...
« Last Edit: July 22, 2009, 06:09:09 pm by A Spork »
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #13 on: July 22, 2009, 06:07:35 pm »
Remove blendfunc add from the first stage.

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #14 on: September 27, 2009, 04:19:06 am »
!bump
Ok, So I commented out the first blendfunc add, but now its glowing white again....

Code: [Select]
textures/spork/crystal_glow
{
qer_editorimage textures/spork/crystal_1.jpg
q3map_lightimage textures/spork/crystal_1.jpg
q3map_surfacelight 750
{
map textures/spork/crystal_2.jpg
// blendfunc add
rgbGen wave sin 0 1 0.5 0.05
}
{
map textures/spork/crystal_1.jpg
blendfunc add
rgbGen wave sin 0 1 0.25 0.05 
}
{
map textures/spork/crystal_2.jpg
blendfunc add
rgbGen wave sin 0 1 0 0.05 
}
{
map textures/spork/crystal_1.jpg
blendfunc add
rgbGen wave sin 0 1 0.75 0.05 
}
}
Halp?
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

Winnie the Pooh

  • Posts: 442
  • Turrets: +45/-85
Re: Having some Difficulties with Shaders
« Reply #15 on: September 27, 2009, 06:16:34 am »
Quote
I also realize that this is the internet, but even more so this is the forum for a video game on an internet, then even beyond that this is TREMULOUS forums the Satan version of all video game forums for a video game that is ON the internet.

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #16 on: September 28, 2009, 08:40:22 pm »
Could Prove Handy, but I'd prefer to just fix whatever is wrong with my more or less already  done shader.
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #17 on: September 28, 2009, 09:15:25 pm »
I think if you just want to toggle periodically between two textures, you should be alpha-blending:

Code: [Select]
textures/spork/crystal_glow
{
qer_editorimage textures/spork/crystal_1.jpg
q3map_lightimage textures/spork/crystal_1.jpg
q3map_surfacelight 750
{
map textures/spork/crystal_1.jpg
}
{
map textures/spork/crystal_2.jpg
blendfunc blend
alphaGen wave sin 0.5 0.5 0 1
}
}

As mentioned below, change the last number to make it pulse faster or slower.

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #18 on: September 28, 2009, 09:40:42 pm »
Nice, but its still glowing white....
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #19 on: September 30, 2009, 12:12:03 pm »
screenshot ?

A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #20 on: September 30, 2009, 07:26:57 pm »

Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

Ingar

  • Tremulous Developers
  • *
  • Posts: 554
  • Turrets: +302/-7
    • Ingar's projects on the Web
Re: Having some Difficulties with Shaders
« Reply #21 on: October 01, 2009, 07:20:57 pm »
I tried this:

Code: [Select]
textures/spork/crystal_glow
{
        qer_editorimage textures/spork/crystal.jpg
        q3map_lightimage textures/spork/crystal.jpg
        q3map_surfacelight 750
        {
                map textures/spork/crystal_1.jpg
                rgbgen wave sin .5 .5 0 0.25
        }
        {
                map textures/spork/crystal_2.jpg
                blendfunc add
                rgbgen wave sin .5 .5 0.5 0.25
        }
}

The 0.25 on the rgbgen line is the strobe frequency, in this example it will take
1 / 0.25 = 4 seconds for one cycle.

Note: Shader Manual, section 6.3 explains those rgbgen wave functions.

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #22 on: October 01, 2009, 08:01:34 pm »
Mathematically those two shaders do the same (except they have a different freq), because (wave sin .5 .5 0.5 0.25) == 1 - (wave sin .5 .5 0 0.25), so if you call the value of (wave sin .5 .5 0 0.25) alpha, then the final color is crystal1.jpg * alpha + crystal2.jpg * (1-alpha). (Ok, my shader computes crystal1.jpg * (1-alpha) + crystal2.jpg * alpha...)

I think the issue that Spork is talking about is that the light emmited from the crystal texture doesn't match the color of the texture. This can be modified by the q3map_lightimage texture, the emmited light will have the (average) color of that texture. Unfortunately the color is compiled into the static lightmap, so changing the texture color at runtime does NOT work.

The only (clumsy) ways to work around this are dynamic lights, which are computed at runtime, but are more limited (e.g. no shadows), or to add the illumination in a shader stage on the surrounding environment that toggles at the same frequency as the crystal.


A Spork

  • Spam Killer
  • *
  • Posts: 1010
  • Turrets: +37/-230
    • Spork - Unvanquished.net
Re: Having some Difficulties with Shaders
« Reply #23 on: October 01, 2009, 08:28:13 pm »
w00t!
It works now, Took ingars code, but changed the lightimage to crystal_2.
Don't shoot friend :basilisk:! Friend :basilisk: only wants to give you hugz and to be your hat

Proud Member of the S.O.B.F.O.B.S.A.D: The Society Of Basilisks For Other Basilisks Safety and Dominance
:basilisk:    :basilisk:    :basilisk:

Ingar

  • Tremulous Developers
  • *
  • Posts: 554
  • Turrets: +302/-7
    • Ingar's projects on the Web
Re: Having some Difficulties with Shaders
« Reply #24 on: October 01, 2009, 08:32:12 pm »
Mathematically those two shaders do the same (except they have a different freq), because (wave sin .5 .5 0.5 0.25) == 1 - (wave sin .5 .5 0 0.25), so if you call the value of (wave sin .5 .5 0 0.25) alpha, then the final color is crystal1.jpg * alpha + crystal2.jpg * (1-alpha). (Ok, my shader computes crystal1.jpg * (1-alpha) + crystal2.jpg * alpha...)

rgbgen with blendfunc add is probably computationally faster then alphagen with blendfunc filter
because there's no need for an alpha channel. The drawback is that I use two rgbgens.

I think the issue that Spork is talking about is that the light emmited from the crystal texture doesn't match the color of the texture. This can be modified by the q3map_lightimage texture, the emmited light will have the (average) color of that texture. Unfortunately the color is compiled into the static lightmap, so changing the texture color at runtime does NOT work.

The only (clumsy) ways to work around this are dynamic lights, which are computed at runtime, but are more limited (e.g. no shadows), or to add the illumination in a shader stage on the surrounding environment that toggles at the same frequency as the crystal.

Then the best option would probably be to cheat. Use the white texture as lightmap and
add seperate (static) light entities for both colors. Create a few shaders with a different
phase for different crystals and the result won't glow but it would probably look presentable.

Add a stage with envmap for extra shinyness.

edit:

w00t!
It works now, Took ingars code, but changed the lightimage to crystal_2.

You could make another shader with crystal_1 as lightmap (crystal_glow1 crystal_glow2)
and play around with that.
« Last Edit: October 01, 2009, 08:35:39 pm by Ingar »

gimhael

  • Posts: 546
  • Turrets: +70/-16
Re: Having some Difficulties with Shaders
« Reply #25 on: October 01, 2009, 09:15:32 pm »
rgbgen with blendfunc add is probably computationally faster then alphagen with blendfunc filter
because there's no need for an alpha channel. The drawback is that I use two rgbgens.

The add shader is in fact faster in the quake 3 engine, but not because of the simpler arithmetic, but because the engine can in fact render a opaque texture and an additive texture in a single multitexture pass, but it always renders a alpha-blended texture in a separate pass. (The code for combining opaque + alpha is present in the engine, but disabled for some reason.)

Also using two rgbgens has the advantage that you can use this also to alternate between two glow textures on top of a fixed base texture like
Code: [Select]
textures/spork/crystal_glow
{
        qer_editorimage textures/spork/crystal.jpg
        q3map_lightimage textures/spork/crystal.jpg
        q3map_surfacelight 750
        {
                map textures/spork/crystal_base
        }
        {
                map $lightmap
        }
        {
                map textures/spork/crystal_glow_1.jpg
                blendfunc add
                rgbgen wave sin .5 .5 0 0.25
        }
        {
                map textures/spork/crystal_glow_2.jpg
                blendfunc add
                rgbgen wave sin .5 .5 0.5 0.25
        }
}

You can't do this with the alpha blended texture.