add shader
This commit is contained in:
parent
2df1b26a09
commit
f3961d7c6b
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 122c7addc294daa1d2c8c19ed08b1b50aa47571f
|
||||
Subproject commit 5ec34e30035a8ef4eeb8c116e19c79d12663c828
|
@ -26,7 +26,7 @@ namespace hgl
|
||||
float height; ///<视图高
|
||||
|
||||
float fov=60; ///<水平FOV
|
||||
float znear=16,zfar=256; ///<Z轴上离眼睛的距离
|
||||
float znear=16,zfar=256; ///<Z轴上离眼睛的距离(注:因znear会参与计算,请不要使用0或过于接近0的值)
|
||||
|
||||
Vector4f eye; ///<眼睛坐标
|
||||
Vector4f center; ///<视点坐标
|
||||
|
@ -23,6 +23,10 @@ public:
|
||||
DataSource() {format=DataFormat::NONE;}
|
||||
DataSource(const DataFormat &df){format=df;}
|
||||
virtual ~DataSource()=default;
|
||||
|
||||
public:
|
||||
|
||||
virtual bool GenDefine(UTF8String &){return false;} ///<产生define代码
|
||||
};//class DataSource
|
||||
|
||||
/**
|
||||
@ -33,6 +37,8 @@ class DataSourceConst:public DataSource
|
||||
public:
|
||||
|
||||
using DataSource::DataSource;
|
||||
|
||||
virtual bool GenDefine(UTF8String &)=0; ///<产生define代码
|
||||
};//class DataSourceConst:public DataSource
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,14 @@ enum class API
|
||||
Vulkan
|
||||
};
|
||||
|
||||
/**
|
||||
* 缺省绑定号
|
||||
*/
|
||||
enum class ShaderDefaultBinding
|
||||
{
|
||||
WorldMatrix=0,
|
||||
};
|
||||
|
||||
class ShaderMaker
|
||||
{
|
||||
protected:
|
||||
@ -44,6 +52,7 @@ protected:
|
||||
virtual bool MakeHeader();
|
||||
virtual bool MakeVertexInput();
|
||||
virtual void MakeConstValue(const NodeList &);
|
||||
virtual void MakeScalarValue(const NodeList &);
|
||||
virtual void MakeTextureInput(const NodeList &);
|
||||
virtual void MakeUBOInput(const NodeList &);
|
||||
virtual void MakeOutput();
|
||||
|
@ -4,14 +4,17 @@
|
||||
#define SHADER_NAMESPACE hgl::graph::shader
|
||||
#define BEGIN_SHADER_NAMESPACE namespace hgl{namespace graph{namespace shader{
|
||||
#define END_SHADER_NAMESPACE }}}
|
||||
#define USING_SHADER_NAMESPACE using SHADER_NAMESPACE;
|
||||
|
||||
#define SHADER_NODE_NAMESPACE hgl::graph::shader::node
|
||||
#define BEGIN_SHADER_NODE_NAMESPACE namespace hgl{namespace graph{namespace shader{namespace node{
|
||||
#define END_SHADER_NODE_NAMESPACE }}}}
|
||||
#define USING_SHADER_NODE_NAMESPACE using SHADER_NODE_NAMESPACE;
|
||||
|
||||
#define SHADER_PARAM_NAMESPACE hgl::graph::shader::param
|
||||
#define BEGIN_SHADER_PARAM_NAMESPACE namespace hgl{namespace graph{namespace shader{namespace param{
|
||||
#define END_SHADER_PARAM_NAMESPACE }}}}
|
||||
#define USING_SHADER_PARAM_NAMESPACE using SHADER_PARAM_NAMESPACE;
|
||||
|
||||
BEGIN_SHADER_NODE_NAMESPACE
|
||||
class Node;
|
||||
|
@ -1,32 +0,0 @@
|
||||
material flat_color
|
||||
{
|
||||
shader
|
||||
{
|
||||
vertex
|
||||
{
|
||||
file = FlatColor.vert.spv
|
||||
|
||||
input Vertex
|
||||
{
|
||||
location = 0
|
||||
format = vec2f
|
||||
}
|
||||
|
||||
input Color
|
||||
{
|
||||
location 1
|
||||
format = vec3f
|
||||
}
|
||||
|
||||
ubo MVPMatrix ubo
|
||||
{
|
||||
binding = 0
|
||||
}
|
||||
}
|
||||
|
||||
fragment
|
||||
{
|
||||
file = FlatColor.frag.spv
|
||||
}
|
||||
}
|
||||
}
|
15
res/shader/UBO_WorldMatrix.glsl
Normal file
15
res/shader/UBO_WorldMatrix.glsl
Normal file
@ -0,0 +1,15 @@
|
||||
layout(binding = 0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
} world;
|
1
res/shader/header_desktop.glsl
Normal file
1
res/shader/header_desktop.glsl
Normal file
@ -0,0 +1 @@
|
||||
#version 460 core
|
1
res/shader/header_mobile.glsl
Normal file
1
res/shader/header_mobile.glsl
Normal file
@ -0,0 +1 @@
|
||||
#version 320 es
|
3
res/shader/push_constant_3d.glsl
Normal file
3
res/shader/push_constant_3d.glsl
Normal file
@ -0,0 +1,3 @@
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
411
res/shader/shaderlib.glsl
Normal file
411
res/shader/shaderlib.glsl
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright 2011-2019 Branimir Karadzic. All rights reserved.
|
||||
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
vec4 encodeRE8(float _r)
|
||||
{
|
||||
float exponent = ceil(log2(_r) );
|
||||
return vec4(_r / exp2(exponent)
|
||||
, 0.0
|
||||
, 0.0
|
||||
, (exponent + 128.0) / 255.0
|
||||
);
|
||||
}
|
||||
|
||||
float decodeRE8(vec4 _re8)
|
||||
{
|
||||
float exponent = _re8.w * 255.0 - 128.0;
|
||||
return _re8.x * exp2(exponent);
|
||||
}
|
||||
|
||||
vec4 encodeRGBE8(vec3 _rgb)
|
||||
{
|
||||
vec4 rgbe8;
|
||||
float maxComponent = max(max(_rgb.x, _rgb.y), _rgb.z);
|
||||
float exponent = ceil(log2(maxComponent) );
|
||||
rgbe8.xyz = _rgb / exp2(exponent);
|
||||
rgbe8.w = (exponent + 128.0) / 255.0;
|
||||
return rgbe8;
|
||||
}
|
||||
|
||||
vec3 decodeRGBE8(vec4 _rgbe8)
|
||||
{
|
||||
float exponent = _rgbe8.w * 255.0 - 128.0;
|
||||
vec3 rgb = _rgbe8.xyz * exp2(exponent);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 encodeNormalUint(vec3 _normal)
|
||||
{
|
||||
return _normal * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 decodeNormalUint(vec3 _encodedNormal)
|
||||
{
|
||||
return _encodedNormal * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
vec2 encodeNormalSphereMap(vec3 _normal)
|
||||
{
|
||||
return normalize(_normal.xy) * sqrt(_normal.z * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
vec3 decodeNormalSphereMap(vec2 _encodedNormal)
|
||||
{
|
||||
float zz = dot(_encodedNormal, _encodedNormal) * 2.0 - 1.0;
|
||||
return vec3(normalize(_encodedNormal.xy) * sqrt(1.0 - zz*zz), zz);
|
||||
}
|
||||
|
||||
vec2 octahedronWrap(vec2 _val)
|
||||
{
|
||||
// Reference(s):
|
||||
// - Octahedron normal vector encoding
|
||||
// https://web.archive.org/web/20191027010600/https://knarkowicz.wordpress.com/2014/04/16/octahedron-normal-vector-encoding/comment-page-1/
|
||||
return (1.0 - abs(_val.yx) )
|
||||
* mix(vec2_splat(-1.0), vec2_splat(1.0), vec2(greaterThanEqual(_val.xy, vec2_splat(0.0) ) ) );
|
||||
}
|
||||
|
||||
vec2 encodeNormalOctahedron(vec3 _normal)
|
||||
{
|
||||
_normal /= abs(_normal.x) + abs(_normal.y) + abs(_normal.z);
|
||||
_normal.xy = _normal.z >= 0.0 ? _normal.xy : octahedronWrap(_normal.xy);
|
||||
_normal.xy = _normal.xy * 0.5 + 0.5;
|
||||
return _normal.xy;
|
||||
}
|
||||
|
||||
vec3 decodeNormalOctahedron(vec2 _encodedNormal)
|
||||
{
|
||||
_encodedNormal = _encodedNormal * 2.0 - 1.0;
|
||||
|
||||
vec3 normal;
|
||||
normal.z = 1.0 - abs(_encodedNormal.x) - abs(_encodedNormal.y);
|
||||
normal.xy = normal.z >= 0.0 ? _encodedNormal.xy : octahedronWrap(_encodedNormal.xy);
|
||||
return normalize(normal);
|
||||
}
|
||||
|
||||
vec3 convertRGB2XYZ(vec3 _rgb)
|
||||
{
|
||||
// Reference(s):
|
||||
// - RGB/XYZ Matrices
|
||||
// https://web.archive.org/web/20191027010220/http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
|
||||
vec3 xyz;
|
||||
xyz.x = dot(vec3(0.4124564, 0.3575761, 0.1804375), _rgb);
|
||||
xyz.y = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||
xyz.z = dot(vec3(0.0193339, 0.1191920, 0.9503041), _rgb);
|
||||
return xyz;
|
||||
}
|
||||
|
||||
vec3 convertXYZ2RGB(vec3 _xyz)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = dot(vec3( 3.2404542, -1.5371385, -0.4985314), _xyz);
|
||||
rgb.y = dot(vec3(-0.9692660, 1.8760108, 0.0415560), _xyz);
|
||||
rgb.z = dot(vec3( 0.0556434, -0.2040259, 1.0572252), _xyz);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 convertXYZ2Yxy(vec3 _xyz)
|
||||
{
|
||||
// Reference(s):
|
||||
// - XYZ to xyY
|
||||
// https://web.archive.org/web/20191027010144/http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
||||
float inv = 1.0/dot(_xyz, vec3(1.0, 1.0, 1.0) );
|
||||
return vec3(_xyz.y, _xyz.x*inv, _xyz.y*inv);
|
||||
}
|
||||
|
||||
vec3 convertYxy2XYZ(vec3 _Yxy)
|
||||
{
|
||||
// Reference(s):
|
||||
// - xyY to XYZ
|
||||
// https://web.archive.org/web/20191027010036/http://www.brucelindbloom.com/index.html?Eqn_xyY_to_XYZ.html
|
||||
vec3 xyz;
|
||||
xyz.x = _Yxy.x*_Yxy.y/_Yxy.z;
|
||||
xyz.y = _Yxy.x;
|
||||
xyz.z = _Yxy.x*(1.0 - _Yxy.y - _Yxy.z)/_Yxy.z;
|
||||
return xyz;
|
||||
}
|
||||
|
||||
vec3 convertRGB2Yxy(vec3 _rgb)
|
||||
{
|
||||
return convertXYZ2Yxy(convertRGB2XYZ(_rgb) );
|
||||
}
|
||||
|
||||
vec3 convertYxy2RGB(vec3 _Yxy)
|
||||
{
|
||||
return convertXYZ2RGB(convertYxy2XYZ(_Yxy) );
|
||||
}
|
||||
|
||||
vec3 convertRGB2Yuv(vec3 _rgb)
|
||||
{
|
||||
vec3 yuv;
|
||||
yuv.x = dot(_rgb, vec3(0.299, 0.587, 0.114) );
|
||||
yuv.y = (_rgb.x - yuv.x)*0.713 + 0.5;
|
||||
yuv.z = (_rgb.z - yuv.x)*0.564 + 0.5;
|
||||
return yuv;
|
||||
}
|
||||
|
||||
vec3 convertYuv2RGB(vec3 _yuv)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = _yuv.x + 1.403*(_yuv.y-0.5);
|
||||
rgb.y = _yuv.x - 0.344*(_yuv.y-0.5) - 0.714*(_yuv.z-0.5);
|
||||
rgb.z = _yuv.x + 1.773*(_yuv.z-0.5);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 convertRGB2YIQ(vec3 _rgb)
|
||||
{
|
||||
vec3 yiq;
|
||||
yiq.x = dot(vec3(0.299, 0.587, 0.114 ), _rgb);
|
||||
yiq.y = dot(vec3(0.595716, -0.274453, -0.321263), _rgb);
|
||||
yiq.z = dot(vec3(0.211456, -0.522591, 0.311135), _rgb);
|
||||
return yiq;
|
||||
}
|
||||
|
||||
vec3 convertYIQ2RGB(vec3 _yiq)
|
||||
{
|
||||
vec3 rgb;
|
||||
rgb.x = dot(vec3(1.0, 0.9563, 0.6210), _yiq);
|
||||
rgb.y = dot(vec3(1.0, -0.2721, -0.6474), _yiq);
|
||||
rgb.z = dot(vec3(1.0, -1.1070, 1.7046), _yiq);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 toLinear(vec3 _rgb)
|
||||
{
|
||||
return pow(abs(_rgb), vec3_splat(2.2) );
|
||||
}
|
||||
|
||||
vec4 toLinear(vec4 _rgba)
|
||||
{
|
||||
return vec4(toLinear(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toLinearAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb / 12.92;
|
||||
vec3 hi = pow( (_rgb + 0.055) / 1.055, vec3_splat(2.4) );
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.04045) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toLinearAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toLinearAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
float toGamma(float _r)
|
||||
{
|
||||
return pow(abs(_r), 1.0/2.2);
|
||||
}
|
||||
|
||||
vec3 toGamma(vec3 _rgb)
|
||||
{
|
||||
return pow(abs(_rgb), vec3_splat(1.0/2.2) );
|
||||
}
|
||||
|
||||
vec4 toGamma(vec4 _rgba)
|
||||
{
|
||||
return vec4(toGamma(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toGammaAccurate(vec3 _rgb)
|
||||
{
|
||||
vec3 lo = _rgb * 12.92;
|
||||
vec3 hi = pow(abs(_rgb), vec3_splat(1.0/2.4) ) * 1.055 - 0.055;
|
||||
vec3 rgb = mix(hi, lo, vec3(lessThanEqual(_rgb, vec3_splat(0.0031308) ) ) );
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 toGammaAccurate(vec4 _rgba)
|
||||
{
|
||||
return vec4(toGammaAccurate(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toReinhard(vec3 _rgb)
|
||||
{
|
||||
return toGamma(_rgb/(_rgb+vec3_splat(1.0) ) );
|
||||
}
|
||||
|
||||
vec4 toReinhard(vec4 _rgba)
|
||||
{
|
||||
return vec4(toReinhard(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toFilmic(vec3 _rgb)
|
||||
{
|
||||
_rgb = max(vec3_splat(0.0), _rgb - 0.004);
|
||||
_rgb = (_rgb*(6.2*_rgb + 0.5) ) / (_rgb*(6.2*_rgb + 1.7) + 0.06);
|
||||
return _rgb;
|
||||
}
|
||||
|
||||
vec4 toFilmic(vec4 _rgba)
|
||||
{
|
||||
return vec4(toFilmic(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 toAcesFilmic(vec3 _rgb)
|
||||
{
|
||||
// Reference(s):
|
||||
// - ACES Filmic Tone Mapping Curve
|
||||
// https://web.archive.org/web/20191027010704/https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
|
||||
float aa = 2.51f;
|
||||
float bb = 0.03f;
|
||||
float cc = 2.43f;
|
||||
float dd = 0.59f;
|
||||
float ee = 0.14f;
|
||||
return saturate( (_rgb*(aa*_rgb + bb) )/(_rgb*(cc*_rgb + dd) + ee) );
|
||||
}
|
||||
|
||||
vec4 toAcesFilmic(vec4 _rgba)
|
||||
{
|
||||
return vec4(toAcesFilmic(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 luma(vec3 _rgb)
|
||||
{
|
||||
float yy = dot(vec3(0.2126729, 0.7151522, 0.0721750), _rgb);
|
||||
return vec3_splat(yy);
|
||||
}
|
||||
|
||||
vec4 luma(vec4 _rgba)
|
||||
{
|
||||
return vec4(luma(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 conSatBri(vec3 _rgb, vec3 _csb)
|
||||
{
|
||||
vec3 rgb = _rgb * _csb.z;
|
||||
rgb = mix(luma(rgb), rgb, _csb.y);
|
||||
rgb = mix(vec3_splat(0.5), rgb, _csb.x);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec4 conSatBri(vec4 _rgba, vec3 _csb)
|
||||
{
|
||||
return vec4(conSatBri(_rgba.xyz, _csb), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 posterize(vec3 _rgb, float _numColors)
|
||||
{
|
||||
return floor(_rgb*_numColors) / _numColors;
|
||||
}
|
||||
|
||||
vec4 posterize(vec4 _rgba, float _numColors)
|
||||
{
|
||||
return vec4(posterize(_rgba.xyz, _numColors), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 sepia(vec3 _rgb)
|
||||
{
|
||||
vec3 color;
|
||||
color.x = dot(_rgb, vec3(0.393, 0.769, 0.189) );
|
||||
color.y = dot(_rgb, vec3(0.349, 0.686, 0.168) );
|
||||
color.z = dot(_rgb, vec3(0.272, 0.534, 0.131) );
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 sepia(vec4 _rgba)
|
||||
{
|
||||
return vec4(sepia(_rgba.xyz), _rgba.w);
|
||||
}
|
||||
|
||||
vec3 blendOverlay(vec3 _base, vec3 _blend)
|
||||
{
|
||||
vec3 lt = 2.0 * _base * _blend;
|
||||
vec3 gte = 1.0 - 2.0 * (1.0 - _base) * (1.0 - _blend);
|
||||
return mix(lt, gte, step(vec3_splat(0.5), _base) );
|
||||
}
|
||||
|
||||
vec4 blendOverlay(vec4 _base, vec4 _blend)
|
||||
{
|
||||
return vec4(blendOverlay(_base.xyz, _blend.xyz), _base.w);
|
||||
}
|
||||
|
||||
vec3 adjustHue(vec3 _rgb, float _hue)
|
||||
{
|
||||
vec3 yiq = convertRGB2YIQ(_rgb);
|
||||
float angle = _hue + atan2(yiq.z, yiq.y);
|
||||
float len = length(yiq.yz);
|
||||
return convertYIQ2RGB(vec3(yiq.x, len*cos(angle), len*sin(angle) ) );
|
||||
}
|
||||
|
||||
vec4 packFloatToRgba(float _value)
|
||||
{
|
||||
const vec4 shift = vec4(256 * 256 * 256, 256 * 256, 256, 1.0);
|
||||
const vec4 mask = vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
|
||||
vec4 comp = fract(_value * shift);
|
||||
comp -= comp.xxyz * mask;
|
||||
return comp;
|
||||
}
|
||||
|
||||
float unpackRgbaToFloat(vec4 _rgba)
|
||||
{
|
||||
const vec4 shift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
||||
return dot(_rgba, shift);
|
||||
}
|
||||
|
||||
vec2 packHalfFloat(float _value)
|
||||
{
|
||||
const vec2 shift = vec2(256, 1.0);
|
||||
const vec2 mask = vec2(0, 1.0 / 256.0);
|
||||
vec2 comp = fract(_value * shift);
|
||||
comp -= comp.xx * mask;
|
||||
return comp;
|
||||
}
|
||||
|
||||
float unpackHalfFloat(vec2 _rg)
|
||||
{
|
||||
const vec2 shift = vec2(1.0 / 256.0, 1.0);
|
||||
return dot(_rg, shift);
|
||||
}
|
||||
|
||||
float random(vec2 _uv)
|
||||
{
|
||||
return fract(sin(dot(_uv.xy, vec2(12.9898, 78.233) ) ) * 43758.5453);
|
||||
}
|
||||
|
||||
vec3 fixCubeLookup(vec3 _v, float _lod, float _topLevelCubeSize)
|
||||
{
|
||||
// Reference(s):
|
||||
// - Seamless cube-map filtering
|
||||
// https://web.archive.org/web/20190411181934/http://the-witness.net/news/2012/02/seamless-cube-map-filtering/
|
||||
float ax = abs(_v.x);
|
||||
float ay = abs(_v.y);
|
||||
float az = abs(_v.z);
|
||||
float vmax = max(max(ax, ay), az);
|
||||
float scale = 1.0 - exp2(_lod) / _topLevelCubeSize;
|
||||
if (ax != vmax) { _v.x *= scale; }
|
||||
if (ay != vmax) { _v.y *= scale; }
|
||||
if (az != vmax) { _v.z *= scale; }
|
||||
return _v;
|
||||
}
|
||||
|
||||
vec2 texture2DBc5(sampler2D _sampler, vec2 _uv)
|
||||
{
|
||||
#if BGFX_SHADER_LANGUAGE_HLSL && BGFX_SHADER_LANGUAGE_HLSL <= 3
|
||||
return texture2D(_sampler, _uv).yx;
|
||||
#else
|
||||
return texture2D(_sampler, _uv).xy;
|
||||
#endif
|
||||
}
|
||||
|
||||
mat3 cofactor(mat4 _m)
|
||||
{
|
||||
// Reference:
|
||||
// Cofactor of matrix. Use to transform normals. The code assumes the last column of _m is [0,0,0,1].
|
||||
// https://www.shadertoy.com/view/3s33zj
|
||||
// https://github.com/graphitemaster/normals_revisited
|
||||
return mat3(
|
||||
_m[1][1]*_m[2][2]-_m[1][2]*_m[2][1],
|
||||
_m[1][2]*_m[2][0]-_m[1][0]*_m[2][2],
|
||||
_m[1][0]*_m[2][1]-_m[1][1]*_m[2][0],
|
||||
_m[0][2]*_m[2][1]-_m[0][1]*_m[2][2],
|
||||
_m[0][0]*_m[2][2]-_m[0][2]*_m[2][0],
|
||||
_m[0][1]*_m[2][0]-_m[0][0]*_m[2][1],
|
||||
_m[0][1]*_m[1][2]-_m[0][2]*_m[1][1],
|
||||
_m[0][2]*_m[1][0]-_m[0][0]*_m[1][2],
|
||||
_m[0][0]*_m[1][1]-_m[0][1]*_m[1][0]
|
||||
);
|
||||
}
|
@ -23,6 +23,10 @@ SET(GRAPH_SHADER_MAKER_SOURCE ${GRAPH_SHADER_HEADER_PATH}/ShaderMaker.h
|
||||
|
||||
source_group("Shader Maker" FILES ${GRAPH_SHADER_MAKER_SOURCE})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SET(GRAPH_SPV_SOURCE ${GRAPH_SHADER_HEADER_PATH}/glsl2spv.h
|
||||
glsl2spv.cpp)
|
||||
|
||||
|
@ -8,6 +8,17 @@
|
||||
#include<hgl/io/DataOutputStream.h>
|
||||
#include<hgl/io/TextOutputStream.h>
|
||||
|
||||
/*
|
||||
设计概念:
|
||||
|
||||
节点分类:
|
||||
const 直接写在代码中的数值
|
||||
scalr 由UBO传入的数据
|
||||
Texture 纹理
|
||||
|
||||
|
||||
*/
|
||||
|
||||
BEGIN_SHADER_NAMESPACE
|
||||
namespace
|
||||
{
|
||||
@ -144,6 +155,30 @@ void ShaderMaker::MakeTextureInput(const NodeList &nl)
|
||||
shader_source.Add("");
|
||||
}
|
||||
|
||||
void ShaderMaker::MakeScalarValue(const NodeList &nl)
|
||||
{
|
||||
const uint count=nl.GetCount();
|
||||
|
||||
if(count<=0)return;
|
||||
|
||||
shader_source.Add("layout(binding="+UTF8String(binding)+") uniform UserInput");
|
||||
shader_source.Add("{");
|
||||
|
||||
node::texture **tex_node=(node::texture **)nl.GetData();
|
||||
param::ParamType tt;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
tt=(*tex_node)->GetTextureType();
|
||||
|
||||
shader_source.Add("layout(binding="+UTF8String(binding)+") uniform "+GetTypename(tt)+" "+(*tex_node)->GetNodeName()+";");
|
||||
|
||||
++tex_node;
|
||||
++binding;
|
||||
}
|
||||
shader_source.Add("}");
|
||||
}
|
||||
|
||||
void ShaderMaker::MakeUBOInput(const NodeList &nl)
|
||||
{
|
||||
}
|
||||
@ -223,9 +258,10 @@ bool ShaderMaker::Make()
|
||||
|
||||
if(!MakeHeader())return(false);
|
||||
|
||||
MakeConstValue (node_list[int(node::NodeType::Const )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeTextureInput(node_list[int(node::NodeType::Texture )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeUBOInput (node_list[int(node::NodeType::UBO )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeConstValue (node_list[uint(node::NodeType::Const )-uint(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeScalarValue (node_list[uint(node::NodeType::Param )-uint(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeTextureInput(node_list[uint(node::NodeType::Texture )-uint(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeUBOInput (node_list[uint(node::NodeType::UBO )-uint(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
|
||||
if(!MakeVertexInput())return(false);
|
||||
|
||||
|
@ -21,7 +21,8 @@ namespace hgl
|
||||
-forward.x, -forward.y, -forward.z/2.0f, 1.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f);
|
||||
// ^^^^^^
|
||||
// 某些引擎此项为0.5,这个会影响最终输出的z值,但我们这里必须为0
|
||||
// 某些引擎这里为0.5,那是因为他们是 -1 to 1 的Z值设定,而我们是0 to 1,所以这里不用乘
|
||||
// 同理,camera的znear为接近0的正数,zfar为一个较大的正数,默认使用16/256
|
||||
|
||||
return result*translate(-eye.xyz());
|
||||
}
|
||||
@ -33,12 +34,14 @@ namespace hgl
|
||||
else
|
||||
matrix.projection=ortho(width,height,znear,zfar); //这个算的不对
|
||||
|
||||
//matrix.inverse_projection=matrix.projection.Inverted();
|
||||
matrix.inverse_projection=matrix.projection.Inverted();
|
||||
|
||||
matrix.modelview=hgl::graph::LookAt(eye,center,up_vector);
|
||||
//matrix.modelview=Matrix4f::LookAt(eye.xyz(),center.xyz(),forward_vector.xyz(),up_vector.xyz(),up_vector.xyz());
|
||||
matrix.inverse_modelview=matrix.modelview.Inverted();
|
||||
|
||||
matrix.mvp=matrix.projection*matrix.modelview;
|
||||
matrix.inverse_map=matrix.mvp.Inverted();
|
||||
|
||||
//注意: C++中要 projection * model_view * local_to_world * position
|
||||
//而GLSL中要 position * local_to_world * model_view * projection
|
||||
|
Loading…
x
Reference in New Issue
Block a user