新工具 MaterialEditor

2020年10月14日 由 admin 没有评论 »

之前写了基于XML的Shader/Material系统,也有了命令行的Material编译器。
但在使用中发现,编辑、查错、编译、复制、预览。。。整个流程下来还是挺繁琐的,于是动手制作了如下小工具。
使用QT 5.15.1做为GUI API,跨平台。

关于前几日网站无法访问的说明

2020年10月8日 由 admin 没有评论 »

前几日由于服务器MariaDB Server(10.1.6)崩溃,造成了网站Wordpress无法访问。

独立的GLSL编译工具

2020年9月5日 由 admin 没有评论 »

由于使用SPIRV-Cross以及glslang的源代码版本有太多的编译配置选项,很烦,所以我制作了一个动态链接库版的GLSL到SPV编译器。

Github仓库

下载链接

使用代码大致如下:

namespace glsl_compiler
{
enum class DescriptorType //等同VkDescriptorType
{
SAMPLER = 0,
COMBINED_IMAGE_SAMPLER = 1,
SAMPLED_IMAGE = 2,
STORAGE_IMAGE = 3,
UNIFORM_TEXEL_BUFFER = 4,
STORAGE_TEXEL_BUFFER = 5,
UNIFORM_BUFFER = 6,
STORAGE_BUFFER = 7,
UNIFORM_BUFFER_DYNAMIC = 8,
STORAGE_BUFFER_DYNAMIC = 9,
INPUT_ATTACHMENT = 10,

BEGIN_RANGE=SAMPLER,
END_RANGE=INPUT_ATTACHMENT,
RANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1
};

enum class VertexAttribBaseType
{
Bool=0,
Int,
UInt,
Float,
Double,
};//enum class VertexAttribBaseType

struct ShaderStage
{
char name[128];
uint8_t location;
uint32_t basetype; //对应enum class VertexAttribBaseType
uint32_t vec_size;
};//

struct ShaderStageData
{
uint32_t count;
ShaderStage *items;
};

struct ShaderResource
{
char name[128];

uint8_t set;
uint8_t binding;
};

struct ShaderResourceData
{
uint32_t count;
ShaderResource *items;
};

struct SPVData
{
bool result;
char *log;
char *debug_log;

uint32_t *spv_data;
uint32_t spv_length;

ShaderStageData input,output;
ShaderResourceData resource[size_t(DescriptorType::RANGE_SIZE)];
};

struct GLSLCompilerInterface
{
bool (*Init)(); ///<初始化
void (*Close)(); ///<关闭

uint32_t (*GetType)(const char *ext_name); ///<根据扩展名获取SHADER类型
SPVData * (*Compile)(const uint32_t type,const char *source); ///<编译glsl

void (*Free)(SPVData *); ///<释放数据
};
}//namespace glsl_shader

使用方法:

  1. 加载动态链接库
  2. 从动态链接库获取GetInterface函数
  3. 用GetInterface函数得到一个GLSLCompilerInterface指针(以下简称GSI)
  4. 调用GSI::Init函数
  5. 自行加载glsl的文本,并保证为ansi或utf8字符集
  6. 截取glsl文件扩展名(不包括.),或自行传递一个字符串给GSI::GetType函数,以获取shader类型。
    shader文件扩展名规则同glslangValidator

    • vert 顶点
    • tesc 镶嵌控制
    • tese 镶嵌评估
    • geom 几何
    • frag 片断
    • comp 计算
    • task 任务
    • mesh 网格
  7. 调用GSI::Compile函数,并同时传递shader类型以及shader文本字符串
  8. 根据得到的SPVData::result来判断是否成功
    • result为false表示失败,在log/debug_log中包含返回的错误信息
    • result为true表示成功,在spv_data,spv_length中包含编译好的spv数据
  9. 自行处理spv数据
  10. 调用GSI::Free释放SPVData指针

文本显示,一个看起来很简单的功能

2020年8月4日 由 admin 没有评论 »

现所有主要开源仓库一览

2020年4月5日 由 admin 没有评论 »
  • 现今主力开发的超轻量级渲染引擎
    • https://github.com/hyzboy/ULRE
  • 曾经的旧主力引擎
    • https://github.com/hyzboy/CMGameEngine
  •  曾经短暂编写PHP网站时总结的小型PHP工具库
    • https://github.com/hyzboy/CMPHP
  • 修改的仅支持OpenGL Core的GLEW
    • https://github.com/hyzboy/GLEWCore

2D/3D抛物线

2019年5月23日 由 admin 没有评论 »

#include<iostream>

using namespace std;
using uint=unsigned int;

struct vec2
{
float x,y;
};

struct vec3
{
float x,y,z;
};

/**
* 算出指定数量的抛物线高度值
* @param count 结果数量
* @param start 起始时间量,一般为-1
* @param end 结束时间量,一般为+1
*/
float *Parabolic(const uint count,const float time_start=-1,const float time_end=1)
{
if(count<=0)return(nullptr);

float *result=new float[count];

float rate;
float cur=time_start;
float total_time=time_end-time_start;

for(uint i=0;i<count;i++)
{
rate=float(i)/float(count);

cur=time_start+rate*total_time;

result[i]=1-cur*cur;

cout<<“height[“<<i<<“] “<<result[i]<<endl;
}

return result;
}

/**
* 画2D抛物线
* @param start 起始点
* @param end 结束点
* @param up 单位向上量
* @param height 高度值
* @param count 数量
*/
void Put2D(const vec2 &start,const vec2 &end,const vec2 &up,const float *height,const uint count)
{
vec2 total;
vec2 pos;
float rate;

total.x=end.x-start.x;
total.y=end.y-start.y;

cout<<“from “<<start.x<<“,”<<start.y<<” to “<<end.x<<“,”<<end.y<<endl;

for(uint i=0;i<count;i++)
{
rate=float(i)/float(count);

pos.x=start.x+rate*total.x;
pos.y=start.y+rate*total.y;

pos.x+=height[i]*up.x;
pos.y+=height[i]*up.y;

cout<<i<<“: “<<pos.x<<“,”<<pos.y<<endl;
}
}

/**
* 画3D抛物线
* @param start 起始点
* @param end 结束点
* @param up 单位向上量
* @param height 高度值
* @param count 数量
*/
void Put3D(const vec3 &start,const vec3 &end,const vec3 &up,const float *height,const uint count)
{
vec3 total;
vec3 pos;
float rate;

total.x=end.x-start.x;
total.y=end.y-start.y;
total.z=end.z-start.z;

cout<<“from “<<start.x<<“,”<<start.y<<“,”<<start.z<<” to “<<end.x<<“,”<<end.y<<“,”<<end.z<<endl;

for(uint i=0;i<count;i++)
{
rate=float(i)/float(count);

pos.x=start.x+rate*total.x;
pos.y=start.y+rate*total.y;
pos.z=start.z+rate*total.z;

pos.x+=height[i]*up.x;
pos.y+=height[i]*up.y;
pos.z+=height[i]*up.z;

cout<<i<<“: “<<pos.x<<“,”<<pos.y<<“,”<<pos.z<<endl;
}
}

void Test2D(float *height,const uint count)
{
vec2 start,end,up;

start.x=0;
start.y=0;

end.x=100;
end.y=0;

up.x=0;
up.y=100;

Put2D(start,end,up,height,count);
}

void Test3D(float *height,const uint count)
{
vec3 start,end,up;

start.x=0;
start.y=0;
start.z=0;

end.x=100;
end.y=0;
end.z=100;

up.x=0;
up.y=100;
up.z=0;

Put3D(start,end,up,height,count);
}

void main()
{
constexpr uint count=10;

float *height=Parabolic(count);

Test2D(height,count);
Test3D(height,count);

delete[] height;
}

技术试验:迁移到Vulkan

2019年4月9日 由 admin 没有评论 »
https://github.com/hyzboy/ULRE/tree/devel_4_move_to_vulkan

Vulkan是Khronos寄于厚望的下一代图形API,我们在全新的试验工程ULRE(超轻量级渲染引擎)中,尝试将渲染API迁移到Vulkan。

未来ULRE的完善版本,将会取代CMGameEngine中老旧的渲染器。

重新支持C++Builder

2018年11月5日 由 admin 没有评论 »

Turbo C/C++、Borland C++、C++Builder曾经是我唯一的开发工具。在很久的一段时间里,我一直使用的是盗版,后来Borland公司的一位员工劝说我要使用正版。我同意了,我努力去做了,我也真的做到了。

只不过世事难料的是,因为我的全正版化计划,我放弃了我最爱的C++Builder。原因很有意思也很简单:我买不到正版从2002年开始,我寻找一切可以购买C++Builder正版的方式,但都一无所获。一开始告诉我在中国不卖个人版和专业版,只卖企业版。于是我准备好了3万块钱去买一套企业版,结果告诉我不卖给个人。我成立了一家空壳公司去买,答复我不卖给只有2个人的小公司。拉了几个朋友都弄成公司员工,最后告诉我至少要5套起卖。当时我就差点去丰联广场拉横幅抗议了,我突然醒悟:为什么我要花这么大的力气去给人送钱呢?

于是我放弃了使用C++Builder,转向Microsoft C/C++。为什么是Microsoft C/C++而不是Visual C++呢?因为我不想花钱,但又想是正版。Visual C++ IDE是收费的,但微软提供了免费且可商用的Windows SDK,其中便包含了Visual C++底层所调用的Microsoft C/C++ Compiler。于是我所有的工程就变成了使用CMAKE生成工程文件,再通过MSBuild编译链接。整个过程全程正版、合法、免费。

我曾经说过,在我可以得到正版的C++Builder前,我不会考虑再度支持C++Builder。只是没想到这个时间隔的是这么久。如今C++Builder推出了免费且可有限商用的Community版,这确实是一份正版授权,履行承诺的时刻来了。

 

全新渲染器

2018年10月1日 由 admin 没有评论 »

近十年,我们的渲染器设计都失败了!这其中,前期有各种各样的原因。后期由于服务器模块的重量化,倒导渲染器的工作也停滞了很多年。

此次的渲染器重新设计,将会对引擎本身带来很多革命性的变化。

  • 多平台支持: PC(Win/macOS/Linux),手机(iOS/Android)
  • 多线程设计: 每个窗口的渲染将完全开启独立线程处理,互不影响。主程序的所有操作都将转换为渲染指令提交给对应窗口的线程。
  • 多渲染API设计: 其实我们支持的还是只有OpenGL,只不过为了同时支持PC和手机,我们会实现OpenGL Core与OpenGL ES两套API支持。Vulkan做为未来可能的选项之一。而同时,我们会首发支持一种简易的软件渲染器(考虑使用SwiftShader的OpenGL/ES),用于一般2D界面的应用软件,比如在OpenGL无法初始化时的一些配置程序。
  • 异步资源加载支持: 此次我们将全面实现资源异步加载支持,资源加载不再同步执行。每一个硬体资源设备,将会有一个独立的线程执行加载任务。
  • 全新的GUI模块: GUI模块一直是我们的骄傲,但终究历史太久。此次我们将引入Qt/Metro/Material等GUI系统的设计概念,全面重新设计我们的GUI系统。更加现代化,同时适用于手机和PC。

新的strchr/strrchr/ClipFilename/ClipLastPathname函数

2018年8月22日 由 admin 没有评论 »

参见范例Example.DataType.StrCharTest

str: “hello,world!”
strchr(str,’,’) return “,world!”
strrchr(str,strlen(str),’,’) return “,world!”
strchr(str,”el”,2) return “ello,world!”
strrchr(str,strlen(str),”el”,2) return “ld!”
strrchr(str,strlen(str),3,’l’) return “lo,world!”
strrchr(str,strlen(str),3,”el”,2) return “lo,world!”
ClipFilename(“C:\1.txt”) return “1.txt”
ClipLastPathname(“C:\1\2”) return “2”
ClipLastPathname(“C:\1\2\”) return “2”
ClipLastPathname(“C:\1\2\\”) return “2”

鄂ICP备09027626号