Dynamic Water in Barrens and Glen
This commit is contained in:
parent
549bd44cce
commit
7763b998a6
|
|
@ -191,6 +191,7 @@ set(EMBEDDED_INPUT
|
||||||
shader/hue.frag
|
shader/hue.frag
|
||||||
shader/sprite.frag
|
shader/sprite.frag
|
||||||
shader/worldMachine.frag
|
shader/worldMachine.frag
|
||||||
|
shader/water.frag
|
||||||
shader/plane.frag
|
shader/plane.frag
|
||||||
shader/gray.frag
|
shader/gray.frag
|
||||||
shader/bitmapBlit.frag
|
shader/bitmapBlit.frag
|
||||||
|
|
@ -205,7 +206,6 @@ set(EMBEDDED_INPUT
|
||||||
shader/simple.vert
|
shader/simple.vert
|
||||||
shader/simpleColor.vert
|
shader/simpleColor.vert
|
||||||
shader/sprite.vert
|
shader/sprite.vert
|
||||||
shader/worldMachine.vert
|
|
||||||
shader/tilemap.vert
|
shader/tilemap.vert
|
||||||
shader/blur.frag
|
shader/blur.frag
|
||||||
shader/blurH.vert
|
shader/blurH.vert
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ DEF_PROP_I(Plane, OX)
|
||||||
DEF_PROP_I(Plane, OY)
|
DEF_PROP_I(Plane, OY)
|
||||||
DEF_PROP_I(Plane, Opacity)
|
DEF_PROP_I(Plane, Opacity)
|
||||||
DEF_PROP_I(Plane, BlendType)
|
DEF_PROP_I(Plane, BlendType)
|
||||||
|
DEF_PROP_I(Plane, Shader)
|
||||||
|
|
||||||
DEF_PROP_F(Plane, ZoomX)
|
DEF_PROP_F(Plane, ZoomX)
|
||||||
DEF_PROP_F(Plane, ZoomY)
|
DEF_PROP_F(Plane, ZoomY)
|
||||||
|
|
@ -75,4 +76,5 @@ void planeBindingInit(){
|
||||||
INIT_PROP_BIND( Plane, BlendType, "blend_type" );
|
INIT_PROP_BIND( Plane, BlendType, "blend_type" );
|
||||||
INIT_PROP_BIND( Plane, Color, "color" );
|
INIT_PROP_BIND( Plane, Color, "color" );
|
||||||
INIT_PROP_BIND( Plane, Tone, "tone" );
|
INIT_PROP_BIND( Plane, Tone, "tone" );
|
||||||
|
INIT_PROP_BIND( Plane, Shader, "shader" );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,7 @@ class Game_Map
|
||||||
ANIMATED = [
|
ANIMATED = [
|
||||||
'blue_water',
|
'blue_water',
|
||||||
]
|
]
|
||||||
FADE_ANIMATION_PANORAMA = [
|
FADE_ANIMATION_PANORAMA = []
|
||||||
'dark_water',
|
|
||||||
'green_water',
|
|
||||||
]
|
|
||||||
ONETOONE = [
|
ONETOONE = [
|
||||||
'blue_water',
|
'blue_water',
|
||||||
'green_water',
|
'green_water',
|
||||||
|
|
@ -73,7 +70,7 @@ class Game_Map
|
||||||
]
|
]
|
||||||
NOZOOM = [
|
NOZOOM = [
|
||||||
'dark_water',
|
'dark_water',
|
||||||
#'green_water',
|
'green_water',
|
||||||
]
|
]
|
||||||
|
|
||||||
ALWAYS_MOVING = [
|
ALWAYS_MOVING = [
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ class Spriteset_Map
|
||||||
end
|
end
|
||||||
if @panorama_name != ""
|
if @panorama_name != ""
|
||||||
if $game_map.pan_fade_animate
|
if $game_map.pan_fade_animate
|
||||||
|
@panorama.shader = Shader::Plane
|
||||||
if @panorama2 == nil
|
if @panorama2 == nil
|
||||||
@panorama2 = Plane.new(@viewport_bg)
|
@panorama2 = Plane.new(@viewport_bg)
|
||||||
@panorama2.z = -999
|
@panorama2.z = -999
|
||||||
|
|
@ -181,8 +182,23 @@ class Spriteset_Map
|
||||||
end
|
end
|
||||||
@panorama.bitmap = RPG::Cache.panorama(@panorama_name + (1 + @pan_frame_index).to_s, @panorama_hue)
|
@panorama.bitmap = RPG::Cache.panorama(@panorama_name + (1 + @pan_frame_index).to_s, @panorama_hue)
|
||||||
@panorama2.bitmap = RPG::Cache.panorama(@panorama_name + (1 + @pan_frame_index).to_s, @panorama_hue)
|
@panorama2.bitmap = RPG::Cache.panorama(@panorama_name + (1 + @pan_frame_index).to_s, @panorama_hue)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
if @panorama_name == "dark_water"
|
||||||
|
@panorama.shader = Shader::Water
|
||||||
|
@panorama.color.set(0, 0, 127, 0)
|
||||||
|
@panorama.tone.set(0, 0, 255, 63)
|
||||||
|
@panorama.blend_type = 1
|
||||||
|
elsif @panorama_name == "green_water"
|
||||||
|
@panorama.shader = Shader::Water
|
||||||
|
@panorama.color.set(0, 21, 43, 100)
|
||||||
|
@panorama.tone.set(13, 236, 255, 200)
|
||||||
|
@panorama.blend_type = 1
|
||||||
|
else
|
||||||
|
@panorama.shader = Shader::Plane
|
||||||
|
@panorama.color.set(0, 0, 0, 0)
|
||||||
|
@panorama.tone.set(0, 0, 0, 0)
|
||||||
|
@panorama.blend_type = 0
|
||||||
|
end
|
||||||
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
|
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -272,7 +288,7 @@ class Spriteset_Map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if $game_map.pan_fade_animate
|
if $game_map.pan_fade_animate && @panorama2 != nil
|
||||||
@panorama2.opacity += 3
|
@panorama2.opacity += 3
|
||||||
@panorama2.ox = @panorama.ox
|
@panorama2.ox = @panorama.ox
|
||||||
@panorama2.oy = @panorama.oy
|
@panorama2.oy = @panorama.oy
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
|
||||||
|
|
||||||
|
uniform sampler2D texture;
|
||||||
|
|
||||||
|
uniform lowp vec4 tone;
|
||||||
|
|
||||||
|
uniform lowp float opacity;
|
||||||
|
uniform lowp vec4 color;
|
||||||
|
uniform lowp vec4 modulate;
|
||||||
|
|
||||||
|
uniform float bushDepth;
|
||||||
|
uniform lowp float bushOpacity;
|
||||||
|
|
||||||
|
uniform float uTime;
|
||||||
|
|
||||||
|
varying vec2 v_texCoord;
|
||||||
|
|
||||||
|
uniform vec2 texSizeInv;
|
||||||
|
|
||||||
|
const vec3 lumaF = vec3(.299, .587, .114);
|
||||||
|
const float WATER_DISTORTION = 0.75;
|
||||||
|
|
||||||
|
vec4 mod289(vec4 x)
|
||||||
|
{
|
||||||
|
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 permute(vec4 x)
|
||||||
|
{
|
||||||
|
return mod289(((x*34.0)+1.0)*x);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 taylorInvSqrt(vec4 r)
|
||||||
|
{
|
||||||
|
return 1.79284291400159 - 0.85373472095314 * r;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 fade(vec2 t) {
|
||||||
|
return t*t*t*(t*(t*6.0-15.0)+10.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float pnoise(vec2 P)
|
||||||
|
{
|
||||||
|
vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
|
vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
|
Pi = mod289(Pi); // To avoid truncation effects in permutation
|
||||||
|
vec4 ix = Pi.xzxz;
|
||||||
|
vec4 iy = Pi.yyww;
|
||||||
|
vec4 fx = Pf.xzxz;
|
||||||
|
vec4 fy = Pf.yyww;
|
||||||
|
|
||||||
|
vec4 i = permute(permute(ix) + iy);
|
||||||
|
|
||||||
|
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
|
||||||
|
vec4 gy = abs(gx) - 0.5 ;
|
||||||
|
vec4 tx = floor(gx + 0.5);
|
||||||
|
gx = gx - tx;
|
||||||
|
|
||||||
|
vec2 g00 = vec2(gx.x,gy.x);
|
||||||
|
vec2 g10 = vec2(gx.y,gy.y);
|
||||||
|
vec2 g01 = vec2(gx.z,gy.z);
|
||||||
|
vec2 g11 = vec2(gx.w,gy.w);
|
||||||
|
|
||||||
|
vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
|
||||||
|
g00 *= norm.x;
|
||||||
|
g01 *= norm.y;
|
||||||
|
g10 *= norm.z;
|
||||||
|
g11 *= norm.w;
|
||||||
|
|
||||||
|
float n00 = dot(g00, vec2(fx.x, fy.x));
|
||||||
|
float n10 = dot(g10, vec2(fx.y, fy.y));
|
||||||
|
float n01 = dot(g01, vec2(fx.z, fy.z));
|
||||||
|
float n11 = dot(g11, vec2(fx.w, fy.w));
|
||||||
|
|
||||||
|
vec2 fade_xy = fade(Pf.xy);
|
||||||
|
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
|
||||||
|
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
|
||||||
|
return 2.3 * n_xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
vec2 uv = v_texCoord * texSizeInv * 8192.0;
|
||||||
|
uv = floor(uv * 16.0) / 16.0;
|
||||||
|
|
||||||
|
float noise = (pnoise(uv) + 1.0) / 2.0;
|
||||||
|
vec2 uv1 = uv - vec2(uTime, uTime * 0.5 + 0.5) * 0.56;
|
||||||
|
float noise1 = (pnoise(uv1 + vec2(WATER_DISTORTION, -WATER_DISTORTION) * noise) + 1.0) / 2.0;
|
||||||
|
float p = pow(noise1 + 0.02, 20.0);
|
||||||
|
|
||||||
|
vec2 uv2 = uv - vec2(uTime - 1.5, -uTime * 0.5) * 0.24;
|
||||||
|
float noise2 = (pnoise(uv2 + vec2(WATER_DISTORTION, -WATER_DISTORTION) * noise) + 1.0) / 2.0;
|
||||||
|
float p2 = pow(noise2 + 0.02, 20.0);
|
||||||
|
|
||||||
|
vec4 frag = mix(vec4(color.r, color.g, color.b, 1.0) * color.a, vec4(color.r, color.g, color.b, 1.0) * tone.a, noise1) + vec4(p, p, p, 1.0) * tone;
|
||||||
|
frag += mix(vec4(color.r, color.g, color.b, 1.0) * color.a, vec4(color.r, color.g, color.b, 1.0) * tone.a, noise2) + vec4(p2, p2, p2, 1.0) * tone;
|
||||||
|
|
||||||
|
/* Apply opacity */
|
||||||
|
frag.a *= opacity;
|
||||||
|
|
||||||
|
/* Apply modulation */
|
||||||
|
frag *= modulate;
|
||||||
|
|
||||||
|
gl_FragColor = frag;
|
||||||
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
|
|
||||||
uniform mat4 projMat;
|
|
||||||
|
|
||||||
uniform mat4 spriteMat;
|
|
||||||
|
|
||||||
uniform vec2 texSizeInv;
|
|
||||||
|
|
||||||
attribute vec2 position;
|
|
||||||
attribute vec2 texCoord;
|
|
||||||
|
|
||||||
varying vec2 v_texCoord;
|
|
||||||
|
|
||||||
void main(){
|
|
||||||
gl_Position = projMat * spriteMat * vec4(position, 0, 1);
|
|
||||||
v_texCoord = texCoord * texSizeInv;
|
|
||||||
}
|
|
||||||
|
|
@ -55,6 +55,8 @@ struct PlanePrivate{
|
||||||
int ox, oy;
|
int ox, oy;
|
||||||
float zoomX, zoomY;
|
float zoomX, zoomY;
|
||||||
|
|
||||||
|
int shader;
|
||||||
|
|
||||||
Scene::Geometry sceneGeo;
|
Scene::Geometry sceneGeo;
|
||||||
|
|
||||||
bool quadSourceDirty;
|
bool quadSourceDirty;
|
||||||
|
|
@ -75,7 +77,8 @@ struct PlanePrivate{
|
||||||
tone(&tmp.tone),
|
tone(&tmp.tone),
|
||||||
ox(0), oy(0),
|
ox(0), oy(0),
|
||||||
zoomX(1), zoomY(1),
|
zoomX(1), zoomY(1),
|
||||||
quadSourceDirty(false)
|
quadSourceDirty(false),
|
||||||
|
shader(ShaderType::SHADER_plane)
|
||||||
{
|
{
|
||||||
updateSrcRectCon();
|
updateSrcRectCon();
|
||||||
prepareCon = shState->prepareDraw.connect
|
prepareCon = shState->prepareDraw.connect
|
||||||
|
|
@ -176,6 +179,7 @@ DEF_ATTR_SIMPLE(Plane, SrcRect, Rect&, *p->srcRect)
|
||||||
DEF_ATTR_SIMPLE(Plane, Opacity, int, p->opacity)
|
DEF_ATTR_SIMPLE(Plane, Opacity, int, p->opacity)
|
||||||
DEF_ATTR_SIMPLE(Plane, Color, Color&, *p->color)
|
DEF_ATTR_SIMPLE(Plane, Color, Color&, *p->color)
|
||||||
DEF_ATTR_SIMPLE(Plane, Tone, Tone&, *p->tone)
|
DEF_ATTR_SIMPLE(Plane, Tone, Tone&, *p->tone)
|
||||||
|
DEF_ATTR_SIMPLE(Plane, Shader, int, p->shader)
|
||||||
|
|
||||||
Plane::~Plane(){
|
Plane::~Plane(){
|
||||||
dispose();
|
dispose();
|
||||||
|
|
@ -269,7 +273,14 @@ void Plane::draw(){
|
||||||
|
|
||||||
ShaderBase *base;
|
ShaderBase *base;
|
||||||
|
|
||||||
if (p->color->hasEffect() || p->tone->hasEffect() || p->opacity != 255){
|
|
||||||
|
bool renderEffect = p->color->hasEffect() ||
|
||||||
|
p->tone->hasEffect();
|
||||||
|
|
||||||
|
switch (p->shader)
|
||||||
|
{
|
||||||
|
case ShaderType::SHADER_plane:
|
||||||
|
{
|
||||||
PlaneShader &shader = shState->shaders().plane;
|
PlaneShader &shader = shState->shaders().plane;
|
||||||
|
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
@ -280,15 +291,69 @@ void Plane::draw(){
|
||||||
shader.setOpacity(p->opacity.norm);
|
shader.setOpacity(p->opacity.norm);
|
||||||
|
|
||||||
base = &shader;
|
base = &shader;
|
||||||
}else{
|
break;
|
||||||
SimpleShader &shader = shState->shaders().simple;
|
}
|
||||||
|
case ShaderType::SHADER_obscured:
|
||||||
|
{
|
||||||
|
ObscuredShader &shader = shState->shaders().obscured;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
shader.setTranslation(Vec2i());
|
shader.setObscured(shState->graphics().obscuredTex());
|
||||||
|
base = &shader;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ShaderType::SHADER_water:
|
||||||
|
{
|
||||||
|
WaterShader &shader = shState->shaders().water;
|
||||||
|
|
||||||
|
defaultSpriteShaderInit(shader);
|
||||||
|
|
||||||
|
base = &shader;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ShaderType::SHADER_worldMachine:
|
||||||
|
{
|
||||||
|
WMShader &shader = shState->shaders().worldMachine;
|
||||||
|
|
||||||
|
defaultSpriteShaderInit(shader);
|
||||||
|
|
||||||
|
base = &shader;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (renderEffect){
|
||||||
|
SpriteShader &shader = shState->shaders().sprite;
|
||||||
|
|
||||||
|
defaultSpriteShaderInit(shader);
|
||||||
|
|
||||||
base = &shader;
|
base = &shader;
|
||||||
}
|
}
|
||||||
|
else if (p->opacity != 255){
|
||||||
|
AlphaSpriteShader &shader = shState->shaders().alphaSprite;
|
||||||
|
shader.bind();
|
||||||
|
|
||||||
|
shader.setAlpha(p->opacity.norm);
|
||||||
|
shader.applyViewportProj();
|
||||||
|
base = &shader;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SimpleSpriteShader &shader = shState->shaders().simpleSprite;
|
||||||
|
shader.bind();
|
||||||
|
|
||||||
|
shader.applyViewportProj();
|
||||||
|
base = &shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boost::chrono::high_resolution_clock::time_point currentTime = boost::chrono::high_resolution_clock::now();
|
||||||
|
boost::chrono::duration<float> elapsed = currentTime - startTime;
|
||||||
|
base->setTime(elapsed.count());
|
||||||
|
base->setTranslation(Vec2i());
|
||||||
|
|
||||||
glState.blendMode.pushSet(p->blendType);
|
glState.blendMode.pushSet(p->blendType);
|
||||||
|
|
||||||
|
|
@ -318,3 +383,16 @@ void Plane::releaseResources(){
|
||||||
|
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Plane::defaultSpriteShaderInit(SpriteShaderBase &shader){
|
||||||
|
shader.bind();
|
||||||
|
|
||||||
|
shader.applyViewportProj();
|
||||||
|
|
||||||
|
shader.setTone(p->tone->norm);
|
||||||
|
shader.setOpacity(p->opacity.norm);
|
||||||
|
shader.setBushOpacity(1.0f);
|
||||||
|
|
||||||
|
shader.setColor(p->color->norm);
|
||||||
|
shader.setModulate(Vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
#include "disposable.h"
|
#include "disposable.h"
|
||||||
#include "viewport.h"
|
#include "viewport.h"
|
||||||
|
#include "shader.h"
|
||||||
|
|
||||||
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
class Bitmap;
|
class Bitmap;
|
||||||
struct Color;
|
struct Color;
|
||||||
|
|
@ -33,6 +36,8 @@ struct PlanePrivate;
|
||||||
|
|
||||||
class Plane : public ViewportElement, public Disposable{
|
class Plane : public ViewportElement, public Disposable{
|
||||||
public:
|
public:
|
||||||
|
boost::chrono::high_resolution_clock::time_point startTime = boost::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
Plane(Viewport *viewport = 0);
|
Plane(Viewport *viewport = 0);
|
||||||
~Plane();
|
~Plane();
|
||||||
|
|
||||||
|
|
@ -46,6 +51,7 @@ public:
|
||||||
DECL_ATTR( BlendType, int )
|
DECL_ATTR( BlendType, int )
|
||||||
DECL_ATTR( Color, Color& )
|
DECL_ATTR( Color, Color& )
|
||||||
DECL_ATTR( Tone, Tone& )
|
DECL_ATTR( Tone, Tone& )
|
||||||
|
DECL_ATTR( Shader, int )
|
||||||
|
|
||||||
void initDynAttribs();
|
void initDynAttribs();
|
||||||
|
|
||||||
|
|
@ -54,6 +60,7 @@ private:
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void onGeometryChange(const Scene::Geometry &);
|
void onGeometryChange(const Scene::Geometry &);
|
||||||
|
void defaultSpriteShaderInit(SpriteShaderBase &);
|
||||||
|
|
||||||
void releaseResources();
|
void releaseResources();
|
||||||
const char *klassName() const { return "plane"; }
|
const char *klassName() const { return "plane"; }
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
#include "common.h.xxd"
|
#include "common.h.xxd"
|
||||||
#include "sprite.frag.xxd"
|
#include "sprite.frag.xxd"
|
||||||
#include "worldMachine.frag.xxd"
|
#include "worldMachine.frag.xxd"
|
||||||
|
#include "water.frag.xxd"
|
||||||
#include "hue.frag.xxd"
|
#include "hue.frag.xxd"
|
||||||
#include "trans.frag.xxd"
|
#include "trans.frag.xxd"
|
||||||
#include "transSimple.frag.xxd"
|
#include "transSimple.frag.xxd"
|
||||||
|
|
@ -47,7 +48,6 @@
|
||||||
#include "simple.vert.xxd"
|
#include "simple.vert.xxd"
|
||||||
#include "simpleColor.vert.xxd"
|
#include "simpleColor.vert.xxd"
|
||||||
#include "sprite.vert.xxd"
|
#include "sprite.vert.xxd"
|
||||||
#include "worldMachine.vert.xxd"
|
|
||||||
#include "tilemap.vert.xxd"
|
#include "tilemap.vert.xxd"
|
||||||
#include "blur.frag.xxd"
|
#include "blur.frag.xxd"
|
||||||
#include "simpleMatrix.vert.xxd"
|
#include "simpleMatrix.vert.xxd"
|
||||||
|
|
@ -378,9 +378,7 @@ void SimpleTransShader::setProg(float value){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SpriteShader::SpriteShader(){
|
void SpriteShaderBase::SpriteShaderInit(){
|
||||||
INIT_SHADER(sprite, sprite, SpriteShader);
|
|
||||||
|
|
||||||
ShaderBase::init();
|
ShaderBase::init();
|
||||||
|
|
||||||
GET_U(spriteMat);
|
GET_U(spriteMat);
|
||||||
|
|
@ -392,38 +390,50 @@ SpriteShader::SpriteShader(){
|
||||||
GET_U(bushOpacity);
|
GET_U(bushOpacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setSpriteMat(const float value[16]){
|
void SpriteShaderBase::setSpriteMat(const float value[16]){
|
||||||
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
|
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setTone(const Vec4 &tone){
|
void SpriteShaderBase::setTone(const Vec4 &tone){
|
||||||
setVec4Uniform(u_tone, tone);
|
setVec4Uniform(u_tone, tone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setColor(const Vec4 &color){
|
void SpriteShaderBase::setColor(const Vec4 &color){
|
||||||
setVec4Uniform(u_color, color);
|
setVec4Uniform(u_color, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setModulate(const Vec4 &color){
|
void SpriteShaderBase::setModulate(const Vec4 &color){
|
||||||
setVec4Uniform(u_modulate, color);
|
setVec4Uniform(u_modulate, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setOpacity(float value){
|
void SpriteShaderBase::setOpacity(float value){
|
||||||
gl.Uniform1f(u_opacity, value);
|
gl.Uniform1f(u_opacity, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setBushDepth(float value){
|
void SpriteShaderBase::setBushDepth(float value){
|
||||||
gl.Uniform1f(u_bushDepth, value);
|
gl.Uniform1f(u_bushDepth, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpriteShader::setBushOpacity(float value){
|
void SpriteShaderBase::setBushOpacity(float value){
|
||||||
gl.Uniform1f(u_bushOpacity, value);
|
gl.Uniform1f(u_bushOpacity, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpriteShader::SpriteShader(){
|
||||||
|
INIT_SHADER(sprite, sprite, SpriteShader);
|
||||||
|
SpriteShaderBase::SpriteShaderInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WMShader::WMShader(){
|
WMShader::WMShader(){
|
||||||
INIT_SHADER(worldMachine, worldMachine, WMShader);
|
INIT_SHADER(sprite, worldMachine, WMShader);
|
||||||
SpriteShader::init();
|
SpriteShaderBase::SpriteShaderInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WaterShader::WaterShader(){
|
||||||
|
INIT_SHADER(simple, water, WaterShader);
|
||||||
|
SpriteShaderBase::SpriteShaderInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
17
src/shader.h
17
src/shader.h
|
|
@ -160,9 +160,9 @@ private:
|
||||||
GLint u_currentScene, u_frozenScene, u_prog;
|
GLint u_currentScene, u_frozenScene, u_prog;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpriteShader : public ShaderBase{
|
class SpriteShaderBase : public ShaderBase{
|
||||||
public:
|
public:
|
||||||
SpriteShader();
|
void SpriteShaderInit();
|
||||||
|
|
||||||
void setSpriteMat(const float value[16]);
|
void setSpriteMat(const float value[16]);
|
||||||
void setTone(const Vec4 &value);
|
void setTone(const Vec4 &value);
|
||||||
|
|
@ -176,11 +176,21 @@ private:
|
||||||
GLint u_spriteMat, u_tone, u_opacity, u_color, u_modulate, u_bushDepth, u_bushOpacity;
|
GLint u_spriteMat, u_tone, u_opacity, u_color, u_modulate, u_bushDepth, u_bushOpacity;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WMShader : public SpriteShader{
|
class SpriteShader : public SpriteShaderBase{
|
||||||
|
public:
|
||||||
|
SpriteShader();
|
||||||
|
};
|
||||||
|
|
||||||
|
class WMShader : public SpriteShaderBase{
|
||||||
public:
|
public:
|
||||||
WMShader();
|
WMShader();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WaterShader : public SpriteShaderBase{
|
||||||
|
public:
|
||||||
|
WaterShader();
|
||||||
|
};
|
||||||
|
|
||||||
class PlaneShader : public ShaderBase{
|
class PlaneShader : public ShaderBase{
|
||||||
public:
|
public:
|
||||||
PlaneShader();
|
PlaneShader();
|
||||||
|
|
@ -308,6 +318,7 @@ private:
|
||||||
X(alphaSprite, AlphaSpriteShader, AlphaSprite) \
|
X(alphaSprite, AlphaSpriteShader, AlphaSprite) \
|
||||||
X(sprite, SpriteShader, Sprite) \
|
X(sprite, SpriteShader, Sprite) \
|
||||||
X(worldMachine, WMShader, WorldMachine) \
|
X(worldMachine, WMShader, WorldMachine) \
|
||||||
|
X(water, WaterShader, Water) \
|
||||||
X(plane, PlaneShader, Plane) \
|
X(plane, PlaneShader, Plane) \
|
||||||
X(gray, GrayShader, Gray) \
|
X(gray, GrayShader, Gray) \
|
||||||
X(tilemap, TilemapShader, TileMap) \
|
X(tilemap, TilemapShader, TileMap) \
|
||||||
|
|
|
||||||
|
|
@ -505,7 +505,7 @@ void Sprite::draw(){
|
||||||
flashing ||
|
flashing ||
|
||||||
p->bushDepth != 0;
|
p->bushDepth != 0;
|
||||||
|
|
||||||
if (p->obscured){
|
if (p->obscured || p->shader == ShaderType::SHADER_obscured){
|
||||||
ObscuredShader &shader = shState->shaders().obscured;
|
ObscuredShader &shader = shState->shaders().obscured;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
shader.applyViewportProj();
|
shader.applyViewportProj();
|
||||||
|
|
@ -513,27 +513,37 @@ void Sprite::draw(){
|
||||||
base = &shader;
|
base = &shader;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
switch (p->shader){
|
switch (p->shader)
|
||||||
|
{
|
||||||
|
case ShaderType::SHADER_plane:
|
||||||
|
{
|
||||||
|
PlaneShader &shader = shState->shaders().plane;
|
||||||
|
|
||||||
|
shader.bind();
|
||||||
|
shader.applyViewportProj();
|
||||||
|
shader.setTone(p->tone->norm);
|
||||||
|
shader.setColor(p->color->norm);
|
||||||
|
shader.setFlash(Vec4());
|
||||||
|
shader.setOpacity(p->opacity.norm);
|
||||||
|
|
||||||
|
base = &shader;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ShaderType::SHADER_water:
|
||||||
|
{
|
||||||
|
WaterShader &shader = shState->shaders().water;
|
||||||
|
|
||||||
|
defaultSpriteShaderInit(shader);
|
||||||
|
|
||||||
|
base = &shader;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ShaderType::SHADER_worldMachine:
|
case ShaderType::SHADER_worldMachine:
|
||||||
{
|
{
|
||||||
WMShader &shader = shState->shaders().worldMachine;
|
WMShader &shader = shState->shaders().worldMachine;
|
||||||
|
|
||||||
shader.bind();
|
defaultSpriteShaderInit(shader);
|
||||||
shader.applyViewportProj();
|
|
||||||
shader.setSpriteMat(p->trans.getMatrix());
|
|
||||||
|
|
||||||
shader.setTone(p->tone->norm);
|
|
||||||
shader.setOpacity(p->opacity.norm);
|
|
||||||
shader.setBushDepth(p->efBushDepth);
|
|
||||||
shader.setBushOpacity(p->bushOpacity.norm);
|
|
||||||
|
|
||||||
/* When both flashing and effective color are set,
|
|
||||||
* the one with higher alpha will be blended */
|
|
||||||
const Vec4 *blend = (flashing && flashColor.w > p->color->norm.w) ?
|
|
||||||
&flashColor : &p->color->norm;
|
|
||||||
|
|
||||||
shader.setColor(*blend);
|
|
||||||
shader.setModulate(p->modulate->norm);
|
|
||||||
|
|
||||||
base = &shader;
|
base = &shader;
|
||||||
|
|
||||||
|
|
@ -544,22 +554,7 @@ void Sprite::draw(){
|
||||||
if (renderEffect){
|
if (renderEffect){
|
||||||
SpriteShader &shader = shState->shaders().sprite;
|
SpriteShader &shader = shState->shaders().sprite;
|
||||||
|
|
||||||
shader.bind();
|
defaultSpriteShaderInit(shader);
|
||||||
shader.applyViewportProj();
|
|
||||||
shader.setSpriteMat(p->trans.getMatrix());
|
|
||||||
|
|
||||||
shader.setTone(p->tone->norm);
|
|
||||||
shader.setOpacity(p->opacity.norm);
|
|
||||||
shader.setBushDepth(p->efBushDepth);
|
|
||||||
shader.setBushOpacity(p->bushOpacity.norm);
|
|
||||||
|
|
||||||
/* When both flashing and effective color are set,
|
|
||||||
* the one with higher alpha will be blended */
|
|
||||||
const Vec4 *blend = (flashing && flashColor.w > p->color->norm.w) ?
|
|
||||||
&flashColor : &p->color->norm;
|
|
||||||
|
|
||||||
shader.setColor(*blend);
|
|
||||||
shader.setModulate(p->modulate->norm);
|
|
||||||
|
|
||||||
base = &shader;
|
base = &shader;
|
||||||
}
|
}
|
||||||
|
|
@ -615,3 +610,22 @@ void Sprite::releaseResources(){
|
||||||
|
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sprite::defaultSpriteShaderInit(SpriteShaderBase &shader){
|
||||||
|
shader.bind();
|
||||||
|
shader.applyViewportProj();
|
||||||
|
shader.setSpriteMat(p->trans.getMatrix());
|
||||||
|
|
||||||
|
shader.setTone(p->tone->norm);
|
||||||
|
shader.setOpacity(p->opacity.norm);
|
||||||
|
shader.setBushDepth(p->efBushDepth);
|
||||||
|
shader.setBushOpacity(p->bushOpacity.norm);
|
||||||
|
|
||||||
|
/* When both flashing and effective color are set,
|
||||||
|
* the one with higher alpha will be blended */
|
||||||
|
const Vec4 *blend = (flashing && flashColor.w > p->color->norm.w) ?
|
||||||
|
&flashColor : &p->color->norm;
|
||||||
|
|
||||||
|
shader.setColor(*blend);
|
||||||
|
shader.setModulate(p->modulate->norm);
|
||||||
|
}
|
||||||
|
|
@ -73,7 +73,6 @@ public:
|
||||||
DECL_ATTR( WavePhase, float )
|
DECL_ATTR( WavePhase, float )
|
||||||
DECL_ATTR( Obscured, bool )
|
DECL_ATTR( Obscured, bool )
|
||||||
DECL_ATTR( Shader, int )
|
DECL_ATTR( Shader, int )
|
||||||
DECL_ATTR( startTime, boost::chrono::high_resolution_clock::time_point)
|
|
||||||
|
|
||||||
void initDynAttribs();
|
void initDynAttribs();
|
||||||
|
|
||||||
|
|
@ -82,6 +81,7 @@ private:
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void onGeometryChange(const Scene::Geometry &);
|
void onGeometryChange(const Scene::Geometry &);
|
||||||
|
void defaultSpriteShaderInit(SpriteShaderBase &);
|
||||||
|
|
||||||
void releaseResources();
|
void releaseResources();
|
||||||
const char *klassName() const { return "sprite"; }
|
const char *klassName() const { return "sprite"; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue