mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
shader using
This commit is contained in:
parent
5376a7e098
commit
50edfe0e12
10 changed files with 160 additions and 121 deletions
|
|
@ -303,6 +303,7 @@ set(BINDING_SOURCE
|
|||
binding-mri/chroma-binding.cpp
|
||||
binding-mri/niko-binding.cpp
|
||||
binding-mri/time-binding.cpp
|
||||
binding-mri/shader-binging.cpp
|
||||
)
|
||||
|
||||
source_group("Binding Source" FILES ${BINDING_SOURCE} ${BINDING_HEADERS})
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ void oneshotBindingInit();
|
|||
void SunshineBindingInit();
|
||||
void steamBindingInit();
|
||||
void chromaBindingInit();
|
||||
void shaderBindingInit();
|
||||
|
||||
RB_METHOD(mriPrint);
|
||||
RB_METHOD(mriP);
|
||||
|
|
@ -119,6 +120,7 @@ static void mriBindingInit(){
|
|||
SunshineBindingInit();
|
||||
steamBindingInit();
|
||||
chromaBindingInit();
|
||||
shaderBindingInit();
|
||||
|
||||
_rb_define_module_function(rb_mKernel, "rgss_main", mriRgssMain);
|
||||
_rb_define_module_function(rb_mKernel, "rgss_stop", mriRgssStop);
|
||||
|
|
|
|||
19
binding-mri/shader-binging.cpp
Normal file
19
binding-mri/shader-binging.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <ruby.h>
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
#include "disposable-binding.h"
|
||||
#include "binding-util.h"
|
||||
#include "binding-types.h"
|
||||
|
||||
VALUE rb_mShader;
|
||||
|
||||
void shaderBindingInit(){
|
||||
printf("[shaderBindingInit] Initializing Shaders binding\n");
|
||||
rb_mShader = rb_define_module("Shader");
|
||||
|
||||
#define DEFINE_RUBY_CONST(name, type, rb) \
|
||||
rb_define_const(rb_mShader, #rb, INT2NUM(ShaderType::SHADER_##name));
|
||||
SHADER_LIST(DEFINE_RUBY_CONST)
|
||||
#undef DEFINE_RUBY_CONST
|
||||
}
|
||||
|
|
@ -63,6 +63,7 @@ DEF_PROP_I(Sprite, BlendType)
|
|||
DEF_PROP_I(Sprite, WaveAmp)
|
||||
DEF_PROP_I(Sprite, WaveLength)
|
||||
DEF_PROP_I(Sprite, WaveSpeed)
|
||||
DEF_PROP_I(Sprite, Shader)
|
||||
|
||||
DEF_PROP_F(Sprite, ZoomX)
|
||||
DEF_PROP_F(Sprite, ZoomY)
|
||||
|
|
@ -71,7 +72,6 @@ DEF_PROP_F(Sprite, WavePhase)
|
|||
|
||||
DEF_PROP_B(Sprite, Mirror)
|
||||
DEF_PROP_B(Sprite, Obscured)
|
||||
DEF_PROP_B(Sprite, WorldMachine)
|
||||
|
||||
RB_METHOD(spriteWidth){
|
||||
RB_UNUSED_PARAM;
|
||||
|
|
@ -123,7 +123,7 @@ void spriteBindingInit(){
|
|||
INIT_PROP_BIND( Sprite, Tone, "tone" );
|
||||
INIT_PROP_BIND( Sprite, Modulate, "modulate" );
|
||||
INIT_PROP_BIND( Sprite, Obscured, "obscured" );
|
||||
INIT_PROP_BIND( Sprite, WorldMachine, "world_machine" );
|
||||
INIT_PROP_BIND( Sprite, Shader, "shader" );
|
||||
|
||||
_rb_define_method(klass, "width", spriteWidth);
|
||||
_rb_define_method(klass, "height", spriteHeight);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class FastTravel
|
|||
@niko_icon.zoom_x = @niko_icon.zoom_y = @scale_multiplier
|
||||
@niko_icon.z = 10
|
||||
@niko_icon.opacity = 0
|
||||
@niko_icon.world_machine = true
|
||||
@niko_icon.shader = Shader::WorldMachine
|
||||
|
||||
@niko_pos_x = 0.0
|
||||
@niko_pos_y = 0.0
|
||||
|
|
@ -70,8 +70,8 @@ class FastTravel
|
|||
@arrow_top.opacity = @arrow_bottom.opacity =
|
||||
@arrow_left.opacity = @arrow_right.opacity = 0
|
||||
|
||||
@arrow_top.world_machine = @arrow_bottom.world_machine =
|
||||
@arrow_left.world_machine = @arrow_right.world_machine = true
|
||||
@arrow_top.shader = @arrow_bottom.shader =
|
||||
@arrow_left.shader = @arrow_right.shader = Shader::WorldMachine
|
||||
|
||||
@arrow_top.z = @arrow_bottom.z =
|
||||
@arrow_left.z = @arrow_right.z = 11
|
||||
|
|
@ -195,7 +195,7 @@ class FastTravel
|
|||
spr.x = Graphics.width / 2 + zone.locations[item].x * @scale_multiplier
|
||||
spr.y = Graphics.height / 2 + zone.locations[item].y * @scale_multiplier
|
||||
spr.opacity = 0
|
||||
spr.world_machine = true
|
||||
spr.shader = Shader::WorldMachine
|
||||
@data_locations[item] = spr
|
||||
set_color(item)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ class Sprite_Character
|
|||
@text_sprite.bitmap.font.size = 12
|
||||
@character = character
|
||||
|
||||
#for debug
|
||||
@last_char_name
|
||||
update
|
||||
end
|
||||
#--------------------------------------------------------------------------
|
||||
|
|
@ -37,7 +35,7 @@ class Sprite_Character
|
|||
def update
|
||||
# Choose the appropriate light sprite
|
||||
@light_sprite.viewport = ($game_screen.tone.blank?) ? @viewport : @light_viewport
|
||||
@light_sprite.world_machine = @sprite.world_machine = @character.character_name.start_with?("en") || (@character.character_name.start_with?("niko") && $game_switches[160])
|
||||
@light_sprite.shader = @sprite.shader = @character.character_name.start_with?("en") || (@character.character_name.start_with?("niko") && $game_switches[160]) ? Shader::WorldMachine : Shader::Sprite
|
||||
if @last_char_name != character.character_name && Settings[:debug]
|
||||
@text_sprite.bitmap.clear
|
||||
@text_sprite.bitmap.draw_text(0, 0, 256, 12, "#{@character.character_name}")
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ void ShaderBase::GLProjMat::apply(const Vec2i &value) {
|
|||
void ShaderBase::init(){
|
||||
GET_U(texSizeInv);
|
||||
GET_U(translation);
|
||||
GET_U(uTime);
|
||||
|
||||
projMat.u_mat = gl.GetUniformLocation(program, "projMat");
|
||||
}
|
||||
|
|
@ -248,6 +249,10 @@ void ShaderBase::setTranslation(const Vec2i &value){
|
|||
gl.Uniform2f(u_translation, value.x, value.y);
|
||||
}
|
||||
|
||||
void ShaderBase::setTime(float value){
|
||||
gl.Uniform1f(u_uTime, value);
|
||||
}
|
||||
|
||||
|
||||
FlatColorShader::FlatColorShader(){
|
||||
INIT_SHADER(minimal, flatColor, FlatColorShader);
|
||||
|
|
@ -422,19 +427,8 @@ void SpriteShader::setBushOpacity(float value){
|
|||
WMShader::WMShader(){
|
||||
INIT_SHADER(worldMachine, worldMachine, WMShader);
|
||||
SpriteShader::init();
|
||||
|
||||
GET_U(uTime);
|
||||
//GET_U(resolution);
|
||||
}
|
||||
|
||||
void WMShader::setTime(float value){
|
||||
gl.Uniform1f(u_uTime, value);
|
||||
}
|
||||
/*
|
||||
void WMShader::setResolution(float x, float y){
|
||||
gl.Uniform2f(u_resolution, x, y);
|
||||
}*/
|
||||
|
||||
|
||||
PlaneShader::PlaneShader(){
|
||||
INIT_SHADER(simple, plane, PlaneShader);
|
||||
|
|
|
|||
60
src/shader.h
60
src/shader.h
|
|
@ -76,11 +76,15 @@ public:
|
|||
|
||||
void setTexSize(const Vec2i &value);
|
||||
void setTranslation(const Vec2i &value);
|
||||
void setTime(float value);
|
||||
|
||||
protected:
|
||||
void init();
|
||||
|
||||
GLint u_texSizeInv, u_translation;
|
||||
|
||||
private:
|
||||
GLint u_uTime;
|
||||
};
|
||||
|
||||
class FlatColorShader : public ShaderBase{
|
||||
|
|
@ -179,11 +183,6 @@ private:
|
|||
class WMShader : public SpriteShader{
|
||||
public:
|
||||
WMShader();
|
||||
|
||||
void setTime(float value);
|
||||
//void setResolution(float x, float y);
|
||||
private:
|
||||
GLint u_uTime/*, u_resolution*/;
|
||||
};
|
||||
|
||||
class PlaneShader : public ShaderBase{
|
||||
|
|
@ -302,26 +301,39 @@ private:
|
|||
};
|
||||
|
||||
/* Global object containing all available shaders */
|
||||
|
||||
// Name C++ Class In ruby const name
|
||||
#define SHADER_LIST(X) \
|
||||
X(flatColor, FlatColorShader, Flat) \
|
||||
X(simple, SimpleShader, Simple) \
|
||||
X(simpleColor, SimpleColorShader, SimpleColor) \
|
||||
X(simpleAlpha, SimpleAlphaShader, SimpleAlpha) \
|
||||
X(simpleSprite, SimpleSpriteShader, SimpleSprite) \
|
||||
X(alphaSprite, AlphaSpriteShader, AlphaSprite) \
|
||||
X(sprite, SpriteShader, Sprite) \
|
||||
X(worldMachine, WMShader, WorldMachine) \
|
||||
X(plane, PlaneShader, Plane) \
|
||||
X(gray, GrayShader, Gray) \
|
||||
X(tilemap, TilemapShader, TileMap) \
|
||||
X(flashMap, FlashMapShader, Flash) \
|
||||
X(trans, TransShader, Trans) \
|
||||
X(simpleTrans, SimpleTransShader, SimpleTrans) \
|
||||
X(hue, HueShader, Hue) \
|
||||
X(blt, BltShader, Blt) \
|
||||
X(simpleMatrix, SimpleMatrixShader, SimpleMatrix) \
|
||||
X(blur, BlurShader, Blur) \
|
||||
X(obscured, ObscuredShader, Obscured)
|
||||
|
||||
struct ShaderSet{
|
||||
FlatColorShader flatColor;
|
||||
SimpleShader simple;
|
||||
SimpleColorShader simpleColor;
|
||||
SimpleAlphaShader simpleAlpha;
|
||||
SimpleSpriteShader simpleSprite;
|
||||
AlphaSpriteShader alphaSprite;
|
||||
SpriteShader sprite;
|
||||
WMShader worldMachine;
|
||||
PlaneShader plane;
|
||||
GrayShader gray;
|
||||
TilemapShader tilemap;
|
||||
FlashMapShader flashMap;
|
||||
TransShader trans;
|
||||
SimpleTransShader simpleTrans;
|
||||
HueShader hue;
|
||||
BltShader blt;
|
||||
SimpleMatrixShader simpleMatrix;
|
||||
BlurShader blur;
|
||||
ObscuredShader obscured;
|
||||
#define DECLARE_SHADER(name, type, rb) type name;
|
||||
SHADER_LIST(DECLARE_SHADER)
|
||||
#undef DECLARE_SHADER
|
||||
};
|
||||
enum ShaderType{
|
||||
#define DECLARE_ENUM(name, type, rb) SHADER_##name,
|
||||
SHADER_LIST(DECLARE_ENUM)
|
||||
#undef DECLARE_ENUM
|
||||
SHADER_COUNT
|
||||
};
|
||||
|
||||
#endif // SHADER_H
|
||||
|
|
|
|||
162
src/sprite.cpp
162
src/sprite.cpp
|
|
@ -44,7 +44,6 @@
|
|||
#include <boost/chrono.hpp>
|
||||
|
||||
struct SpritePrivate{
|
||||
boost::chrono::high_resolution_clock::time_point startTime = boost::chrono::high_resolution_clock::now();
|
||||
|
||||
Bitmap *bitmap;
|
||||
|
||||
|
|
@ -69,11 +68,12 @@ struct SpritePrivate{
|
|||
bool isVisible;
|
||||
|
||||
bool obscured;
|
||||
bool worldMachine;
|
||||
|
||||
Color *color;
|
||||
Tone *tone;
|
||||
Color *modulate;
|
||||
|
||||
int shader;
|
||||
|
||||
struct{
|
||||
int amp;
|
||||
|
|
@ -103,10 +103,10 @@ struct SpritePrivate{
|
|||
blendType(BlendNormal),
|
||||
isVisible(false),
|
||||
obscured(false),
|
||||
worldMachine(false),
|
||||
color(&tmp.color),
|
||||
tone(&tmp.tone),
|
||||
modulate(&tmp.modulate)
|
||||
modulate(&tmp.modulate),
|
||||
shader(ShaderType::SHADER_sprite)
|
||||
|
||||
{
|
||||
sceneRect.x = sceneRect.y = 0;
|
||||
|
|
@ -315,14 +315,14 @@ DEF_ATTR_RD_SIMPLE(Sprite, WaveLength, int, p->wave.length)
|
|||
DEF_ATTR_RD_SIMPLE(Sprite, WaveSpeed, int, p->wave.speed)
|
||||
DEF_ATTR_RD_SIMPLE(Sprite, WavePhase, float, p->wave.phase)
|
||||
|
||||
DEF_ATTR_SIMPLE(Sprite, BushOpacity, int, p->bushOpacity)
|
||||
DEF_ATTR_SIMPLE(Sprite, Opacity, int, p->opacity)
|
||||
DEF_ATTR_SIMPLE(Sprite, SrcRect, Rect&, *p->srcRect)
|
||||
DEF_ATTR_SIMPLE(Sprite, Color, Color&, *p->color)
|
||||
DEF_ATTR_SIMPLE(Sprite, Tone, Tone&, *p->tone)
|
||||
DEF_ATTR_SIMPLE(Sprite, Modulate, Color&, *p->modulate)
|
||||
DEF_ATTR_SIMPLE(Sprite, Obscured, bool, p->obscured)
|
||||
DEF_ATTR_SIMPLE(Sprite, WorldMachine, bool, p->worldMachine)
|
||||
DEF_ATTR_SIMPLE(Sprite, BushOpacity, int, p->bushOpacity)
|
||||
DEF_ATTR_SIMPLE(Sprite, Opacity, int, p->opacity)
|
||||
DEF_ATTR_SIMPLE(Sprite, SrcRect, Rect&, *p->srcRect)
|
||||
DEF_ATTR_SIMPLE(Sprite, Color, Color&, *p->color)
|
||||
DEF_ATTR_SIMPLE(Sprite, Tone, Tone&, *p->tone)
|
||||
DEF_ATTR_SIMPLE(Sprite, Modulate, Color&, *p->modulate)
|
||||
DEF_ATTR_SIMPLE(Sprite, Obscured, bool, p->obscured)
|
||||
DEF_ATTR_SIMPLE(Sprite, Shader, int, p->shader)
|
||||
|
||||
void Sprite::setBitmap(Bitmap *bitmap){
|
||||
guardDisposed();
|
||||
|
|
@ -512,73 +512,83 @@ void Sprite::draw(){
|
|||
shader.setObscured(shState->graphics().obscuredTex());
|
||||
base = &shader;
|
||||
}
|
||||
else if (p->worldMachine){
|
||||
WMShader &shader = shState->shaders().worldMachine;
|
||||
|
||||
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);
|
||||
//shader.setResolution(p->bitmap->width(), p->bitmap->height());
|
||||
|
||||
boost::chrono::high_resolution_clock::time_point currentTime = boost::chrono::high_resolution_clock::now();
|
||||
|
||||
boost::chrono::duration<float> elapsed = currentTime - p->startTime;
|
||||
shader.setTime(elapsed.count());
|
||||
|
||||
base = &shader;
|
||||
}
|
||||
else if (renderEffect){
|
||||
SpriteShader &shader = shState->shaders().sprite;
|
||||
|
||||
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);
|
||||
|
||||
base = &shader;
|
||||
}
|
||||
else if (p->opacity != 255){
|
||||
AlphaSpriteShader &shader = shState->shaders().alphaSprite;
|
||||
shader.bind();
|
||||
|
||||
shader.setSpriteMat(p->trans.getMatrix());
|
||||
shader.setAlpha(p->opacity.norm);
|
||||
shader.applyViewportProj();
|
||||
base = &shader;
|
||||
}
|
||||
else{
|
||||
SimpleSpriteShader &shader = shState->shaders().simpleSprite;
|
||||
shader.bind();
|
||||
switch (p->shader)
|
||||
{
|
||||
case ShaderType::SHADER_worldMachine:
|
||||
{
|
||||
WMShader &shader = shState->shaders().worldMachine;
|
||||
|
||||
shader.setSpriteMat(p->trans.getMatrix());
|
||||
shader.applyViewportProj();
|
||||
base = &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);
|
||||
|
||||
base = &shader;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (renderEffect){
|
||||
SpriteShader &shader = shState->shaders().sprite;
|
||||
|
||||
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);
|
||||
|
||||
base = &shader;
|
||||
}
|
||||
else if (p->opacity != 255){
|
||||
AlphaSpriteShader &shader = shState->shaders().alphaSprite;
|
||||
shader.bind();
|
||||
|
||||
shader.setSpriteMat(p->trans.getMatrix());
|
||||
shader.setAlpha(p->opacity.norm);
|
||||
shader.applyViewportProj();
|
||||
base = &shader;
|
||||
}
|
||||
else{
|
||||
SimpleSpriteShader &shader = shState->shaders().simpleSprite;
|
||||
shader.bind();
|
||||
|
||||
shader.setSpriteMat(p->trans.getMatrix());
|
||||
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());
|
||||
|
||||
glState.blendMode.pushSet(p->blendType);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include "disposable.h"
|
||||
#include "viewport.h"
|
||||
#include "util.h"
|
||||
#include "shader.h"
|
||||
|
||||
#include <boost/chrono.hpp>
|
||||
|
||||
|
|
@ -39,6 +40,8 @@ struct SpritePrivate;
|
|||
|
||||
class Sprite : public ViewportElement, public Flashable, public Disposable{
|
||||
public:
|
||||
boost::chrono::high_resolution_clock::time_point startTime = boost::chrono::high_resolution_clock::now();
|
||||
|
||||
Sprite(Viewport *viewport = 0);
|
||||
~Sprite();
|
||||
|
||||
|
|
@ -69,7 +72,7 @@ public:
|
|||
DECL_ATTR( WaveSpeed, int )
|
||||
DECL_ATTR( WavePhase, float )
|
||||
DECL_ATTR( Obscured, bool )
|
||||
DECL_ATTR( WorldMachine, bool )
|
||||
DECL_ATTR( Shader, int )
|
||||
DECL_ATTR( startTime, boost::chrono::high_resolution_clock::time_point)
|
||||
|
||||
void initDynAttribs();
|
||||
|
|
|
|||
Loading…
Reference in a new issue