Skip to content
Permalink
Browse files

Rework shader control system

- Reduce the default shake amount in the shake shader
- Add speed uniform to shake shader
- Now, each shader controller is a ZScript class that has a virtual SetUniforms function.
- The amount of a shader controller a player can carry is now 2147483647, or practically unlimited.

I'm trying to figure out how to control the shaking amount of the shake shader based on the speed of the truck
  • Loading branch information...
Talon1024 committed Jul 26, 2017
1 parent e51f614 commit b62b6ae0879d261f08dabc7c5da4fb07379963a3
Showing with 81 additions and 46 deletions.
  1. +1 −0 boashaders.txt
  2. +0 −1 decorate.txt
  3. +23 −42 scripts/shaders/shadercontrol.txt
  4. +53 −0 scripts/shaders/shadercontrol_base.txt
  5. +2 −2 shaders/Shake.fp
  6. +2 −1 zscript.txt
@@ -396,6 +396,7 @@ HardwareShader PostProcess scene {
Name "shakeshader"
Shader "shaders/Shake.fp" 330
Uniform float timer
Uniform float speed
}

HardwareShader PostProcess scene {
@@ -133,4 +133,3 @@
#include "actors/misc/eastereggs.txt"
#include "actors/misc/titlemap.txt" //MaxED
#include "actors/misc/teleporter.txt"
#include "actors/misc/shadercontrol.txt" // Talon1024
@@ -1,50 +1,31 @@
/*
Shader controller base class

This allows mappers to control shaders using the GiveInventory/TakeInventory
ACS functions.

Do not use this directly! Instead, make an actor class that inherits from
ShaderControl. Set the ShaderControl.Shader property to the name of the
shader to control. The shader must be defined in GLDEFS.

To enable a shader, give 2 of the ShaderControl subclass item to the player.
For example:

GiveInventory("ShakeShaderControl", 2);

To disable a shader, take 1 or 2 of the shader control item away.
For example:

TakeInventory("ShakeShaderControl", 2);
Shake shader control - shakes the screen based on the movement of an actor
The amount the player has is the TID of the actor to check the speed of.
*/
class ShaderControl : Inventory {
string ShaderToControl;
property Shader: ShaderToControl;
class ShakeShaderControl : ShaderControl {
Default {
Inventory.MaxAmount 2;
ShaderControl.Shader "shakeshader";
}
}

class CustomShaderHandler : StaticEventHandler
{
override void RenderOverlay(RenderEvent e)
{
PlayerInfo p = players[consoleplayer];
ShaderControl shaderControl = ShaderControl(p.mo.FindInventory("ShaderControl", true));

if (shaderControl != null)
{
//Console.Printf("Shader: %s", shaderControl.ShaderToControl);
if (shaderControl.amount == 2)
{
Shader.SetUniform1f(p, shaderControl.ShaderToControl, "timer", gametic + e.FracTic);
Shader.SetEnabled(p, shaderControl.ShaderToControl, true);
}
else
{
Shader.SetEnabled(p, shaderControl.ShaderToControl, false);
}
override void SetUniforms(PlayerInfo p, RenderEvent e) {
/*
Actor thingToGetSpeedOf;
if (amount == 2) {
thingToGetSpeedOf = p.mo;
} else {
ActorIterator it = ActorIterator.Create(amount, "Actor");
thingToGetSpeedOf = it.Next();
}
double speed = thingToGetSpeedOf.speed;
Console.printf("Thing's speed: %f", speed);
*/
double speed = 1.0;
Shader.SetUniform1f(p, ShaderToControl, "speed", speed);
}
}

class OldVideoShaderControl : ShaderControl {
Default {
ShaderControl.Shader "oldvideoshader";
}
}
@@ -0,0 +1,53 @@
/*
Shader controller base class

This allows mappers to control shaders using the GiveInventory/TakeInventory
ACS functions.

Do not use this directly! Instead, make an actor class that inherits from
ShaderControl. Set the ShaderControl.Shader property to the name of the
shader to control. The shader must be defined in GLDEFS.

To enable a shader, give 2 of the ShaderControl subclass item to the player.
For example:

GiveInventory("ShakeShaderControl", 2);

To disable a shader, take 1 or 2 of the shader control item away.
For example:

TakeInventory("ShakeShaderControl", 2);
*/
class ShaderControl : Inventory {
string ShaderToControl;
property Shader: ShaderToControl;
Default {
Inventory.MaxAmount 0x7fffffff;
}

virtual ui void SetUniforms(PlayerInfo p, RenderEvent e) {}
}

class CustomShaderHandler : StaticEventHandler
{
override void RenderOverlay(RenderEvent e)
{
PlayerInfo p = players[consoleplayer];
ShaderControl shaderControl = ShaderControl(p.mo.FindInventory("ShaderControl", true));

if (shaderControl != null)
{
//Console.Printf("Shader: %s", shaderControl.ShaderToControl);
if (shaderControl.amount >= 2)
{
Shader.SetUniform1f(p, shaderControl.ShaderToControl, "timer", gametic + e.FracTic);
shaderControl.SetUniforms(p, e);
Shader.SetEnabled(p, shaderControl.ShaderToControl, true);
}
else
{
Shader.SetEnabled(p, shaderControl.ShaderToControl, false);
}
}
}
}
@@ -1,5 +1,5 @@
// Modified from Nash's GZDoom port of the old video shader by Talon1024
#define MAX_SHAKE 0.005
#define MAX_SHAKE 0.002
#define FREQUENCY 15.0

vec2 uv;
@@ -22,7 +22,7 @@ void main()
float t = float(int(timer * FREQUENCY));

// Get some image movement
vec2 suv = uv + MAX_SHAKE * vec2(rand(t), rand(t + 23.0));
vec2 suv = uv + speed * MAX_SHAKE * vec2(rand(t), rand(t + 23.0));

// Get the image
vec3 image = texture(InputTexture, vec2(suv.x, suv.y)).xyz;
@@ -40,5 +40,6 @@ version "2.5"
#include "scripts/items/visibility.txt" // Stealth visibility handling for player

/// Shaders
#include "scripts/shaders/shadercontrol.txt" // Talon1024 - Generic custom shader controls
#include "scripts/shaders/shadercontrol_base.txt" // Talon1024 - Generic custom shader controls
#include "scripts/shaders/shadercontrol.txt" // Talon1024 - Shader controllers
#include "scripts/shaders/underwater.txt" // Underwater

0 comments on commit b62b6ae

Please sign in to comment.
You can’t perform that action at this time.