Skip to content

Commit

Permalink
opaque,translucent renderPools;
Browse files Browse the repository at this point in the history
  • Loading branch information
turesnake committed Aug 19, 2019
1 parent dbd99c2 commit 412f39d
Show file tree
Hide file tree
Showing 40 changed files with 341 additions and 186 deletions.
2 changes: 1 addition & 1 deletion jsons/animFrameSets.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"name": "oneEyeBoy",
"pngs": [
{
"path": "/oneEyeBoy/oneEyeBoy.P.png",
"path": "/oneEyeBoy/oneEyeBoy2.P.png",
"frameNum.col": 1,
"frameNum.row": 1,
"totalFrameNum": 1,
Expand Down
37 changes: 37 additions & 0 deletions shaders/playerGoIndication.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#version 330 core

//-- 片段着色器的 主输出:颜色
out vec4 FragColor;

//-- 从 顶点着色器 传来的 数据(名称和类型 都要相同)
in vec2 TexCoord; //-- 每个pix 在 tecture 上的坐标 [0.0, 1.0] [left_bottom]

//-- sampler 系列 是 采样器数据类型。
//-- 现在,我们创建了 1个 纹理采样器
uniform sampler2D texture1;


void main()
{
//-- 取得 texture 颜色 --
vec4 texColor = texture(texture1, TexCoord);

//-- 半透明度小于 0.05 的像素直接不渲染 --
//-- 通过这个方法来处理大部分 “要么实心要么全透明” 的图元
if( texColor.a < 0.05 ){
discard;
}

vec3 addColor = vec3( 0.87, 0.42, 0.42 );

texColor.rgb = texColor.rgb * addColor;


//FragColor = vec4( 0.2, 0.6, 0.9, 1.0 );
//FragColor = vec4( texColor.rgb, 0.2 ); //- 半透明
//FragColor = vec4( texColor.rgb * 0.5, 1.0);
FragColor = vec4( 0.87, 0.42, 0.42, 0.8); //- 实心颜色
//FragColor = vec4( texColor.rgb, 0.9 );


}
26 changes: 26 additions & 0 deletions shaders/playerGoIndication.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 330 core

// 由用户程序中 glVertexAttribPointer() 配置 (VAOVBO 模块中) --
layout (location = 0) in vec3 aPos; //-- 每个pix 在 图元上的坐标 [-1.0,1.0]
layout (location = 1) in vec2 aTexCoord; //-- 每个pix 在 tecture 上的坐标 [0.0,1.0]


//-- 输出给 fs 的颜色数据
out vec2 TexCoord; //-- 每个pix 在 tecture 上的坐标 [-1.0,1.0]

//uniform mat4 transform; //-- 矩阵 变换 变量。

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;


//-- 顶点着色器,只需要 每个顶点 运行一次 --
// 在我们的 pix 游戏中,所有 图元都是 4个顶点的 矩形。
// 所以,顶点着色器的 工作负担,要比 片段着色器 轻很多
void main()
{
gl_Position = projection * view * model * vec4( aPos, 1.0 );
TexCoord = aTexCoord;
}

49 changes: 17 additions & 32 deletions shaders/waterAnimCanvas.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// gpgpu FBO -- pix
// water anim --
#version 330 core

//-- 片段着色器的 主输出:颜色
Expand Down Expand Up @@ -70,12 +70,11 @@ vec3 color_sea_5 = vec3( 0.13, 0.24, 0.32 );
vec3 color_sea_6 = vec3( 0.11, 0.21, 0.27 );
*/

//--- old ----
vec3 color_sea_2 = vec3( 0.18, 0.32, 0.38 );
vec3 color_sea_3 = vec3( 0.16, 0.26, 0.34 );
vec3 color_sea_4 = vec3( 0.14, 0.22, 0.30 );
vec3 color_sea_5 = vec3( 0.12, 0.20, 0.26 );
vec3 color_sea_6 = vec3( 0.10, 0.18, 0.22 );
//--- sec visual style ----
vec3 color_sea_2 = vec3( 0.745, 0.753, 0.706 );
vec3 color_sea_3 = vec3( 0.608, 0.627, 0.596 );
vec3 color_sea_4 = vec3( 0.521, 0.541, 0.525 );
vec3 color_sea_5 = vec3( 0.423, 0.443, 0.435 );


//============ funcs ===========//
Expand Down Expand Up @@ -167,38 +166,25 @@ void main()
float altiLvl;
if( altiVal < 0.0 ){ //- under water

//------ -1 -------
if( altiVal > -10.0 ){
altiLvl = -1.0;
}
//------ -2 -------
else if( altiVal > -30.0 ){
if( altiVal > -30.0 ){
altiLvl = -2.0;
}

//------ -3 -------
else if( altiVal > -50.0 ){
else if( altiVal > -55.0 ){
altiLvl = -3.0;
}

//------ -4 -------
else if( altiVal > -60.0 ){
else if( altiVal > -90.0 ){
altiLvl = -4.0;
}

//------ -5 -------
else if( altiVal > -90.0 ){
altiLvl = -5.0;
}

//------ -6 -------
else{
altiLvl = -6.0;
altiLvl = -5.0;
}

//----------------
if( altiLvl < -6.0 ){
altiLvl = -6.0;
if( altiLvl < -5.0 ){
altiLvl = -5.0;
}
}else{ //- land
altiLvl = 1.0;
Expand All @@ -209,18 +195,17 @@ void main()
//------------------//
if( altiLvl >= -2.0 ){
color = color_sea_2;
alpha = 0.88; //-- 一定程度的 半透明
//alpha = 0.88; //-- 一定程度的 半透明
alpha = 1.0;
}else if( altiLvl == -3.0 ){
color = color_sea_3;
alpha = 0.94; //-- 一定程度的 半透明
//alpha = 0.94; //-- 一定程度的 半透明
alpha = 1.0;
}else if( altiLvl == -4.0 ){
color = color_sea_4;
alpha = 1.0;
}else if( altiLvl == -5.0 ){
color = color_sea_5;
alpha = 1.0;
}else{
color = color_sea_6;
color = color_sea_5;
alpha = 1.0;
}

Expand Down
28 changes: 18 additions & 10 deletions src/Engine/camera/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
void Camera::RenderUpdate(){

if( this->isMoving == false ){
return;
return;
}

glm::dvec2 off { this->targetDPos.x - this->currentDPos.x,
this->targetDPos.y - this->currentDPos.y };
//-- 若非常接近,直接同步 --
double criticalVal { 2.0 };
double criticalVal { 8.0 };
//-- 适当提高临界值,会让 camera运动变的 “简练”
// 同时利于 waterAnimCanvas 中的运算
if( (std::abs(off.x)<=criticalVal) && (std::abs(off.y)<=criticalVal) ){
Expand All @@ -43,20 +43,28 @@ void Camera::RenderUpdate(){
}

//---------------------------//
// 为了解决游戏中 “chunk间白线” 问题
// 限制 camera 每帧位移,都取整于 0.01
//
// 但这可能导致 win 中,画面位移卡顿... 猜测
//
// 将每一次 camera 的位移距离,都对齐于 windowsz 像素尺寸
//---------------------------//
/*
{
double bili = ViewingBox::windowSZ.x / ViewingBox::gameSZ.x; // tmp
//
off.x = floor(bili * off.x) / bili;
off.y = floor(bili * off.y) / bili;
}
*/


double alignX = this->approachPercent * off.x;
double alignY = this->approachPercent * off.y;
alignX = floor(alignX*1000.0) / 1000.0;
alignY = floor(alignY*1000.0) / 1000.0;
//-----------
this->currentDPos.x += alignX;
this->currentDPos.y += alignY;
this->currentDPos.z = -this->currentDPos.y + (0.5 * ViewingBox::z); //-- IMPORTANT --




}


Expand Down
4 changes: 2 additions & 2 deletions src/Engine/camera/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Camera{


//- 外部代码控制 camera运动 的唯一方式
inline void set_targetDPos( const glm::dvec2 &tpos_, double approachPercent_=0.08 ){
inline void set_targetDPos( const glm::dvec2 &tpos_, double approachPercent_=0.1 ){
if( tpos_ == this->targetDPos ){
return;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ class Camera{
glm::dvec2 targetDPos;
glm::dvec3 currentDPos;

double approachPercent {0.08}; //- camera运动的 “接近比率”
double approachPercent {0.1}; //- camera运动的 “接近比率”

//------ 方向向量 -------
//-- 以下3个向量 都是 单位向量
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/camera/RenderLayerType.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class RenderLayerType{
MajorGoes,
//....


PlayerGoIndication, //- not be used yet
UIs
};

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/camera/ViewingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ViewingBox::init(){
windowSZ_vs_gameSZ = srcHeight / 720.0;
}
*/
windowSZ_vs_gameSZ_ = srcHeight / 1080.0; // 测试版简易法,玩家设置的窗口变小,mapent显示尺寸也将变小
windowSZ_vs_gameSZ_ = srcHeight / 1200.0; // 测试版简易法,玩家设置的窗口变小,mapent显示尺寸也将变小

ViewingBox::windowSZ.x = windowConfig.windowPixW;
ViewingBox::windowSZ.y = windowConfig.windowPixH;
Expand Down
10 changes: 8 additions & 2 deletions src/Engine/camera/ViewingBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class ViewingBox{
static double chunks_zOff;
// 游戏地图 图层。 由无数块 chunk 拼接而成。
// 其中 water区域是半透明的,可以看到下层的 waterAnimCanvas 效果
// ...
// 在当前版本中,此层为空

static double waterAnim_zOff;
// 水域动画 图层。a canvas,其颜色逐帧生成,并直接渲染
Expand All @@ -79,6 +81,10 @@ class ViewingBox{

//...

static double playerGoIndication_zOff;
// 在 MajorGoes 的上方,再次渲染 player go,半透明的
// 从而让玩家可以知道 playerGo 的位置
// 一个最简单的方案

static double UIs_zOff;
// UIs 专用 图层
Expand All @@ -101,8 +107,8 @@ inline double ViewingBox::goShadows_zOff { 50.0 };
inline double ViewingBox::debug_zOff { 60.0 };

//...

inline double ViewingBox::UIs_zOff { 1900.0 };
inline double ViewingBox::playerGoIndication_zOff { 1890.0 };
inline double ViewingBox::UIs_zOff { 1900.0 };


#endif
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/game/MapCoord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* mapEntPos / pixPos 2-axis
* --------------------------
* some kinds of pos:
* FPos - float pos
* DPos - double pos
* FPos - float pos (pix)
* DPos - double pos (pix)
* PPos - pixel pos
* MPos - mapEnt pos
* FDPos - field pos
Expand Down
4 changes: 0 additions & 4 deletions src/Engine/game/gameObj/GameObj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ void GameObj::creat_new_goMesh( const std::string &name_,
const std::string &animFrameSetName_,
const std::string &actionName_,
RenderLayerType layerType_,
ShaderProgram *pixShaderPtr_,
ShaderProgram *shadowShaderPtr_,
const glm::vec2 pposOff_,
double off_z_,
bool isVisible_,
Expand All @@ -58,8 +56,6 @@ void GameObj::creat_new_goMesh( const std::string &name_,

//----- init -----//
gmesh.set_pic_renderLayer( layerType_ );
gmesh.set_pic_shader_program( pixShaderPtr_ );
gmesh.set_shadow_shader_program( shadowShaderPtr_ );

//-- goMesh pos in go --
gmesh.set_pposOff(pposOff_);
Expand Down
7 changes: 4 additions & 3 deletions src/Engine/game/gameObj/GameObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class GameObj : public std::enable_shared_from_this<GameObj>{
const std::string &animFrameSetName_,
const std::string &actionName_,
RenderLayerType layerType_,
ShaderProgram *pixShaderPtr_,
ShaderProgram *shadowShaderPtr_,
const glm::vec2 pposOff_,
double off_z_,
bool isVisible_,
Expand All @@ -95,6 +93,8 @@ class GameObj : public std::enable_shared_from_this<GameObj>{

void signUp_newGO_to_mapEnt();

void render_all_goMesh_for_playerGoIndication();

//-- 目前被 Crawl 使用 --
inline void set_direction_and_isFlipOver( const GODirection &dir_ ){
this->direction = dir_;
Expand Down Expand Up @@ -152,13 +152,14 @@ class GameObj : public std::enable_shared_from_this<GameObj>{
}



inline void render_all_goMesh(){
for( auto &pairRef : this->goMeshs ){
pairRef.second->RenderUpdate();
}
}



//void debug(); //- 打印 本go实例 的所有信息

//---------------- callback -----------------//
Expand Down
29 changes: 29 additions & 0 deletions src/Engine/game/gameObj/playerGoIndication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* ================= playerGoIndication.cpp ==========================
* -- tpr --
* CREATE -- 2019.08.19
* MODIFY --
* ----------------------------------------------------------
*/
#include "GameObj.h"



/* ===========================================================
* init
* -----------------------------------------------------------
*/
void GameObj::render_all_goMesh_for_playerGoIndication(){

//-------------------------------//
//
//-------------------------------//



}





4 changes: 3 additions & 1 deletion src/Engine/game/map/MapEnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ class MemMapEnt{
// 就算是 深渊类型的地面,也会有材质信息。
// ...这个值可能被取消...

EcoSysPlanType ecoSysPlanType {EcoSysPlanType::Forest};
//EcoSysPlanType ecoSysPlanType {EcoSysPlanType::Forest};

//-- 这个值暂时未被配置,尽管在理想态,每个 mapent,应该知道自己的 eco 类型


//--- 二级信息区 ---
Expand Down
Loading

0 comments on commit 412f39d

Please sign in to comment.