mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
shaderc: Removed instMul. (#3536)
This commit is contained in:
committed by
GitHub
parent
d9d99f51ad
commit
aa94189553
@@ -10,31 +10,27 @@ $output v_wpos, v_view, v_normal, v_tangent, v_bitangent, v_texcoord0
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 model;
|
mat4 model = mtxFromCols(i_data0, i_data1, i_data2, i_data3);
|
||||||
model[0] = i_data0;
|
|
||||||
model[1] = i_data1;
|
|
||||||
model[2] = i_data2;
|
|
||||||
model[3] = i_data3;
|
|
||||||
|
|
||||||
vec3 wpos = instMul(model, vec4(a_position, 1.0) ).xyz;
|
vec3 wpos = mul(model, vec4(a_position, 1.0) ).xyz;
|
||||||
gl_Position = mul(u_viewProj, vec4(wpos, 1.0) );
|
gl_Position = mul(u_viewProj, vec4(wpos, 1.0) );
|
||||||
|
|
||||||
vec4 normal = a_normal * 2.0 - 1.0;
|
vec4 normal = a_normal * 2.0 - 1.0;
|
||||||
vec3 wnormal = instMul(model, vec4(normal.xyz, 0.0) ).xyz;
|
vec3 wnormal = mul(model, vec4(normal.xyz, 0.0) ).xyz;
|
||||||
|
|
||||||
vec4 tangent = a_tangent * 2.0 - 1.0;
|
vec4 tangent = a_tangent * 2.0 - 1.0;
|
||||||
vec3 wtangent = instMul(model, vec4(tangent.xyz, 0.0) ).xyz;
|
vec3 wtangent = mul(model, vec4(tangent.xyz, 0.0) ).xyz;
|
||||||
|
|
||||||
v_normal = wnormal;
|
v_normal = wnormal;
|
||||||
v_tangent = wtangent;
|
v_tangent = wtangent;
|
||||||
v_bitangent = cross(v_normal, v_tangent) * tangent.w;
|
v_bitangent = cross(v_normal, v_tangent) * tangent.w;
|
||||||
|
|
||||||
mat3 tbn = mat3(v_tangent, v_bitangent, v_normal);
|
mat3 tbn = mtxFromCols(v_tangent, v_bitangent, v_normal);
|
||||||
|
|
||||||
v_wpos = wpos;
|
v_wpos = wpos;
|
||||||
|
|
||||||
vec3 weyepos = mul(vec4(0.0, 0.0, 0.0, 1.0), u_view).xyz;
|
vec3 weyepos = mul(vec4(0.0, 0.0, 0.0, 1.0), u_view).xyz;
|
||||||
v_view = instMul(weyepos - wpos, tbn);
|
v_view = mul(weyepos - wpos, tbn);
|
||||||
|
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,14 +81,10 @@ void main()
|
|||||||
// --edgeFixup warp //!< This must be used on DirectX9. When fileted with 'warp', fixCubeLookup() should be used.
|
// --edgeFixup warp //!< This must be used on DirectX9. When fileted with 'warp', fixCubeLookup() should be used.
|
||||||
float mip = 1.0 + 5.0*(1.0 - inGloss); // Use mip levels [1..6] for radiance.
|
float mip = 1.0 + 5.0*(1.0 - inGloss); // Use mip levels [1..6] for radiance.
|
||||||
|
|
||||||
mat4 mtx;
|
mat4 mtx = mtxFromCols(u_mtx0, u_mtx1, u_mtx2, u_mtx3);
|
||||||
mtx[0] = u_mtx0;
|
|
||||||
mtx[1] = u_mtx1;
|
|
||||||
mtx[2] = u_mtx2;
|
|
||||||
mtx[3] = u_mtx3;
|
|
||||||
vec3 vr = 2.0*ndotv*nn - vv; // Same as: -reflect(vv, nn);
|
vec3 vr = 2.0*ndotv*nn - vv; // Same as: -reflect(vv, nn);
|
||||||
vec3 cubeR = normalize(instMul(mtx, vec4(vr, 0.0)).xyz);
|
vec3 cubeR = normalize(mul(mtx, vec4(vr, 0.0)).xyz);
|
||||||
vec3 cubeN = normalize(instMul(mtx, vec4(nn, 0.0)).xyz);
|
vec3 cubeN = normalize(mul(mtx, vec4(nn, 0.0)).xyz);
|
||||||
cubeR = fixCubeLookup(cubeR, mip, 256.0);
|
cubeR = fixCubeLookup(cubeR, mip, 256.0);
|
||||||
|
|
||||||
vec3 radiance = toLinear(textureCubeLod(s_texCube, cubeR, mip).xyz);
|
vec3 radiance = toLinear(textureCubeLod(s_texCube, cubeR, mip).xyz);
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ void main()
|
|||||||
float aspect = height*(u_viewRect.z / u_viewRect.w);
|
float aspect = height*(u_viewRect.z / u_viewRect.w);
|
||||||
vec2 tex = (2.0*a_texcoord0-1.0) * vec2(aspect, height);
|
vec2 tex = (2.0*a_texcoord0-1.0) * vec2(aspect, height);
|
||||||
|
|
||||||
mat4 mtx;
|
mat4 mtx = mtxFromCols(u_mtx0, u_mtx1, u_mtx2, u_mtx3);
|
||||||
mtx[0] = u_mtx0;
|
v_dir = mul(mtx, vec4(tex, 1.0, 0.0) ).xyz;
|
||||||
mtx[1] = u_mtx1;
|
|
||||||
mtx[2] = u_mtx2;
|
|
||||||
mtx[3] = u_mtx3;
|
|
||||||
v_dir = instMul(mtx, vec4(tex, 1.0, 0.0) ).xyz;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ void main()
|
|||||||
vec3 t = normalize(mul(u_norm_mtx, vec4(tangent, 0.0) ).xyz);
|
vec3 t = normalize(mul(u_norm_mtx, vec4(tangent, 0.0) ).xyz);
|
||||||
vec3 b = normalize(mul(u_norm_mtx, vec4(bitangent, 0.0) ).xyz);
|
vec3 b = normalize(mul(u_norm_mtx, vec4(bitangent, 0.0) ).xyz);
|
||||||
vec3 n = normalize(mul(u_norm_mtx, vec4(normal, 0.0) ).xyz);
|
vec3 n = normalize(mul(u_norm_mtx, vec4(normal, 0.0) ).xyz);
|
||||||
mat3 tbn = mat3(t, b, n);
|
mat3 tbn = mtxFromCols(t, b, n);
|
||||||
|
|
||||||
v_ts_light_pos = instMul(u_light_pos.xyz, tbn);
|
v_ts_light_pos = mul(u_light_pos.xyz, tbn);
|
||||||
// Our camera is always at the origin
|
// Our camera is always at the origin
|
||||||
v_ts_view_pos = instMul(vec3_splat(0.0), tbn);
|
v_ts_view_pos = mul(vec3_splat(0.0), tbn);
|
||||||
v_ts_frag_pos = instMul(wpos, tbn);
|
v_ts_frag_pos = mul(wpos, tbn);
|
||||||
|
|
||||||
v_texcoord0 = a_texcoord0;
|
v_texcoord0 = a_texcoord0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ $output v_materialID
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 model;
|
mat4 model = mtxFromCols(
|
||||||
model[0] = vec4(i_data0.xyz, 0.0);
|
vec4(i_data0.xyz, 0.0)
|
||||||
model[1] = i_data1;
|
, i_data1
|
||||||
model[2] = i_data2;
|
, i_data2
|
||||||
model[3] = i_data3;
|
, i_data3
|
||||||
|
);
|
||||||
|
|
||||||
v_materialID = i_data0.w;
|
v_materialID = i_data0.w;
|
||||||
|
|
||||||
vec4 worldPos = instMul(model, vec4(a_position, 1.0) );
|
vec4 worldPos = mul(model, vec4(a_position, 1.0) );
|
||||||
gl_Position = mul(u_viewProj, worldPos);
|
gl_Position = mul(u_viewProj, worldPos);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,8 @@ $input a_position, i_data0, i_data1, i_data2, i_data3, i_data4
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat4 model;
|
mat4 model = mtxFromCols(i_data0, i_data1, i_data2, i_data3);
|
||||||
model[0] = i_data0;
|
|
||||||
model[1] = i_data1;
|
|
||||||
model[2] = i_data2;
|
|
||||||
model[3] = i_data3;
|
|
||||||
|
|
||||||
vec4 worldPos = instMul(model, vec4(a_position, 1.0) );
|
vec4 worldPos = mul(model, vec4(a_position, 1.0) );
|
||||||
gl_Position = mul(u_viewProj, worldPos);
|
gl_Position = mul(u_viewProj, worldPos);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
//I decided to keep the non square matrices definition in the example, since I am still not sure how non square matrices should be treated in bgfx (Daniel Gavin)
|
|
||||||
|
|
||||||
#ifndef MATRICES_H_HEADER_GUARD
|
|
||||||
#define MATRICES_H_HEADER_GUARD
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
|
||||||
|
|
||||||
# define mat3x4 float4x3
|
|
||||||
# define mat4x3 float3x4
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_*
|
|
||||||
|
|
||||||
mat4x3 mtxFromRows(vec4 _0, vec4 _1, vec4 _2)
|
|
||||||
{
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
return transpose(mat3x4(_0, _1, _2) );
|
|
||||||
#else
|
|
||||||
return mat4x3(_0, _1, _2);
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 mtxGetRow(mat4x3 _0, uint row)
|
|
||||||
{
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
return vec4(_0[0][row], _0[1][row], _0[2][row], _0[3][row]);
|
|
||||||
#else
|
|
||||||
return vec4(_0[row]);
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 mtxGetRow(mat4 _0, uint row)
|
|
||||||
{
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
return vec4(_0[0][row], _0[1][row], _0[2][row], _0[3][row]);
|
|
||||||
#else
|
|
||||||
return vec4(_0[row]);
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 mtxGetColumn(mat4 _0, uint column)
|
|
||||||
{
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
return vec4(_0[column]);
|
|
||||||
#else
|
|
||||||
return vec4(_0[0][column], _0[1][column], _0[2][column], _0[3][column]);
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
}
|
|
||||||
|
|
||||||
float mtxGetElement(mat4 _0, uint column, uint row)
|
|
||||||
{
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
return _0[column][row];
|
|
||||||
#else
|
|
||||||
return _0[row][column];
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
|
||||||
#endif // MATRICES_H_HEADER_GUARD
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "bgfx_compute.sh"
|
#include "bgfx_compute.sh"
|
||||||
#include "matrices.sh"
|
|
||||||
#include "isubd.sh"
|
#include "isubd.sh"
|
||||||
#include "uniforms.sh"
|
#include "uniforms.sh"
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
|||||||
|
|
||||||
// construct a scale-invariant frame
|
// construct a scale-invariant frame
|
||||||
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
||||||
return mat3(T*invMax, B*invMax, N);
|
return mtxFromCols(T*invMax, B*invMax, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -47,7 +47,7 @@ void main()
|
|||||||
// perturb geometry normal by normal map
|
// perturb geometry normal by normal map
|
||||||
vec3 pos = v_texcoord2.xyz; // contains world space pos
|
vec3 pos = v_texcoord2.xyz; // contains world space pos
|
||||||
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
||||||
vec3 bumpedNormal = normalize(instMul(TBN, normalMap));
|
vec3 bumpedNormal = normalize(mul(TBN, normalMap));
|
||||||
|
|
||||||
// need some proxy for roughness value w/o roughness texture
|
// need some proxy for roughness value w/o roughness texture
|
||||||
// assume horizontal (blue) normal map is smooth, and then
|
// assume horizontal (blue) normal map is smooth, and then
|
||||||
|
|||||||
@@ -16,22 +16,22 @@ void main()
|
|||||||
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0));
|
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0));
|
||||||
|
|
||||||
// Calculate previous frame's position
|
// Calculate previous frame's position
|
||||||
mat4 worldToViewPrev = mat4(
|
mat4 worldToViewPrev = mtxFromCols(
|
||||||
u_worldToViewPrev0,
|
u_worldToViewPrev0
|
||||||
u_worldToViewPrev1,
|
, u_worldToViewPrev1
|
||||||
u_worldToViewPrev2,
|
, u_worldToViewPrev2
|
||||||
u_worldToViewPrev3
|
, u_worldToViewPrev3
|
||||||
);
|
);
|
||||||
mat4 viewToProjPrev = mat4(
|
mat4 viewToProjPrev = mtxFromCols(
|
||||||
u_viewToProjPrev0,
|
u_viewToProjPrev0
|
||||||
u_viewToProjPrev1,
|
, u_viewToProjPrev1
|
||||||
u_viewToProjPrev2,
|
, u_viewToProjPrev2
|
||||||
u_viewToProjPrev3
|
, u_viewToProjPrev3
|
||||||
);
|
);
|
||||||
|
|
||||||
vec3 wsPos = mul(u_model[0], vec4(pos, 1.0)).xyz;
|
vec3 wsPos = mul(u_model[0], vec4(pos, 1.0)).xyz;
|
||||||
vec3 vspPos = instMul(worldToViewPrev, vec4(wsPos, 1.0)).xyz;
|
vec3 vspPos = mul(worldToViewPrev, vec4(wsPos, 1.0)).xyz;
|
||||||
vec4 pspPos = instMul(viewToProjPrev, vec4(vspPos, 1.0));
|
vec4 pspPos = mul(viewToProjPrev, vec4(vspPos, 1.0));
|
||||||
|
|
||||||
// Calculate normal, unpack
|
// Calculate normal, unpack
|
||||||
vec3 osNormal = a_normal.xyz * 2.0 - 1.0;
|
vec3 osNormal = a_normal.xyz * 2.0 - 1.0;
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ void main()
|
|||||||
float initialOffset = (0.0 < u_useNoiseOffset) ? (0.5+random) : 1.0;
|
float initialOffset = (0.0 < u_useNoiseOffset) ? (0.5+random) : 1.0;
|
||||||
samplePosition += initialOffset * lightStep;
|
samplePosition += initialOffset * lightStep;
|
||||||
|
|
||||||
mat4 viewToProj = mat4(
|
mat4 viewToProj = mtxFromCols(
|
||||||
u_viewToProj0,
|
u_viewToProj0
|
||||||
u_viewToProj1,
|
, u_viewToProj1
|
||||||
u_viewToProj2,
|
, u_viewToProj2
|
||||||
u_viewToProj3
|
, u_viewToProj3
|
||||||
);
|
);
|
||||||
|
|
||||||
float occluded = 0.0;
|
float occluded = 0.0;
|
||||||
@@ -65,7 +65,7 @@ void main()
|
|||||||
float firstHit = u_shadowSteps;
|
float firstHit = u_shadowSteps;
|
||||||
for (int i = 0; i < int(u_shadowSteps); ++i, samplePosition += lightStep)
|
for (int i = 0; i < int(u_shadowSteps); ++i, samplePosition += lightStep)
|
||||||
{
|
{
|
||||||
vec3 psSamplePosition = instMul(viewToProj, vec4(samplePosition, 1.0)).xyw;
|
vec3 psSamplePosition = mul(viewToProj, vec4(samplePosition, 1.0)).xyw;
|
||||||
psSamplePosition.xy *= (1.0/psSamplePosition.z);
|
psSamplePosition.xy *= (1.0/psSamplePosition.z);
|
||||||
|
|
||||||
vec2 sampleCoord = psSamplePosition.xy * 0.5 + 0.5;
|
vec2 sampleCoord = psSamplePosition.xy * 0.5 + 0.5;
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ void main()
|
|||||||
float roughness = normalRoughness.w;
|
float roughness = normalRoughness.w;
|
||||||
|
|
||||||
// transform normal into view space
|
// transform normal into view space
|
||||||
mat4 worldToView = mat4(
|
mat4 worldToView = mtxFromCols(
|
||||||
u_worldToView0,
|
u_worldToView0
|
||||||
u_worldToView1,
|
, u_worldToView1
|
||||||
u_worldToView2,
|
, u_worldToView2
|
||||||
u_worldToView3
|
, u_worldToView3
|
||||||
);
|
);
|
||||||
vec3 vsNormal = instMul(worldToView, vec4(normal, 0.0)).xyz;
|
vec3 vsNormal = mul(worldToView, vec4(normal, 0.0)).xyz;
|
||||||
|
|
||||||
// read depth and recreate position
|
// read depth and recreate position
|
||||||
float linearDepth = texture2D(s_depth, texCoord).x;
|
float linearDepth = texture2D(s_depth, texCoord).x;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
|||||||
|
|
||||||
// construct a scale-invariant frame
|
// construct a scale-invariant frame
|
||||||
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
||||||
return mat3(T*invMax, B*invMax, N);
|
return mtxFromCols(T*invMax, B*invMax, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -47,7 +47,7 @@ void main()
|
|||||||
// perturb geometry normal by normal map
|
// perturb geometry normal by normal map
|
||||||
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
||||||
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
||||||
vec3 bumpedNormal = normalize(instMul(TBN, normalMap));
|
vec3 bumpedNormal = normalize(mul(TBN, normalMap));
|
||||||
|
|
||||||
// need some proxy for roughness value w/o roughness texture
|
// need some proxy for roughness value w/o roughness texture
|
||||||
// assume horizontal (blue) normal map is smooth, and then
|
// assume horizontal (blue) normal map is smooth, and then
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ uniform vec4 u_modelParams[2];
|
|||||||
#define u_color (u_modelParams[0].xyz)
|
#define u_color (u_modelParams[0].xyz)
|
||||||
#define u_lightPosition (u_modelParams[1].xyz)
|
#define u_lightPosition (u_modelParams[1].xyz)
|
||||||
|
|
||||||
|
|
||||||
// http://www.thetenthplanet.de/archives/1180
|
// http://www.thetenthplanet.de/archives/1180
|
||||||
// "followup: normal mapping without precomputed tangents"
|
// "followup: normal mapping without precomputed tangents"
|
||||||
mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
||||||
@@ -35,7 +34,7 @@ mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
|||||||
|
|
||||||
// construct a scale-invariant frame
|
// construct a scale-invariant frame
|
||||||
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
||||||
return mat3(T*invMax, B*invMax, N);
|
return mtxFromCols(T*invMax, B*invMax, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -57,7 +56,7 @@ void main()
|
|||||||
// perturb geometry normal by normal map
|
// perturb geometry normal by normal map
|
||||||
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
||||||
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
||||||
vec3 bumpedNormal = normalize(instMul(TBN, normalMap));
|
vec3 bumpedNormal = normalize(mul(TBN, normalMap));
|
||||||
|
|
||||||
vec3 light = (u_lightPosition - pos);
|
vec3 light = (u_lightPosition - pos);
|
||||||
light = normalize(light);
|
light = normalize(light);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)
|
|||||||
|
|
||||||
// construct a scale-invariant frame
|
// construct a scale-invariant frame
|
||||||
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
float invMax = inversesqrt(max(dot(T,T), dot(B,B)));
|
||||||
return mat3(T*invMax, B*invMax, N);
|
return mtxFromCols(T*invMax, B*invMax, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -56,7 +56,7 @@ void main()
|
|||||||
// perturb geometry normal by normal map
|
// perturb geometry normal by normal map
|
||||||
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
vec3 pos = v_texcoord1.xyz; // contains world space pos
|
||||||
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
mat3 TBN = cotangentFrame(normal, pos, v_texcoord0);
|
||||||
vec3 bumpedNormal = normalize(instMul(TBN, normalMap));
|
vec3 bumpedNormal = normalize(mul(TBN, normalMap));
|
||||||
|
|
||||||
vec3 light = (u_lightPosition - pos);
|
vec3 light = (u_lightPosition - pos);
|
||||||
light = normalize(light);
|
light = normalize(light);
|
||||||
|
|||||||
@@ -14,13 +14,15 @@
|
|||||||
# error "Compute is not supported!"
|
# error "Compute is not supported!"
|
||||||
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV
|
#if BGFX_SHADER_LANGUAGE_METAL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_WGSL
|
||||||
# define FORMAT(_format) [[spv::format_ ## _format]]
|
# define FORMAT(_format) [[spv::format_ ## _format]]
|
||||||
# define WRITEONLY [[spv::nonreadable]]
|
# define WRITEONLY [[spv::nonreadable]]
|
||||||
#else
|
#else
|
||||||
# define FORMAT(_format)
|
# define FORMAT(_format)
|
||||||
# define WRITEONLY
|
# define WRITEONLY
|
||||||
#endif // BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV
|
#endif // BGFX_SHADER_LANGUAGE_*
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
|
||||||
@@ -148,7 +150,9 @@
|
|||||||
|
|
||||||
#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg)
|
#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg)
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV
|
#if BGFX_SHADER_LANGUAGE_METAL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_WGSL
|
||||||
#define BUFFER_RO(_name, _struct, _reg) StructuredBuffer<_struct> _name : REGISTER(t, _reg)
|
#define BUFFER_RO(_name, _struct, _reg) StructuredBuffer<_struct> _name : REGISTER(t, _reg)
|
||||||
#define BUFFER_RW(_name, _struct, _reg) RWStructuredBuffer <_struct> _name : REGISTER(u, _reg)
|
#define BUFFER_RW(_name, _struct, _reg) RWStructuredBuffer <_struct> _name : REGISTER(u, _reg)
|
||||||
#define BUFFER_WO(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg)
|
#define BUFFER_WO(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg)
|
||||||
@@ -156,7 +160,7 @@
|
|||||||
#define BUFFER_RO(_name, _struct, _reg) Buffer<_struct> _name : REGISTER(t, _reg)
|
#define BUFFER_RO(_name, _struct, _reg) Buffer<_struct> _name : REGISTER(t, _reg)
|
||||||
#define BUFFER_RW(_name, _struct, _reg) RWBuffer<_struct> _name : REGISTER(u, _reg)
|
#define BUFFER_RW(_name, _struct, _reg) RWBuffer<_struct> _name : REGISTER(u, _reg)
|
||||||
#define BUFFER_WO(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg)
|
#define BUFFER_WO(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg)
|
||||||
#endif
|
#endif // BGFX_SHADER_LANGUAGE_*
|
||||||
|
|
||||||
#define NUM_THREADS(_x, _y, _z) [numthreads(_x, _y, _z)]
|
#define NUM_THREADS(_x, _y, _z) [numthreads(_x, _y, _z)]
|
||||||
|
|
||||||
@@ -249,13 +253,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define __IMAGE_IMPL_ATOMIC(_format, _storeComponents, _type, _loadComponents) \
|
#define __IMAGE_IMPL_ATOMIC(_format, _storeComponents, _type, _loadComponents) \
|
||||||
\
|
|
||||||
void imageAtomicAdd(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \
|
void imageAtomicAdd(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \
|
||||||
{ \
|
{ \
|
||||||
InterlockedAdd(_image[_uv], _value._storeComponents); \
|
InterlockedAdd(_image[_uv], _value._storeComponents); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
|
||||||
__IMAGE_IMPL_A(float, x, vec4, xxxx)
|
__IMAGE_IMPL_A(float, x, vec4, xxxx)
|
||||||
__IMAGE_IMPL_A(float2, xy, vec4, xyyy)
|
__IMAGE_IMPL_A(float2, xy, vec4, xyyy)
|
||||||
__IMAGE_IMPL_A(float4, xyzw, vec4, xyzw)
|
__IMAGE_IMPL_A(float4, xyzw, vec4, xyzw)
|
||||||
@@ -268,11 +270,10 @@ __IMAGE_IMPL_A(uint4, xyzw, uvec4, xyzw)
|
|||||||
__IMAGE_IMPL_A(unorm float, x, vec4, xxxx)
|
__IMAGE_IMPL_A(unorm float, x, vec4, xxxx)
|
||||||
__IMAGE_IMPL_A(unorm float2, xy, vec4, xyyy)
|
__IMAGE_IMPL_A(unorm float2, xy, vec4, xyyy)
|
||||||
__IMAGE_IMPL_A(unorm float4, xyzw, vec4, xyzw)
|
__IMAGE_IMPL_A(unorm float4, xyzw, vec4, xyzw)
|
||||||
#endif
|
#endif // BGFX_SHADER_LANGUAGE_HLSL
|
||||||
|
|
||||||
__IMAGE_IMPL_ATOMIC(uint, x, uvec4, xxxx)
|
__IMAGE_IMPL_ATOMIC(uint, x, uvec4, xxxx)
|
||||||
|
|
||||||
|
|
||||||
#define atomicAdd(_mem, _data) InterlockedAdd(_mem, _data)
|
#define atomicAdd(_mem, _data) InterlockedAdd(_mem, _data)
|
||||||
#define atomicAnd(_mem, _data) InterlockedAnd(_mem, _data)
|
#define atomicAnd(_mem, _data) InterlockedAnd(_mem, _data)
|
||||||
#define atomicMax(_mem, _data) InterlockedMax(_mem, _data)
|
#define atomicMax(_mem, _data) InterlockedMax(_mem, _data)
|
||||||
|
|||||||
@@ -12,21 +12,29 @@
|
|||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_HLSL > 300
|
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||||
# define BRANCH [branch]
|
|
||||||
# define LOOP [loop]
|
|
||||||
# define UNROLL [unroll]
|
|
||||||
#else
|
|
||||||
# define BRANCH
|
# define BRANCH
|
||||||
# define LOOP
|
# define LOOP
|
||||||
# define UNROLL
|
# define UNROLL
|
||||||
|
#else
|
||||||
|
# define BRANCH [branch]
|
||||||
|
# define LOOP [loop]
|
||||||
|
# define UNROLL [unroll]
|
||||||
#endif // BGFX_SHADER_LANGUAGE_HLSL > 300
|
#endif // BGFX_SHADER_LANGUAGE_HLSL > 300
|
||||||
|
|
||||||
#if (BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV) && BGFX_SHADER_TYPE_FRAGMENT
|
#define BGFX_SHADER_MATRIX_COLUMN_MAJOR (0 \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_GLSL \
|
||||||
|
)
|
||||||
|
|
||||||
|
#if BGFX_SHADER_TYPE_FRAGMENT
|
||||||
|
# if BGFX_SHADER_LANGUAGE_HLSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_METAL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV
|
||||||
# define EARLY_DEPTH_STENCIL [earlydepthstencil]
|
# define EARLY_DEPTH_STENCIL [earlydepthstencil]
|
||||||
#else
|
#else
|
||||||
# define EARLY_DEPTH_STENCIL
|
# define EARLY_DEPTH_STENCIL
|
||||||
#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT
|
# endif // BGFX_SHADER_LANGUAGE_...
|
||||||
|
#endif // BGFX_SHADER_TYPE_FRAGMENT
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||||
# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[](
|
# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[](
|
||||||
@@ -52,26 +60,32 @@
|
|||||||
|
|
||||||
// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around
|
// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around
|
||||||
// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk).
|
// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk).
|
||||||
# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
# if BGFX_SHADER_LANGUAGE_HLSL > 400 \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_PSSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_METAL
|
||||||
# define REGISTER(_type, _reg) register( _type[_reg] )
|
# define REGISTER(_type, _reg) register( _type[_reg] )
|
||||||
# else
|
# else
|
||||||
# define REGISTER(_type, _reg) register(_type ## _reg)
|
# define REGISTER(_type, _reg) register(_type ## _reg)
|
||||||
# endif // BGFX_SHADER_LANGUAGE_HLSL
|
# endif // BGFX_SHADER_LANGUAGE_HLSL
|
||||||
|
|
||||||
# if BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
# if BGFX_SHADER_LANGUAGE_HLSL > 400 \
|
||||||
# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
|| BGFX_SHADER_LANGUAGE_PSSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_METAL
|
||||||
# define dFdxCoarse(_x) ddx_coarse(_x)
|
# define dFdxCoarse(_x) ddx_coarse(_x)
|
||||||
# define dFdxFine(_x) ddx_fine(_x)
|
# define dFdxFine(_x) ddx_fine(_x)
|
||||||
# define dFdyCoarse(_y) ddy_coarse(-(_y))
|
# define dFdyCoarse(_y) ddy_coarse(-(_y))
|
||||||
# define dFdyFine(_y) ddy_fine(-(_y))
|
# define dFdyFine(_y) ddy_fine(-(_y))
|
||||||
# endif // BGFX_SHADER_LANGUAGE_HLSL > 400
|
|
||||||
|
|
||||||
# if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
# if BGFX_SHADER_LANGUAGE_HLSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_METAL
|
||||||
float intBitsToFloat(int _x) { return asfloat(_x); }
|
float intBitsToFloat(int _x) { return asfloat(_x); }
|
||||||
vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); }
|
vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); }
|
||||||
vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); }
|
vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); }
|
||||||
vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); }
|
vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); }
|
||||||
# endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
# endif // BGFX_SHADER_LANGUAGE_*
|
||||||
|
|
||||||
float uintBitsToFloat(uint _x) { return asfloat(_x); }
|
float uintBitsToFloat(uint _x) { return asfloat(_x); }
|
||||||
vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); }
|
vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); }
|
||||||
@@ -571,11 +585,6 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord)
|
|||||||
|
|
||||||
# endif // BGFX_SHADER_LANGUAGE_HLSL > 300
|
# endif // BGFX_SHADER_LANGUAGE_HLSL > 300
|
||||||
|
|
||||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); }
|
|
||||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); }
|
|
||||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); }
|
|
||||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); }
|
|
||||||
|
|
||||||
bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; }
|
bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; }
|
||||||
bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; }
|
bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; }
|
||||||
bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; }
|
bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; }
|
||||||
@@ -613,7 +622,6 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
|
|||||||
#else
|
#else
|
||||||
# define CONST(_x) const _x
|
# define CONST(_x) const _x
|
||||||
# define atan2(_x, _y) atan(_x, _y)
|
# define atan2(_x, _y) atan(_x, _y)
|
||||||
# define mul(_a, _b) ( (_a) * (_b) )
|
|
||||||
# define saturate(_x) clamp(_x, 0.0, 1.0)
|
# define saturate(_x) clamp(_x, 0.0, 1.0)
|
||||||
# define SAMPLER2D(_name, _reg) uniform sampler2D _name
|
# define SAMPLER2D(_name, _reg) uniform sampler2D _name
|
||||||
# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name
|
# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name
|
||||||
@@ -645,11 +653,6 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
|
|||||||
# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias)
|
# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias)
|
||||||
# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130
|
# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130
|
||||||
|
|
||||||
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
|
|
||||||
vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); }
|
|
||||||
vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); }
|
|
||||||
vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); }
|
|
||||||
|
|
||||||
float rcp(float _a) { return 1.0/_a; }
|
float rcp(float _a) { return 1.0/_a; }
|
||||||
vec2 rcp(vec2 _a) { return vec2(1.0)/_a; }
|
vec2 rcp(vec2 _a) { return vec2(1.0)/_a; }
|
||||||
vec3 rcp(vec3 _a) { return vec3(1.0)/_a; }
|
vec3 rcp(vec3 _a) { return vec3(1.0)/_a; }
|
||||||
@@ -660,56 +663,144 @@ vec2 vec2_splat(float _x) { return vec2(_x, _x); }
|
|||||||
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
|
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
|
||||||
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }
|
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_HLSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_PSSL \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_SPIRV \
|
||||||
|
|| BGFX_SHADER_LANGUAGE_METAL
|
||||||
uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); }
|
uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); }
|
||||||
uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); }
|
uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); }
|
||||||
uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); }
|
uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); }
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL
|
#endif // BGFX_SHADER_LANGUAGE_*
|
||||||
|
|
||||||
|
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
# define mul(_a, _b) ( (_a) * (_b) )
|
||||||
|
#else
|
||||||
|
# define mul(_a, _b) mul(_a, _b)
|
||||||
|
# define mat3x4 float4x3
|
||||||
|
# define mat4x3 float3x4
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_*
|
||||||
|
|
||||||
mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3)
|
mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3)
|
||||||
{
|
{
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
return transpose(mat4(_0, _1, _2, _3) );
|
return transpose(mat4(_0, _1, _2, _3) );
|
||||||
#else
|
#else
|
||||||
return mat4(_0, _1, _2, _3);
|
return mat4(_0, _1, _2, _3);
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3)
|
mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3)
|
||||||
{
|
{
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
return mat4(_0, _1, _2, _3);
|
return mat4(_0, _1, _2, _3);
|
||||||
#else
|
#else
|
||||||
return transpose(mat4(_0, _1, _2, _3) );
|
return transpose(mat4(_0, _1, _2, _3) );
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
}
|
}
|
||||||
|
|
||||||
mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2)
|
mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2)
|
||||||
{
|
{
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
return transpose(mat3(_0, _1, _2) );
|
return transpose(mat3(_0, _1, _2) );
|
||||||
#else
|
#else
|
||||||
return mat3(_0, _1, _2);
|
return mat3(_0, _1, _2);
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
}
|
}
|
||||||
|
|
||||||
mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2)
|
mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2)
|
||||||
{
|
{
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
return mat3(_0, _1, _2);
|
return mat3(_0, _1, _2);
|
||||||
#else
|
#else
|
||||||
return transpose(mat3(_0, _1, _2) );
|
return transpose(mat3(_0, _1, _2) );
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
#if !BGFX_SHADER_LANGUAGE_ESSL
|
||||||
#define mtxFromRows3(_0, _1, _2) transpose(mat3(_0, _1, _2) )
|
mat4x3 mtxFromRows(vec4 _0, vec4 _1, vec4 _2)
|
||||||
#define mtxFromRows4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) )
|
{
|
||||||
#define mtxFromCols3(_0, _1, _2) mat3(_0, _1, _2)
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
#define mtxFromCols4(_0, _1, _2, _3) mat4(_0, _1, _2, _3)
|
return transpose(mat3x4(_0, _1, _2) );
|
||||||
#else
|
#else
|
||||||
#define mtxFromRows3(_0, _1, _2) mat3(_0, _1, _2)
|
return mat4x3(_0, _1, _2);
|
||||||
#define mtxFromRows4(_0, _1, _2, _3) mat4(_0, _1, _2, _3)
|
|
||||||
#define mtxFromCols3(_0, _1, _2) transpose(mat3(_0, _1, _2) )
|
|
||||||
#define mtxFromCols4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) )
|
|
||||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
#endif // !BGFX_SHADER_LANGUAGE_ESSL
|
||||||
|
|
||||||
|
vec3 mtxGetRow(mat3 _mtx, int _row)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec3(_mtx[0][_row], _mtx[1][_row], _mtx[2][_row]);
|
||||||
|
#else
|
||||||
|
return vec3(_mtx[_row]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 mtxGetColumn(mat3 _mtx, int _column)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec3(_mtx[_column]);
|
||||||
|
#else
|
||||||
|
return vec3(_mtx[0][_column], _mtx[1][_column], _mtx[2][_column]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !BGFX_SHADER_LANGUAGE_ESSL
|
||||||
|
vec4 mtxGetRow(mat4x3 _mtx, int _row)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec4(_mtx[0][_row], _mtx[1][_row], _mtx[2][_row], _mtx[3][_row]);
|
||||||
|
#else
|
||||||
|
return vec4(_mtx[_row]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 mtxGetColumn(mat4x3 _mtx, int _column)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec3(_mtx[_column]);
|
||||||
|
#else
|
||||||
|
return vec3(_mtx[0][_column], _mtx[1][_column], _mtx[2][_column]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
#endif // !BGFX_SHADER_LANGUAGE_ESSL
|
||||||
|
|
||||||
|
vec4 mtxGetRow(mat4 _mtx, int _row)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec4(_mtx[0][_row], _mtx[1][_row], _mtx[2][_row], _mtx[3][_row]);
|
||||||
|
#else
|
||||||
|
return vec4(_mtx[_row]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 mtxGetColumn(mat4 _mtx, int _column)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return vec4(_mtx[_column]);
|
||||||
|
#else
|
||||||
|
return vec4(_mtx[0][_column], _mtx[1][_column], _mtx[2][_column], _mtx[3][_column]);
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
float mtxGetElement(mat3 _mtx, int _column, int _row)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return _mtx[_column][_row];
|
||||||
|
#else
|
||||||
|
return _mtx[_row][_column];
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
|
float mtxGetElement(mat4 _mtx, int _column, int _row)
|
||||||
|
{
|
||||||
|
#if BGFX_SHADER_MATRIX_COLUMN_MAJOR
|
||||||
|
return _mtx[_column][_row];
|
||||||
|
#else
|
||||||
|
return _mtx[_row][_column];
|
||||||
|
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||||
|
}
|
||||||
|
|
||||||
uniform vec4 u_viewRect;
|
uniform vec4 u_viewRect;
|
||||||
uniform vec4 u_viewTexel;
|
uniform vec4 u_viewTexel;
|
||||||
@@ -719,12 +810,12 @@ uniform mat4 u_proj;
|
|||||||
uniform mat4 u_invProj;
|
uniform mat4 u_invProj;
|
||||||
uniform mat4 u_viewProj;
|
uniform mat4 u_viewProj;
|
||||||
uniform mat4 u_invViewProj;
|
uniform mat4 u_invViewProj;
|
||||||
uniform mat4 u_model[BGFX_CONFIG_MAX_BONES];
|
|
||||||
uniform mat4 u_modelView;
|
uniform mat4 u_modelView;
|
||||||
uniform mat4 u_invModelView;
|
uniform mat4 u_invModelView;
|
||||||
uniform mat4 u_modelViewProj;
|
uniform mat4 u_modelViewProj;
|
||||||
uniform vec4 u_alphaRef4;
|
uniform vec4 u_alphaRef4;
|
||||||
#define u_alphaRef u_alphaRef4.x
|
#define u_alphaRef u_alphaRef4.x
|
||||||
|
uniform mat4 u_model[BGFX_CONFIG_MAX_BONES];
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
|||||||
@@ -796,11 +796,14 @@ namespace bgfx
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setDefine(const char* _define)
|
void setDefine(const char* _define)
|
||||||
|
{
|
||||||
|
if (0 != bx::strLen(_define) )
|
||||||
{
|
{
|
||||||
m_tagptr->tag = FPPTAG_DEFINE;
|
m_tagptr->tag = FPPTAG_DEFINE;
|
||||||
m_tagptr->data = scratch(_define);
|
m_tagptr->data = scratch(_define);
|
||||||
m_tagptr++;
|
m_tagptr++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setDefaultDefine(const char* _name)
|
void setDefaultDefine(const char* _name)
|
||||||
{
|
{
|
||||||
@@ -1172,6 +1175,7 @@ namespace bgfx
|
|||||||
preprocessor.setDefaultDefine("BX_PLATFORM_XBOXONE");
|
preprocessor.setDefaultDefine("BX_PLATFORM_XBOXONE");
|
||||||
|
|
||||||
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_GLSL");
|
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_GLSL");
|
||||||
|
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_ESSL");
|
||||||
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_HLSL");
|
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_HLSL");
|
||||||
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_METAL");
|
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_METAL");
|
||||||
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_PSSL");
|
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_PSSL");
|
||||||
@@ -1181,7 +1185,10 @@ namespace bgfx
|
|||||||
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_FRAGMENT");
|
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_FRAGMENT");
|
||||||
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_VERTEX");
|
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_VERTEX");
|
||||||
|
|
||||||
char glslDefine[128];
|
char glslDefine[128] = { '\0' };
|
||||||
|
char esslDefine[128] = { '\0' };
|
||||||
|
char hlslDefine[128] = { '\0' };
|
||||||
|
|
||||||
if (profile->lang == ShadingLang::GLSL
|
if (profile->lang == ShadingLang::GLSL
|
||||||
|| profile->lang == ShadingLang::ESSL)
|
|| profile->lang == ShadingLang::ESSL)
|
||||||
{
|
{
|
||||||
@@ -1189,9 +1196,16 @@ namespace bgfx
|
|||||||
, "BGFX_SHADER_LANGUAGE_GLSL=%d"
|
, "BGFX_SHADER_LANGUAGE_GLSL=%d"
|
||||||
, profile->id
|
, profile->id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (profile->lang == ShadingLang::ESSL)
|
||||||
|
{
|
||||||
|
bx::snprintf(esslDefine, BX_COUNTOF(esslDefine)
|
||||||
|
, "BGFX_SHADER_LANGUAGE_ESSL=%d"
|
||||||
|
, profile->id
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char hlslDefine[128];
|
|
||||||
if (profile->lang == ShadingLang::HLSL)
|
if (profile->lang == ShadingLang::HLSL)
|
||||||
{
|
{
|
||||||
bx::snprintf(hlslDefine, BX_COUNTOF(hlslDefine)
|
bx::snprintf(hlslDefine, BX_COUNTOF(hlslDefine)
|
||||||
@@ -1211,12 +1225,14 @@ namespace bgfx
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (0 == bx::strCmpI(platform, "asm.js") )
|
else if (0 == bx::strCmpI(platform, "asm.js") )
|
||||||
{
|
{
|
||||||
preprocessor.setDefine("BX_PLATFORM_EMSCRIPTEN=1");
|
preprocessor.setDefine("BX_PLATFORM_EMSCRIPTEN=1");
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
else if (0 == bx::strCmpI(platform, "linux") )
|
else if (0 == bx::strCmpI(platform, "linux") )
|
||||||
{
|
{
|
||||||
@@ -1229,6 +1245,7 @@ namespace bgfx
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (0 == bx::strCmpI(platform, "ios")
|
else if (0 == bx::strCmpI(platform, "ios")
|
||||||
@@ -1252,7 +1269,9 @@ namespace bgfx
|
|||||||
if (profile->lang != ShadingLang::Metal)
|
if (profile->lang != ShadingLang::Metal)
|
||||||
{
|
{
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
|
|
||||||
char temp[32];
|
char temp[32];
|
||||||
bx::snprintf(
|
bx::snprintf(
|
||||||
temp
|
temp
|
||||||
@@ -1273,6 +1292,7 @@ namespace bgfx
|
|||||||
|| profile->lang == ShadingLang::ESSL)
|
|| profile->lang == ShadingLang::ESSL)
|
||||||
{
|
{
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
else if (profile->lang == ShadingLang::SpirV)
|
else if (profile->lang == ShadingLang::SpirV)
|
||||||
{
|
{
|
||||||
@@ -1295,6 +1315,7 @@ namespace bgfx
|
|||||||
|| profile->lang == ShadingLang::ESSL)
|
|| profile->lang == ShadingLang::ESSL)
|
||||||
{
|
{
|
||||||
preprocessor.setDefine(glslDefine);
|
preprocessor.setDefine(glslDefine);
|
||||||
|
preprocessor.setDefine(esslDefine);
|
||||||
}
|
}
|
||||||
else if (profile->lang == ShadingLang::SpirV)
|
else if (profile->lang == ShadingLang::SpirV)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user