Add SP for correct normal and easier shader system

This commit is contained in:
Benau 2017-12-25 14:00:10 +08:00
parent a55e7d204a
commit 7797115867
243 changed files with 15742 additions and 9498 deletions

View File

@ -175,6 +175,9 @@ if(NOT SERVER_ONLY AND NOT USE_GLES2)
include_directories("${PROJECT_SOURCE_DIR}/lib/graphics_utils")
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/libsquish")
include_directories("${PROJECT_SOURCE_DIR}/lib/libsquish")
# Build the irrlicht library
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/irrlicht")
include_directories("${PROJECT_SOURCE_DIR}/lib/irrlicht/include")
@ -426,6 +429,10 @@ if(NOT SERVER_ONLY)
endif()
endif()
if(NOT SERVER_ONLY AND NOT USE_GLES2)
target_link_libraries(supertuxkart squish)
endif()
if(UNIX AND NOT APPLE)
if(USE_LIBBFD)
target_link_libraries(supertuxkart ${LIBBFD_LIBRARIES})
@ -440,6 +447,10 @@ if(BUILD_RECORDER)
target_link_libraries(supertuxkart ${OPENGLRECORDER_LIBRARY})
endif()
if(TEX_COMPRESS)
target_link_libraries(supertuxkart ${TC_LIBRARY})
endif()
# FreeBSD does not search in /usr/local/lib, but at least Freetype is installed there :(
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")

View File

@ -2,19 +2,17 @@
<graphical-restrictions>
<card is="Intel(R) HD Graphics" os="windows" version="<9.0" disable="ForceLegacyDevice"/>
<card is="Intel(R) HD Graphics" os="windows" version="<9.0" disable="HighDefinitionTextures"/>
<card is="Intel(R) HD Graphics 2000" os="windows" disable="UniformBufferObject"/>
<card is="Intel(R) HD Graphics 2000" os="windows" disable="FramebufferSRGB"/>
<card is="Intel(R) HD Graphics 2000" os="windows" disable="10BitVector"/>
<card is="Intel(R) HD Graphics 2000" os="windows" disable="HighDefinitionTextures"/>
<card is="Intel(R) HD Graphics 3000" os="windows" disable="UniformBufferObject"/>
<card is="Intel(R) HD Graphics 3000" os="windows" disable="FramebufferSRGB"/>
<card is="Intel(R) HD Graphics 3000" os="windows" disable="10BitVector"/>
<card is="Intel(R) HD Graphics 3000" os="windows" disable="HighDefinitionTextures"/>
<card is="Intel(R) HD Graphics 4600" os="windows" disable="ComputeShader"/>
<card contains="Intel" os="osx" disable="GI"/>
<card contains="Intel" os="linux" version="<11.2" disable="ComputeShader"/>
<card contains="Intel" os="linux" version="<11.2" disable="GeometryShader"/>
<card contains="Intel" os="linux" disable="FramebufferSRGBWorkaround2"/>
<card contains="Ivybridge" os="linux" disable="10BitVector"/>
<card contains="Sandybridge" os="linux" disable="10BitVector"/>
<card contains="Intel" os="linux" version="<11.2" disable="TextureCompressionS3TC"/>
<card contains="Intel" os="windows" disable="TextureCompressionS3TC"/>
<card contains="Intel" os="osx" disable="TextureCompressionS3TC"/>
<card contains="NVIDIA" os="windows" version="<344.65" disable="BufferStorage"/>
<card contains="NVIDIA" os="linux" version="<343.22" disable="BufferStorage"/>
@ -37,6 +35,5 @@
<card os="android" disable="ColorBufferFloat"/>
<card contains="Adreno" os="android" version="<=19" disable="VertexIdWorking"/>
<card contains="Android Emulator" os="android" disable="ForceLegacyDevice"/>
<card os="android" disable="UniformBufferObject"/>
<card vendor="Broadcom" os="linux" disable="HighDefinitionTextures256"/>
</graphical-restrictions>

View File

@ -9,7 +9,6 @@
handled as one, so list it here -->
<bubblegum model="bubblegum.spm" lowmodel="bubblegum-low.spm" glow="246 150 209"/>
<bubblegum-nolok model="bubblegum-nolok.spm" lowmodel="bubblegum-nolok-low.spm"/>
<!-- <easter-egg model="easter_egg.spm" /> -->
<easter-egg model="easter_egg.spm" />
<easter-egg model="easter_egg.spm" glow="0 60 120" />
</items>

View File

@ -16,14 +16,14 @@ out vec4 Spec;
void main(void)
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec3 normal = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
Diff = vec4(0.25 * DiffuseIBL(normal), 1.);
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec3 eyedir = -normalize(xpos.xyz);
float specval = texture(ntex, uv).z;

View File

@ -54,10 +54,10 @@ void main()
for (int j = 0; j < 8; j++) {
vec2 uv = (start_xy + vec2(i, j) * gl_WorkGroupID.xy) / screen;
vec2 uv = (start_xy + vec2(i, j) * gl_WorkGroupID.xy) / u_screen;
float z = texture(depth, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec4 lightcoord = InverseViewMatrix * xpos;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec4 lightcoord = u_inverse_view_matrix * xpos;
lightcoord /= lightcoord.w;
lightcoord = SunCamMatrix * lightcoord;
lightcoord /= lightcoord.w;

View File

@ -54,12 +54,12 @@ void main(void)
vec3 newquadcorner = vec3(size * quadcorner, 0.0);
newquadcorner = newquadcorner + 2.0 * cross(cross(newquadcorner,
quat.xyz) + quat.w * newquadcorner, quat.xyz);
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
viewpos = u_view_matrix * vec4(Position + newquadcorner, 1.0);
}
else
{
viewpos = ViewMatrix * vec4(Position, 1.0);
viewpos = u_view_matrix * vec4(Position, 1.0);
viewpos += vec4(size * quadcorner, 0.0, 0.0);
}
gl_Position = ProjectionMatrix * viewpos;
gl_Position = u_projection_matrix * viewpos;
}

View File

@ -8,7 +8,7 @@ out vec4 FragColor;
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec4 col = .125 * texture(tex_128, uv);
col += .25 * texture(tex_256, uv);
col += .5 * texture(tex_512, uv);

View File

@ -0,0 +1,39 @@
uniform sampler2D diffuse_map;
uniform sampler2D specular_map;
uniform sampler2D ssao_tex;
uniform sampler2D gloss_map;
uniform sampler2D diffuse_color;
uniform sampler2D depth_stencil;
out vec4 o_final_color;
#stk_include "utils/getPosFromUVDepth.frag"
void main()
{
vec2 tc = gl_FragCoord.xy / u_screen;
vec4 diffuseMatColor = texture(diffuse_color, tc);
// Gloss map here is stored in red and green for spec and emit map
// Real gloss channel is stored in normal and depth framebuffer .z
float specMapValue = texture(gloss_map, tc).x;
float emitMapValue = texture(gloss_map, tc).y;
float ao = texture(ssao_tex, tc).x;
vec3 DiffuseComponent = texture(diffuse_map, tc).xyz;
vec3 SpecularComponent = texture(specular_map, tc).xyz;
vec3 tmp = diffuseMatColor.xyz * DiffuseComponent * (1. - specMapValue) + SpecularComponent * specMapValue;
vec3 emitCol = diffuseMatColor.xyz * diffuseMatColor.xyz * diffuseMatColor.xyz * 15.;
vec4 color_1 = vec4(tmp * ao + (emitMapValue * emitCol), diffuseMatColor.a);
// Fog
float z = texture(depth_stencil, tc).x;
vec4 xpos = getPosFromUVDepth(vec3(tc, z), u_inverse_projection_matrix);
float dist = length(xpos.xyz);
// fog density
float factor = (1.0 - exp(u_fog_data.w * dist));
vec3 fog = u_fog_color.xyz * factor;
// Additively blend the color by fog
o_final_color = color_1 + vec4(fog, factor);
}

View File

@ -15,7 +15,7 @@ out vec4 Spec;
void main(void)
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec3 normal = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
Diff = vec4(0.25 * DiffuseIBL(normal), 1.);

View File

@ -35,7 +35,7 @@ void main()
shift.y = -shiftval.z + shiftval.w;
shift /= 50.;
vec2 tc = gl_FragCoord.xy / screen;
vec2 tc = gl_FragCoord.xy / u_screen;
float mask = texture(mask_tex, tc + shift).x;
tc += (mask < 1.) ? vec2(0.) : shift;

View File

@ -9,15 +9,15 @@ float range = 100.;
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float curdepth = texture(dtex, uv).x;
vec4 FragPos = InverseProjectionMatrix * (2.0 * vec4(uv, curdepth, 1.0) - 1.0);
vec4 FragPos = u_inverse_projection_matrix * (2.0 * vec4(uv, curdepth, 1.0) - 1.0);
FragPos /= FragPos.w;
float depth = FragPos.z;
float blur = clamp(abs(depth - focalDepth) / range, -maxblur, maxblur);
vec2 offset = 10. / screen;
vec2 offset = 10. / u_screen;
vec4 col = texture(tex, uv);
vec4 colOriginal = col;

View File

@ -4,5 +4,5 @@ layout(location = 0) in vec3 Position;
void main(void)
{
gl_Position = ShadowViewProjMatrixes[idx] * vec4(Position, 1.);
gl_Position = u_shadow_projection_view_matrices[idx] * vec4(Position, 1.);
}

View File

@ -37,18 +37,18 @@ vec3 resolution = vec3(32, 16, 32);
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec3 GI = vec3(0.);
float depth = texture2D(dtex, uv).x;
// Discard background fragments
if (depth==1.0) discard;
vec4 pos_screen_space = getPosFromUVDepth(vec3(uv, depth), InverseProjectionMatrix);
vec4 tmp = (InvRHMatrix * InverseViewMatrix * pos_screen_space);
vec4 pos_screen_space = getPosFromUVDepth(vec3(uv, depth), u_inverse_projection_matrix);
vec4 tmp = (InvRHMatrix * u_inverse_view_matrix * pos_screen_space);
vec3 pos = tmp.xyz / tmp.w;
vec3 normal_screen_space = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
vec3 normal = (transpose(ViewMatrix) * vec4(normal_screen_space, 0.)).xyz;
vec3 normal = (transpose(u_view_matrix) * vec4(normal_screen_space, 0.)).xyz;
// Convert to grid coordinates
vec3 uvw = .5 + 0.5 * pos / extents;

View File

@ -18,7 +18,7 @@ flat out vec4 glowColor;
void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix);
gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * u_inverse_view_matrix);
gl_Position = u_projection_view_matrix * ModelMatrix * vec4(Position, 1.);
glowColor = misc_data;
}

View File

@ -6,7 +6,7 @@ out vec4 FragColor;
void main()
{
// Use quarter resolution
vec2 uv = 4. * gl_FragCoord.xy / screen;
vec2 uv = 4. * gl_FragCoord.xy / u_screen;
vec4 res = texture(tex, uv);
// Keep the sun fully bright, but fade the sky

View File

@ -9,7 +9,7 @@ out vec4 FragColor;
void main()
{
vec2 uv = 4. * gl_FragCoord.xy / screen;
vec2 uv = 4. * gl_FragCoord.xy / u_screen;
vec2 texc = uv;
vec2 tosun = sunpos - texc;

View File

@ -31,8 +31,8 @@ void main()
// affects "nor" which is later only * 0.1 by scattering
new_inverse_model_matrix[3].xyz -= test * Color.r;
mat4 ModelViewProjectionMatrix = ProjectionViewMatrix * new_model_matrix;
mat4 TransposeInverseModelView = transpose(InverseViewMatrix * new_inverse_model_matrix);
mat4 ModelViewProjectionMatrix = u_projection_view_matrix * new_model_matrix;
mat4 TransposeInverseModelView = transpose(u_inverse_view_matrix * new_inverse_model_matrix);
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;

View File

@ -16,15 +16,16 @@ uniform float greenLmn[9];
uniform float redLmn[9];
#else
layout (std140) uniform MatrixesData
layout (std140) uniform Matrices
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ProjectionViewMatrix;
mat4 ShadowViewProjMatrixes[4];
vec2 screen;
mat4 u_view_matrix;
mat4 u_projection_matrix;
mat4 u_inverse_view_matrix;
mat4 u_inverse_projection_matrix;
mat4 u_projection_view_matrix;
mat4 u_shadow_projection_view_matrices[4];
vec2 u_screen;
};
// Expand because of catalyst (14.12) not correctly associating array in UBO
@ -64,5 +65,12 @@ layout (std140) uniform LightingData
float rL22;
};
layout (std140) uniform SPFogData
{
// x: fog_start, y: fog_end, z: fog_max, w: fog_density
vec4 u_fog_data;
vec4 u_fog_color;
};
#endif
#endif // HEADER_TXT

View File

@ -44,8 +44,8 @@ void main()
vec3 test = sin(windDir * (Position.y * 0.1)) * 1.;
test += cos(windDir) * 0.7;
mat4 ModelMatrix = getWorldMatrix(Origin + test * Color.r, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + test * Color.r, Orientation, Scale) * InverseViewMatrix);
gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + test * Color.r, Orientation, Scale) * u_inverse_view_matrix);
gl_Position = u_projection_view_matrix * ModelMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
uv = Texcoord;
color_change = misc_data.zw;

View File

@ -46,14 +46,14 @@ void main(void)
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
#ifdef VSLayer
gl_Layer = layer;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position + test * Color.r, 1.);
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * vec4(Position + test * Color.r, 1.);
uv = Texcoord;
#ifdef Use_Bindless_Texture
handle = Handle;
#endif
#else
layerId = layer;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position + test * Color.r, 1.);
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * vec4(Position + test * Color.r, 1.);
tc = Texcoord;
#ifdef Use_Bindless_Texture
hdle = Handle;

View File

@ -9,6 +9,8 @@ flat in sampler2D fourthhandle;
#endif
in vec3 tangent;
in vec3 bitangent;
in vec3 nor;
flat in float bitangent_sign;
in vec2 uv;
out vec3 EncodedNormal;
@ -26,10 +28,9 @@ void main()
#endif
// Because of interpolation, we need to renormalize
vec3 Frag_tangent = normalize(tangent);
vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
vec3 Frag_normal = normalize(nor);
vec3 Frag_bitangent = normalize(cross(Frag_normal, tangent) * bitangent_sign);
vec3 FragmentNormal = mat3(Frag_tangent, Frag_bitangent, Frag_normal) * TS_normal;
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5;
EncodedNormal.z = gloss;
}

View File

@ -5,7 +5,7 @@ layout(location = 2) in vec4 Color;
layout(location = 3) in vec2 Texcoord;
layout(location = 4) in vec2 SecondTexcoord;
layout(location = 5) in vec3 Tangent;
layout(location = 6) in vec3 Bitangent;
layout(location = 6) in vec4 Bitangent;
layout(location = 7) in vec3 Origin;
layout(location = 8) in vec3 Orientation;
@ -33,9 +33,11 @@ in vec3 Scale;
in vec4 misc_data;
#endif
out vec3 nort;
out vec3 nor;
out vec3 tangent;
out vec3 bitangent;
flat out float bitangent_sign;
out vec2 uv;
out vec2 uv_bis;
out vec4 color;
@ -52,13 +54,14 @@ flat out sampler2D fourthhandle;
void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix);
gl_Position = ProjectionViewMatrix * ModelMatrix * vec4(Position, 1.);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * u_inverse_view_matrix);
gl_Position = u_projection_view_matrix * ModelMatrix * vec4(Position, 1.);
// Keep orthogonality
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
// Keep direction
tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
tangent = (TransposeInverseModelView * vec4(Tangent, 0.)).xyz;
bitangent = (TransposeInverseModelView * vec4(Bitangent.xyz, 0.)).xyz;
bitangent_sign = Bitangent.w;
uv = vec2(Texcoord.x + misc_data.x, Texcoord.y + misc_data.y);
uv_bis = SecondTexcoord;
color = Color.zyxw;
@ -69,4 +72,5 @@ void main(void)
thirdhandle = ThirdHandle;
fourthhandle = FourthHandle;
#endif
//bitangent = Bitangent;
}

View File

@ -14,8 +14,8 @@ out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
void main() {
vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.);
vec3 u = getPosFromUVDepth(texc, InverseProjectionMatrix).xyz;
vec3 texc = gl_FragCoord.xyz / vec3(u_screen, 1.);
vec3 u = getPosFromUVDepth(texc, u_inverse_projection_matrix).xyz;
vec3 r = reflect(u, nor);
float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0));

View File

@ -40,14 +40,14 @@ void main(void)
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
#ifdef VSLayer
gl_Layer = layer;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position, 1.);
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * vec4(Position, 1.);
uv = Texcoord;
#ifdef Use_Bindless_Texture
handle = Handle;
#endif
#else
layerId = layer;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.);
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * vec4(Position, 1.);
tc = Texcoord;
#ifdef Use_Bindless_Texture
hdle = Handle;

View File

@ -2,8 +2,9 @@
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec4 Color;
layout(location = 3) in vec4 Data1;
layout(location = 4) in vec4 Data2;
layout(location = 3) in vec2 Texcoord;
layout(location = 4) in vec3 Tangent;
layout(location = 11) in vec4 Bitangent;
layout(location = 5) in ivec4 Joint;
layout(location = 6) in vec4 Weight;
@ -35,8 +36,10 @@ in int skinning_offset;
#endif
out vec3 nor;
out vec3 nort;
out vec3 tangent;
out vec3 bitangent;
flat out float bitangent_sign;
out vec2 uv;
out vec4 color;
flat out vec2 color_change;
@ -54,11 +57,11 @@ uniform samplerBuffer skinning_tex;
void main(void)
{
mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix);
mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * u_inverse_view_matrix);
vec4 idle_position = vec4(Position, 1.);
vec4 idle_normal = vec4(Normal, 0.);
vec4 idle_tangent = vec4(Data1.z, Data1.w, Data2.x, 0.);
vec4 idle_bitangent = vec4(Data2.y, Data2.z, Data2.w, 0.);
vec4 idle_tangent = vec4(Tangent, 0.);
vec4 idle_bitangent = vec4(Bitangent.xyz, 0.);
vec4 skinned_position = vec4(0.);
vec4 skinned_normal = vec4(0.);
vec4 skinned_tangent = vec4(0.);
@ -76,13 +79,14 @@ void main(void)
skinned_bitangent += Weight[i] * joint_matrix * idle_bitangent;
}
gl_Position = ProjectionViewMatrix * ModelMatrix * skinned_position;
gl_Position = u_projection_view_matrix * ModelMatrix * skinned_position;
// Keep orthogonality
nor = (TransposeInverseModelView * skinned_normal).xyz;
// Keep direction
tangent = (ViewMatrix * ModelMatrix * skinned_tangent).xyz;
bitangent = (ViewMatrix * ModelMatrix * skinned_bitangent).xyz;
uv = vec2(Data1.x + misc_data.x, Data1.y + misc_data.y);
tangent = (TransposeInverseModelView * skinned_tangent).xyz;
bitangent = (TransposeInverseModelView * skinned_bitangent).xyz;
bitangent_sign = Bitangent.w;
uv = vec2(Texcoord.x + misc_data.x, Texcoord.y + misc_data.y);
color = Color.zyxw;
color_change = misc_data.zw;
#ifdef Use_Bindless_Texture
@ -91,4 +95,5 @@ void main(void)
thirdhandle = ThirdHandle;
fourthhandle = FourthHandle;
#endif
//bitangent = skinned_bitangent.xyz;
}

View File

@ -57,14 +57,14 @@ void main(void)
#ifdef VSLayer
gl_Layer = layer;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * skinned_position;
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * skinned_position;
uv = Data1.xy;
#ifdef Use_Bindless_Texture
handle = Handle;
#endif
#else
layerId = layer;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * skinned_position;
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * skinned_position;
tc = Data1.xy;
#ifdef Use_Bindless_Texture
hdle = Handle;

View File

@ -11,7 +11,7 @@ out vec4 FragColor;
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec4 col = .125 * texture(tex_128, uv);
col += .25 * texture(tex_256, uv);
col += .5 * texture(tex_512, uv);

View File

@ -6,7 +6,7 @@ out float Depth;
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float d = texture(tex, uv).x;
float c0 = zn * zf, c1 = zn - zf, c2 = zf;
Depth = c0 / (d * c1 + c2);

View File

@ -12,7 +12,7 @@ out vec4 FragColor;
* bit.
*/
vec4 tex2Doffset(sampler2D map, vec2 texcoord, vec2 offset) {
return textureLod(map, texcoord + offset / screen, 0.0);
return textureLod(map, texcoord + offset / u_screen, 0.0);
}
float SearchXLeft(vec2 texcoord) {
@ -68,7 +68,7 @@ vec2 Area(vec2 distance, float e1, float e2) {
void main() {
vec4 areas = vec4(0.0);
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec2 e = texture(edgesMap, uv).rg;
@ -79,7 +79,7 @@ void main() {
// Now fetch the crossing edges. Instead of sampling between edgels, we
// sample at 0.25, to be able to discern what value has each edgel:
vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) / screen.xyxy + uv.xyxy;
vec4 coords = vec4(d.x, 0.25, d.y + 1.0, 0.25) / u_screen.xyxy + uv.xyxy;
float e1 = textureLod(edgesMap, coords.xy, 0.0).r;
float e2 = textureLod(edgesMap, coords.zw, 0.0).r;
@ -94,7 +94,7 @@ void main() {
vec2 d = vec2(SearchYUp(uv), SearchYDown(uv));
// Now fetch the crossing edges (yet again):
vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) / screen.xyxy + uv.xyxy;
vec4 coords = vec4(-0.25, d.x, -0.25, d.y - 1.0) / u_screen.xyxy + uv.xyxy;
float e1 = textureLod(edgesMap, coords.xy, 0.0).g;
float e2 = textureLod(edgesMap, coords.zw, 0.0).g;

View File

@ -7,11 +7,11 @@ out vec4 FragColor;
void main() {
vec3 weights = vec3(0.2126,0.7152, 0.0722); // ITU-R BT. 709
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv_left = uv + vec2(-1., 0.) / screen;
vec2 uv_top = uv + vec2(0., 1.) / screen;
vec2 uv_right = uv + vec2(1., 0.) / screen;
vec2 uv_bottom = uv + vec2(0., -1.) / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec2 uv_left = uv + vec2(-1., 0.) / u_screen;
vec2 uv_top = uv + vec2(0., 1.) / u_screen;
vec2 uv_right = uv + vec2(1., 0.) / u_screen;
vec2 uv_bottom = uv + vec2(0., -1.) / u_screen;
/**
* Luma calculation requires gamma-corrected colors:

View File

@ -4,11 +4,11 @@ uniform sampler2D colorMap;
out vec4 FragColor;
void main() {
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv_left = uv + vec2(-1., 0.) / screen;
vec2 uv_top = uv + vec2(0., 1.) / screen;
vec2 uv_right = uv + vec2(1., 0.) / screen;
vec2 uv_bottom = uv + vec2(0., -1.) / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec2 uv_left = uv + vec2(-1., 0.) / u_screen;
vec2 uv_top = uv + vec2(0., 1.) / u_screen;
vec2 uv_right = uv + vec2(1., 0.) / u_screen;
vec2 uv_bottom = uv + vec2(0., -1.) / u_screen;
// Fetch the blending weights for current pixel:
vec4 topLeft = texture(blendMap, uv);

View File

@ -46,14 +46,14 @@ out vec4 FragColor;
void main()
{
vec2 texcoords = gl_FragCoord.xy / screen;
vec2 texcoords = gl_FragCoord.xy / u_screen;
// Sample the color buffer
vec3 color = texture(color_buffer, texcoords).rgb;
float z = texture(dtex, texcoords).x;
vec4 ViewPos = getPosFromUVDepth(vec3(texcoords, z), InverseProjectionMatrix);
vec4 OldScreenPos = previous_viewproj * InverseViewMatrix * ViewPos;
vec4 ViewPos = getPosFromUVDepth(vec3(texcoords, z), u_inverse_projection_matrix);
vec4 OldScreenPos = previous_viewproj * u_inverse_view_matrix * ViewPos;
OldScreenPos /= OldScreenPos.w;
OldScreenPos = .5 * OldScreenPos + .5;

View File

@ -46,15 +46,15 @@ out float camdist;
void main(void)
{
color = Color.zyxw;
mat4 ModelViewProjectionMatrix = ProjectionViewMatrix * ModelMatrix;
mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix);
mat4 ModelViewProjectionMatrix = u_projection_view_matrix * ModelMatrix;
mat4 TransposeInverseModelView = transpose(InverseModelMatrix * u_inverse_view_matrix);
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
// Keep orthogonality
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
// Keep direction
tangent = (ViewMatrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (ViewMatrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
tangent = (u_view_matrix * ModelMatrix * vec4(Tangent, 0.)).xyz;
bitangent = (u_view_matrix * ModelMatrix * vec4(Bitangent, 0.)).xyz;
uv = vec2(Texcoord.x + texture_trans.x, Texcoord.y + texture_trans.y);
uv_bis = SecondTexcoord;
camdist = length(ViewMatrix * ModelMatrix * vec4(Position, 1.));
camdist = length(u_view_matrix * ModelMatrix * vec4(Position, 1.));
}

View File

@ -13,8 +13,8 @@ out vec4 FragColor;
#stk_include "utils/getLightFactor.frag"
void main() {
vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.);
vec3 u = getPosFromUVDepth(texc, InverseProjectionMatrix).xyz;
vec3 texc = gl_FragCoord.xyz / vec3(u_screen, 1.);
vec3 u = getPosFromUVDepth(texc, u_inverse_projection_matrix).xyz;
vec3 r = reflect(u, nor);
float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0));

View File

@ -21,15 +21,15 @@ out vec4 Spec;
void main()
{
vec2 texc = gl_FragCoord.xy / screen;
vec2 texc = gl_FragCoord.xy / u_screen;
float z = texture(dtex, texc).x;
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
float roughness = texture(ntex, texc).z;
vec4 xpos = getPosFromUVDepth(vec3(texc, z), InverseProjectionMatrix);
vec4 xpos = getPosFromUVDepth(vec3(texc, z), u_inverse_projection_matrix);
vec3 eyedir = -normalize(xpos.xyz);
vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0);
vec4 pseudocenter = u_view_matrix * vec4(center.xyz, 1.0);
pseudocenter /= pseudocenter.w;
vec3 light_pos = pseudocenter.xyz;
vec3 light_col = col.xyz;

View File

@ -60,8 +60,8 @@ vec2 UpdateClipRegion(float lc, /* Light x/y coordinate (view space) */
vec4 ComputeClipRegion(vec3 lightPosView, float lightRadius)
{
if (lightPosView.z + lightRadius >= zNear) {
vec2 clipX = UpdateClipRegion(lightPosView.x, lightPosView.z, lightRadius, ProjectionMatrix[0][0]);
vec2 clipY = UpdateClipRegion(lightPosView.y, lightPosView.z, lightRadius, ProjectionMatrix[1][1]);
vec2 clipX = UpdateClipRegion(lightPosView.x, lightPosView.z, lightRadius, u_projection_matrix[0][0]);
vec2 clipY = UpdateClipRegion(lightPosView.y, lightPosView.z, lightRadius, u_projection_matrix[1][1]);
return vec4(clipX, clipY);
}
@ -72,7 +72,7 @@ vec4 ComputeClipRegion(vec3 lightPosView, float lightRadius)
void main(void)
{
vec4 Center = ViewMatrix * vec4(Position, 1.);
vec4 Center = u_view_matrix * vec4(Position, 1.);
Center /= Center.w;
vec2 ProjectedCornerPosition;
@ -98,7 +98,7 @@ void main(void)
float quadDepth = max(zNear, Center.z - Radius);
// Project quad depth into clip space
vec4 quadClip = ProjectionMatrix * vec4(0., 0., quadDepth, 1.0f);
vec4 quadClip = u_projection_matrix * vec4(0., 0., quadDepth, 1.0f);
gl_Position = vec4(ProjectedCornerPosition, quadClip.z / quadClip.w, 1.);
col = Color;

View File

@ -13,15 +13,15 @@ out vec4 Fog;
void main()
{
vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0);
vec4 pseudocenter = u_view_matrix * vec4(center.xyz, 1.0);
pseudocenter /= pseudocenter.w;
vec3 light_pos = pseudocenter.xyz;
vec3 light_col = col.xyz;
// Compute pixel position
vec2 texc = 2. * gl_FragCoord.xy / screen;
vec2 texc = 2. * gl_FragCoord.xy / u_screen;
float z = texture(dtex, texc).x;
vec4 pixelpos = getPosFromUVDepth(vec3(texc, z), InverseProjectionMatrix);
vec4 pixelpos = getPosFromUVDepth(vec3(texc, z), u_inverse_projection_matrix);
vec3 eyedir = -normalize(pixelpos.xyz);
vec3 farthestpoint = - eyedir * (min(dot(-eyedir, light_pos) + radius, length(pixelpos.xyz)));

View File

@ -16,13 +16,15 @@ in vec3 Tangent;
in vec3 Bitangent;
#endif
uniform vec2 fullscreen;
out vec2 uv;
out vec4 color;
void main(void)
{
color = Color.zyxw;
vec3 P = Position / vec3(screen, 1.);
vec3 P = Position / vec3(fullscreen, 1.);
P = 2. * P - 1.;
P.y *= -1.;
gl_Position = vec4(P, 1.);

View File

@ -14,7 +14,7 @@ void main(void)
float gz = int(gl_VertexID >> 9) & (resolution.z - 1);
uvw = vec3(gx, gy, gz) / vec3(resolution);
vec3 WorldPos = (2. * uvw - 1.) * extents;
gl_Position = ProjectionViewMatrix * RHMatrix * vec4(WorldPos, 1.);
gl_Position = u_projection_view_matrix * RHMatrix * vec4(WorldPos, 1.);
gl_PointSize = 500. / gl_Position.w;
}

View File

@ -21,10 +21,10 @@ void main(void)
#ifdef VSLayer
gl_Layer = layer;
uv = Texcoord;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position, 1.);
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * vec4(Position, 1.);
#else
layerId = layer;
tc = Texcoord;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position, 1.);
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * vec4(Position, 1.);
#endif
}

View File

@ -28,10 +28,10 @@ void main(void)
#ifdef VSLayer
gl_Layer = layer;
uv = Texcoord;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position + test * Color.r, 1.);
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * vec4(Position + test * Color.r, 1.);
#else
layerId = layer;
tc = Texcoord;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position + test * Color.r, 1.);
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * vec4(Position + test * Color.r, 1.);
#endif
}

View File

@ -10,11 +10,11 @@ out vec4 FragColor;
void main(void)
{
vec2 xy = gl_FragCoord.xy / screen;
vec2 xy = gl_FragCoord.xy / u_screen;
float FragZ = gl_FragCoord.z;
vec4 FragmentPos = getPosFromUVDepth(vec3(xy, FragZ), InverseProjectionMatrix);
vec4 FragmentPos = getPosFromUVDepth(vec3(xy, FragZ), u_inverse_projection_matrix);
float EnvZ = texture(dtex, xy).x;
vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), InverseProjectionMatrix);
vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), u_inverse_projection_matrix);
float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix);
FragColor = texture(tex, tc) * billboard_alpha * pc * alpha;

View File

@ -59,12 +59,12 @@ void main(void)
vec3 newquadcorner = vec3(size * quadcorner, 0.0);
newquadcorner = newquadcorner + 2.0 * cross(cross(newquadcorner,
quat.xyz) + quat.w * newquadcorner, quat.xyz);
viewpos = ViewMatrix * vec4(Position + newquadcorner, 1.0);
viewpos = u_view_matrix * vec4(Position + newquadcorner, 1.0);
}
else
{
viewpos = ViewMatrix * vec4(Position, 1.0);
viewpos = u_view_matrix * vec4(Position, 1.0);
viewpos += vec4(size * quadcorner, 0.0, 0.0);
}
gl_Position = ProjectionMatrix * viewpos;
gl_Position = u_projection_matrix * viewpos;
}

View File

@ -51,7 +51,7 @@ out vec4 color;
void main(void)
{
mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix);
mat4 TransposeInverseModelView = transpose(InverseModelMatrix * u_inverse_view_matrix);
vec4 idle_position = vec4(Position, 1.);
vec4 idle_normal = vec4(Normal, 0.);
vec4 idle_tangent = vec4(Data1.z, Data1.w, Data2.x, 0.);
@ -82,12 +82,12 @@ void main(void)
skinned_bitangent += Weight[i] * joint_matrix * idle_bitangent;
}
gl_Position = ProjectionViewMatrix * ModelMatrix * skinned_position;
gl_Position = u_projection_view_matrix * ModelMatrix * skinned_position;
// Keep orthogonality
nor = (TransposeInverseModelView * skinned_normal).xyz;
// Keep direction
tangent = (ViewMatrix * ModelMatrix * skinned_tangent).xyz;
bitangent = (ViewMatrix * ModelMatrix * skinned_bitangent).xyz;
tangent = (u_view_matrix * ModelMatrix * skinned_tangent).xyz;
bitangent = (u_view_matrix * ModelMatrix * skinned_bitangent).xyz;
uv = vec2(Data1.x + texture_trans.x, Data1.y + texture_trans.y);
color = Color.zyxw;
}

View File

@ -52,10 +52,10 @@ void main(void)
#ifdef VSLayer
gl_Layer = layer;
uv = Data1.xy;
gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * skinned_position;
gl_Position = u_shadow_projection_view_matrices[gl_Layer] * ModelMatrix * skinned_position;
#else
layerId = layer;
tc = Data1.xy;
gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * skinned_position;
gl_Position = u_shadow_projection_view_matrices[layerId] * ModelMatrix * skinned_position;
#endif
}

View File

@ -4,11 +4,11 @@ out vec4 FragColor;
void main(void)
{
vec3 eyedir = vec3(mod(gl_FragCoord.xy, screen) / screen, 1.);
vec3 eyedir = vec3(mod(gl_FragCoord.xy, u_screen) / u_screen, 1.);
eyedir = 2.0 * eyedir - 1.0;
vec4 tmp = (InverseProjectionMatrix * vec4(eyedir, 1.));
vec4 tmp = (u_inverse_projection_matrix * vec4(eyedir, 1.));
tmp /= tmp.w;
eyedir = (InverseViewMatrix * vec4(tmp.xyz, 0.)).xyz;
eyedir = (u_inverse_view_matrix * vec4(tmp.xyz, 0.)).xyz;
vec4 color = texture(tex, eyedir);
FragColor = vec4(color.xyz, 1.);
}

View File

@ -0,0 +1,76 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_2;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// gloss map
uniform sampler2D tex_layer_2;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_2;
#endif
flat in float hue_change;
in vec4 color;
in vec3 normal;
in vec2 uv;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (col.a * color.a < 0.5)
{
discard;
}
col.xyz *= color.xyz;
if (hue_change > 0.0)
{
vec3 old_hsv = rgbToHsv(col.rgb);
vec2 new_xy = vec2(hue_change, old_hsv.y);
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, col.a);
}
vec3 final_color = col.xyz * color.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = layer_2.yz;
#endif
}

View File

@ -0,0 +1,67 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_1;
flat in sampler2D tex_layer_2;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// spm layer 1 texture
uniform sampler2D tex_layer_1;
// gloss map
uniform sampler2D tex_layer_2;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_1;
flat in float array_2;
#endif
in vec3 normal;
in vec2 uv;
in vec2 uv_two;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
void main(void)
{
#ifdef Use_Array_Texture
vec4 color = texture(tex_array, vec3(uv, array_0));
vec4 layer_two_tex = texture(tex_array, vec3(uv_two, array_1));
#else
vec4 color = texture(tex_layer_0, uv);
vec4 layer_two_tex = texture(tex_layer_1, uv_two);
#endif
layer_two_tex.rgb = layer_two_tex.a * layer_two_tex.rgb;
vec3 final_color = layer_two_tex.rgb + color.rgb * (1.0 - layer_two_tex.a);
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = layer_2.yz;
#endif
}

View File

@ -0,0 +1,63 @@
uniform sampler2D displacement_tex;
uniform sampler2D mask_tex;
uniform sampler2D color_tex;
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
#endif
uniform vec4 direction;
in vec2 uv;
in float camdist;
out vec4 o_frag_color;
const float maxlen = 0.02;
void main()
{
float horiz = texture(displacement_tex, uv + direction.xy).x;
float vert = texture(displacement_tex, (uv.yx + direction.zw) * vec2(0.9)).x;
vec2 offset = vec2(horiz, vert);
offset *= 2.0;
offset -= 1.0;
// Fade according to distance to cam
float fade = 1.0 - smoothstep(1.0, 100.0, camdist);
vec4 shiftval;
shiftval.r = step(offset.x, 0.0) * -offset.x;
shiftval.g = step(0.0, offset.x) * offset.x;
shiftval.b = step(offset.y, 0.0) * -offset.y;
shiftval.a = step(0.0, offset.y) * offset.y;
vec2 shift;
shift.x = -shiftval.x + shiftval.y;
shift.y = -shiftval.z + shiftval.w;
shift *= 0.02;
vec2 tc = gl_FragCoord.xy / u_screen;
float mask = texture(mask_tex, tc + shift).x;
tc += (mask < 1.) ? vec2(0.) : shift;
vec4 col = texture(color_tex, tc);
#ifdef Use_Array_Texture
vec4 blend_tex = texture(tex_array, vec3(uv, array_0));
#else
vec4 blend_tex = texture(tex_layer_0, uv);
#endif
col.rgb = blend_tex.rgb * blend_tex.a + (1. - blend_tex.a) * col.rgb;
o_frag_color = vec4(col.rgb, 1.);
}

View File

@ -0,0 +1,58 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
#endif
uniform float custom_alpha;
flat in float hue_change;
in vec2 uv;
in vec4 color;
out vec4 o_diffuse_color;
#stk_include "utils/rgb_conversion.frag"
void main()
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (hue_change > 0.0)
{
float mask = col.a;
vec3 old_hsv = rgbToHsv(col.rgb);
float mask_step = step(mask, 0.5);
#if !defined(Advanced_Lighting_Enabled)
float saturation = mask * 2.1;
#else
float saturation = mask * 2.5;
#endif
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(hue_change,
max(old_hsv.y, saturation)), vec2(mask_step, mask_step));
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, 1.0);
}
vec3 final_color = col.xyz * color.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4((final_color * custom_alpha), custom_alpha);
}

View File

@ -0,0 +1,72 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_2;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// gloss map
uniform sampler2D tex_layer_2;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_2;
#endif
flat in float hue_change;
in vec3 normal;
in vec2 uv;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (col.a < 0.5)
{
discard;
}
if (hue_change > 0.0)
{
vec3 old_hsv = rgbToHsv(col.rgb);
vec2 new_xy = vec2(hue_change, old_hsv.y);
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, col.a);
}
vec3 final_color = col.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = 0.1 * layer_2.yz;
#endif
}

View File

@ -0,0 +1,97 @@
uniform vec3 wind_direction;
layout(location = 0) in vec3 i_position;
#if defined(Converts_10bit_Vector)
layout(location = 1) in int i_normal_pked;
#else
layout(location = 1) in vec4 i_normal;
#endif
layout(location = 2) in vec4 i_color;
layout(location = 3) in vec2 i_uv;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
#if defined(Converts_10bit_Vector)
layout(location = 11) in int i_misc_data_pked;
#else
layout(location = 11) in vec4 i_misc_data;
#endif
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec3 normal;
out vec2 uv;
flat out float hue_change;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_normal = convert10BitVector(i_normal_pked);
vec4 i_rotation = convert10BitVector(i_rotation_pked);
vec4 i_misc_data = convert10BitVector(i_misc_data_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
vec3 test = sin(wind_direction * (i_position.y * 0.1));
test += cos(wind_direction) * 0.7;
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin + test * i_color.r,
quaternion, i_scale.xyz, i_position);
vec3 world_normal = rotateVector(quaternion, i_normal.xyz);
normal = (u_view_matrix * vec4(world_normal, 0.0)).xyz;
uv = i_uv;
hue_change = i_misc_data.z;
gl_Position = u_projection_view_matrix * world_position;
}

View File

@ -0,0 +1,82 @@
uniform int layer;
uniform vec3 wind_direction;
layout(location = 0) in vec3 i_position;
layout(location = 2) in vec4 i_color;
layout(location = 3) in vec2 i_uv;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec2 uv;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_rotation = convert10BitVector(i_rotation_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
#ifdef VSLayer
gl_Layer = layer;
#endif
vec3 test = sin(wind_direction * (i_position.y * 0.1));
test += cos(wind_direction) * 0.7;
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin + test * i_color.r,
quaternion, i_scale.xyz, i_position);
uv = i_uv;
gl_Position = u_shadow_projection_view_matrices[layer] * world_position;
}

View File

@ -0,0 +1,96 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_2;
flat in sampler2D tex_layer_3;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// gloss map
uniform sampler2D tex_layer_2;
// normal map
uniform sampler2D tex_layer_3;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_2;
flat in float array_3;
#endif
flat in float hue_change;
in vec4 color;
in vec3 tangent;
in vec3 bitangent;
in vec3 normal;
in vec2 uv;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
#stk_include "utils/rgb_conversion.frag"
void main()
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (hue_change > 0.0)
{
float mask = col.a;
vec3 old_hsv = rgbToHsv(col.rgb);
float mask_step = step(mask, 0.5);
#if !defined(Advanced_Lighting_Enabled)
float saturation = mask * 2.1;
#else
float saturation = mask * 2.5;
#endif
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(hue_change,
max(old_hsv.y, saturation)), vec2(mask_step, mask_step));
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, 1.0);
}
vec3 final_color = col.xyz * color.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_3 = texture(tex_array, vec3(uv, array_3));
#else
vec4 layer_3 = texture(tex_layer_3, uv);
#endif
vec3 tangent_space_normal = 2.0 * layer_3.xyz - 1.0;
vec3 frag_tangent = normalize(tangent);
vec3 frag_bitangent = normalize(bitangent);
vec3 frag_normal = normalize(normal);
mat3 t_b_n = mat3(frag_tangent, frag_bitangent, frag_normal);
vec3 world_normal = t_b_n * tangent_space_normal;
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(world_normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = layer_2.yz;
#endif
}

View File

@ -0,0 +1,22 @@
layout(triangles) in;
layout(line_strip, max_vertices = 6) out;
in vec3 normal[];
void main()
{
for (int i = 0; i < gl_in.length(); i++)
{
vec4 pos = gl_in[i].gl_Position;
gl_Position = pos;
EmitVertex();
pos = inverse(u_projection_matrix) * pos;
pos /= pos.w;
gl_Position = u_projection_matrix *
(pos + 0.2 * vec4(normalize(normal[i]), 0.0));
EmitVertex();
EndPrimitive();
}
}

View File

@ -0,0 +1,66 @@
uniform samplerBuffer skinning_tex;
layout(location = 0) in vec3 i_position;
#if defined(Converts_10bit_Vector)
layout(location = 1) in int i_normal_pked;
#else
layout(location = 1) in vec4 i_normal;
#endif
layout(location = 6) in ivec4 i_joint;
layout(location = 7) in vec4 i_weight;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
layout(location = 12) in int i_skinning_offset;
#stk_include "utils/get_world_location.vert"
out vec2 uv;
out vec3 normal;
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_normal = convert10BitVector(i_normal_pked);
vec4 i_rotation = convert10BitVector(i_rotation_pked);
#endif
vec4 idle_position = vec4(i_position, 1.0);
vec4 idle_normal = vec4(i_normal.xyz, 0.0);
vec4 skinned_position = vec4(0.0);
vec4 skinned_normal = vec4(0.0);
for (int i = 0; i < 4; i++)
{
mat4 joint_matrix = mat4(
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 1),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 2),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 3));
skinned_position += i_weight[i] * joint_matrix * idle_position;
skinned_normal += i_weight[i] * joint_matrix * idle_normal;
}
float step_mix = step(float(i_skinning_offset), -32769.0);
skinned_position = mix(idle_position, skinned_position, step_mix);
skinned_normal = mix(idle_normal, skinned_normal, step_mix);
vec4 world_position = getWorldPosition(i_origin, i_rotation, i_scale.xyz,
skinned_position.xyz);
vec3 world_normal = rotateVector(i_rotation, skinned_normal.xyz);
normal = (u_view_matrix * vec4(world_normal, 0.0)).xyz;
gl_Position = u_projection_view_matrix * world_position;
}

118
data/shaders/sp_pass.vert Normal file
View File

@ -0,0 +1,118 @@
layout(location = 0) in vec3 i_position;
#if defined(Converts_10bit_Vector)
layout(location = 1) in int i_normal_pked;
#else
layout(location = 1) in vec4 i_normal;
#endif
layout(location = 2) in vec4 i_color;
layout(location = 3) in vec2 i_uv;
layout(location = 4) in vec2 i_uv_two;
#if defined(Converts_10bit_Vector)
layout(location = 5) in int i_tangent_pked;
#else
layout(location = 5) in vec4 i_tangent;
#endif
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
#if defined(Converts_10bit_Vector)
layout(location = 11) in int i_misc_data_pked;
#else
layout(location = 11) in vec4 i_misc_data;
#endif
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec3 tangent;
out vec3 bitangent;
out vec3 normal;
out vec2 uv;
out vec2 uv_two;
out vec4 color;
out float camdist;
flat out float hue_change;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_normal = convert10BitVector(i_normal_pked);
vec4 i_tangent = convert10BitVector(i_tangent_pked);
vec4 i_rotation = convert10BitVector(i_rotation_pked);
vec4 i_misc_data = convert10BitVector(i_misc_data_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
i_position);
vec3 world_normal = rotateVector(quaternion, i_normal.xyz);
vec3 world_tangent = rotateVector(quaternion, i_tangent.xyz);
tangent = (u_view_matrix * vec4(world_tangent, 0.0)).xyz;
bitangent = (u_view_matrix *
// bitangent sign
vec4(cross(world_normal, world_tangent) * i_tangent.w, 0.0)
).xyz;
normal = (u_view_matrix * vec4(world_normal, 0.0)).xyz;
uv = vec2(i_uv.x + (i_misc_data.x * i_normal.w),
i_uv.y + (i_misc_data.y * i_normal.w));
uv_two = i_uv_two;
color = i_color.zyxw;
camdist = length(u_view_matrix * world_position);
hue_change = i_misc_data.z;
gl_Position = u_projection_view_matrix * world_position;
}

View File

@ -0,0 +1,7 @@
out vec4 o_frag_color;
void main()
{
o_frag_color = vec4(exp(32.0 * (2.0 * gl_FragCoord.z - 1.) /
gl_FragCoord.w));
}

View File

@ -0,0 +1,76 @@
uniform int layer;
layout(location = 0) in vec3 i_position;
layout(location = 3) in vec2 i_uv;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec2 uv;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_rotation = convert10BitVector(i_rotation_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
#ifdef VSLayer
gl_Layer = layer;
#endif
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
i_position);
uv = i_uv;
gl_Position = u_shadow_projection_view_matrices[layer] * world_position;
}

View File

@ -0,0 +1,30 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
#endif
in vec2 uv;
out vec4 o_frag_color;
void main(void)
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (col.a < 0.5)
{
discard;
}
o_frag_color = vec4(1.0);
}

View File

@ -0,0 +1,162 @@
#ifdef GL_ES
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
#endif
layout(location = 0) in vec3 i_position;
#if defined(Converts_10bit_Vector)
layout(location = 1) in int i_normal_pked;
#else
layout(location = 1) in vec4 i_normal;
#endif
layout(location = 2) in vec4 i_color;
layout(location = 3) in vec2 i_uv;
layout(location = 4) in vec2 i_uv_two;
#if defined(Converts_10bit_Vector)
layout(location = 5) in int i_tangent_pked;
#else
layout(location = 5) in vec4 i_tangent;
#endif
layout(location = 6) in ivec4 i_joint;
layout(location = 7) in vec4 i_weight;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
#if defined(Converts_10bit_Vector)
layout(location = 11) in int i_misc_data_pked;
#else
layout(location = 11) in vec4 i_misc_data;
#endif
layout(location = 12) in int i_skinning_offset;
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec3 tangent;
out vec3 bitangent;
out vec3 normal;
out vec2 uv;
out vec2 uv_two;
out vec4 color;
out float camdist;
flat out float hue_change;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_normal = convert10BitVector(i_normal_pked);
vec4 i_tangent = convert10BitVector(i_tangent_pked);
vec4 i_rotation = convert10BitVector(i_rotation_pked);
vec4 i_misc_data = convert10BitVector(i_misc_data_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
vec4 idle_position = vec4(i_position, 1.0);
vec4 idle_normal = vec4(i_normal.xyz, 0.0);
vec4 idle_tangent = vec4(i_tangent.xyz, 0.0);
vec4 skinned_position = vec4(0.0);
vec4 skinned_normal = vec4(0.0);
vec4 skinned_tangent = vec4(0.0);
for (int i = 0; i < 4; i++)
{
#ifdef GL_ES
mat4 joint_matrix = mat4(
texelFetch(skinning_tex, ivec2
(0 , clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(1, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(2, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(3, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0));
#else
mat4 joint_matrix = mat4(
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 1),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 2),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 3));
#endif
skinned_position += i_weight[i] * joint_matrix * idle_position;
skinned_normal += i_weight[i] * joint_matrix * idle_normal;
skinned_tangent += i_weight[i] * joint_matrix * idle_tangent;
}
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
skinned_position.xyz);
vec3 world_normal = rotateVector(quaternion, skinned_normal.xyz);
vec3 world_tangent = rotateVector(quaternion, skinned_tangent.xyz);
tangent = (u_view_matrix * vec4(world_tangent, 0.0)).xyz;
bitangent = (u_view_matrix *
// bitangent sign
vec4(cross(world_normal, world_tangent) * i_tangent.w, 0.0)
).xyz;
normal = (u_view_matrix * vec4(world_normal, 0.0)).xyz;
uv = vec2(i_uv.x + (i_misc_data.x * i_normal.w),
i_uv.y + (i_misc_data.y * i_normal.w));
uv_two = i_uv_two;
color = i_color.zyxw;
camdist = length(u_view_matrix * world_position);
hue_change = i_misc_data.z;
gl_Position = u_projection_view_matrix * world_position;
}

View File

@ -0,0 +1,115 @@
uniform int layer;
#ifdef GL_ES
uniform sampler2D skinning_tex;
#else
uniform samplerBuffer skinning_tex;
#endif
layout(location = 0) in vec3 i_position;
layout(location = 3) in vec2 i_uv;
layout(location = 6) in ivec4 i_joint;
layout(location = 7) in vec4 i_weight;
layout(location = 8) in vec3 i_origin;
#if defined(Converts_10bit_Vector)
layout(location = 9) in int i_rotation_pked;
#else
layout(location = 9) in vec4 i_rotation;
#endif
layout(location = 10) in vec4 i_scale;
layout(location = 12) in int i_skinning_offset;
#if defined(Use_Bindless_Texture)
layout(location = 13) in uvec4 i_bindless_texture_0;
layout(location = 14) in uvec4 i_bindless_texture_1;
layout(location = 15) in uvec4 i_bindless_texture_2;
#elif defined(Use_Array_Texture)
layout(location = 13) in uvec4 i_array_texture_0;
layout(location = 14) in uvec2 i_array_texture_1;
#endif
#stk_include "utils/get_world_location.vert"
out vec2 uv;
#if defined(Use_Bindless_Texture)
flat out sampler2D tex_layer_0;
flat out sampler2D tex_layer_1;
flat out sampler2D tex_layer_2;
flat out sampler2D tex_layer_3;
flat out sampler2D tex_layer_4;
flat out sampler2D tex_layer_5;
#elif defined(Use_Array_Texture)
flat out float array_0;
flat out float array_1;
flat out float array_2;
flat out float array_3;
flat out float array_4;
flat out float array_5;
#endif
void main()
{
#if defined(Converts_10bit_Vector)
vec4 i_rotation = convert10BitVector(i_rotation_pked);
#endif
#if defined(Use_Bindless_Texture)
tex_layer_0 = sampler2D(i_bindless_texture_0.xy);
tex_layer_1 = sampler2D(i_bindless_texture_0.zw);
tex_layer_2 = sampler2D(i_bindless_texture_1.xy);
tex_layer_3 = sampler2D(i_bindless_texture_1.zw);
tex_layer_4 = sampler2D(i_bindless_texture_2.xy);
tex_layer_5 = sampler2D(i_bindless_texture_2.zw);
#elif defined(Use_Array_Texture)
array_0 = float(i_array_texture_0.x);
array_1 = float(i_array_texture_0.y);
array_2 = float(i_array_texture_0.z);
array_3 = float(i_array_texture_0.w);
array_4 = float(i_array_texture_1.x);
array_5 = float(i_array_texture_1.y);
#endif
#ifdef VSLayer
gl_Layer = layer;
#endif
vec4 idle_position = vec4(i_position, 1.0);
vec4 skinned_position = vec4(0.0);
for (int i = 0; i < 4; i++)
{
#ifdef GL_ES
mat4 joint_matrix = mat4(
texelFetch(skinning_tex, ivec2
(0, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(1, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(2, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0),
texelFetch(skinning_tex, ivec2
(3, clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES)), 0));
#else
mat4 joint_matrix = mat4(
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 1),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 2),
texelFetch(skinning_tex,
clamp(i_joint[i] + i_skinning_offset, 0, MAX_BONES) * 4 + 3));
#endif
skinned_position += i_weight[i] * joint_matrix * idle_position;
}
vec4 quaternion = normalize(vec4(i_rotation.xyz, i_scale.w));
vec4 world_position = getWorldPosition(i_origin, quaternion, i_scale.xyz,
skinned_position.xyz);
uv = i_uv;
gl_Position = u_shadow_projection_view_matrices[layer] * world_position;
}

View File

@ -0,0 +1,76 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_2;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// gloss map
uniform sampler2D tex_layer_2;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_2;
#endif
flat in float hue_change;
in vec4 color;
in vec3 normal;
in vec2 uv;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (hue_change > 0.0)
{
float mask = col.a;
vec3 old_hsv = rgbToHsv(col.rgb);
float mask_step = step(mask, 0.5);
#if !defined(Advanced_Lighting_Enabled)
float saturation = mask * 2.1;
#else
float saturation = mask * 2.5;
#endif
vec2 new_xy = mix(vec2(old_hsv.x, old_hsv.y), vec2(hue_change,
max(old_hsv.y, saturation)), vec2(mask_step, mask_step));
vec3 new_color = hsvToRgb(vec3(new_xy.x, new_xy.y, old_hsv.z));
col = vec4(new_color.r, new_color.g, new_color.b, 1.0);
}
vec3 final_color = col.xyz * color.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = layer_2.yz;
#endif
}

View File

@ -0,0 +1,52 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
#endif
uniform int fog_enabled;
uniform float custom_alpha;
in vec2 uv;
in vec4 color;
out vec4 o_diffuse_color;
void main()
{
#ifdef Use_Array_Texture
vec4 diffusecolor = texture(tex_array, vec3(uv, array_0));
#else
vec4 diffusecolor = texture(tex_layer_0, uv);
#endif
vec4 finalcolor = vec4(0.);
if (fog_enabled == 0)
{
finalcolor = diffusecolor;
finalcolor.xyz *= color.xyz;
finalcolor.a *= color.a;
}
else
{
diffusecolor.xyz *= color.xyz;
diffusecolor.a *= color.a;
vec3 tmp = vec3(gl_FragCoord.xy / u_screen, gl_FragCoord.z);
tmp = 2. * tmp - 1.;
vec4 xpos = vec4(tmp, 1.0);
xpos = u_inverse_projection_matrix * xpos;
xpos.xyz /= xpos.w;
float dist = length(xpos.xyz);
float fog = smoothstep(u_fog_data.x, u_fog_data.y, dist);
fog = min(fog, u_fog_data.z);
finalcolor = u_fog_color * fog + diffusecolor * (1. - fog);
}
o_diffuse_color = vec4(finalcolor.rgb * (finalcolor.a * (1.0 - custom_alpha)),
finalcolor.a * (1.0 - custom_alpha));
}

View File

@ -0,0 +1,66 @@
#ifdef Use_Bindless_Texture
flat in sampler2D tex_layer_0;
flat in sampler2D tex_layer_2;
#else
// spm layer 1 texture
uniform sampler2D tex_layer_0;
// gloss map
uniform sampler2D tex_layer_2;
#endif
#ifdef Use_Array_Texture
uniform sampler2DArray tex_array;
flat in float array_0;
flat in float array_2;
#endif
in vec4 color;
in vec3 normal;
in vec2 uv;
layout(location = 0) out vec4 o_diffuse_color;
layout(location = 1) out vec3 o_normal_depth;
layout(location = 2) out vec2 o_gloss_map;
#stk_include "utils/encode_normal.frag"
#stk_include "utils/rgb_conversion.frag"
void main(void)
{
#ifdef Use_Array_Texture
vec4 col = texture(tex_array, vec3(uv, array_0));
#else
vec4 col = texture(tex_layer_0, uv);
#endif
if (col.a < 0.5)
{
discard;
}
vec3 final_color = col.xyz * color.xyz;
#if !defined(Advanced_Lighting_Enabled)
#if !defined(sRGB_Framebuffer_Usable)
final_color = final_color * 0.73; // 0.5 ^ (1. / 2.2)
#else
final_color = final_color * 0.5;
#endif
#endif
o_diffuse_color = vec4(final_color, 1.0);
#if defined(Advanced_Lighting_Enabled)
#ifdef Use_Array_Texture
vec4 layer_2 = texture(tex_array, vec3(uv, array_2));
#else
vec4 layer_2 = texture(tex_layer_2, uv);
#endif
o_normal_depth.xy = 0.5 * EncodeNormal(normalize(normal)) + 0.5;
o_normal_depth.z = layer_2.x;
o_gloss_map = vec2(0.0);
#endif
}

View File

@ -17,14 +17,14 @@ const float invSamples = 0.0625; // 1. / SAMPLES
vec3 getXcYcZc(int x, int y, float zC)
{
// We use perspective symetric projection matrix hence P(0,2) = P(1, 2) = 0
float xC= (2. * (float(x)) / screen.x - 1.) * zC / ProjectionMatrix[0][0];
float yC= (2. * (float(y)) / screen.y - 1.) * zC / ProjectionMatrix[1][1];
float xC= (2. * (float(x)) / u_screen.x - 1.) * zC / u_projection_matrix[0][0];
float yC= (2. * (float(y)) / u_screen.y - 1.) * zC / u_projection_matrix[1][1];
return vec3(xC, yC, zC);
}
void main(void)
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float lineardepth = textureLod(dtex, uv, 0.).x;
int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y);
vec3 FragPos = getXcYcZc(x, y, lineardepth);
@ -40,7 +40,7 @@ void main(void)
float m = log2(r) + 6. + log2(invSamples);
float theta = mod(2. * 3.14 * tau * .5 * invSamples + phi, 6.283185307179586);
vec2 rotations = vec2(cos(theta), sin(theta)) * screen;
vec2 rotations = vec2(cos(theta), sin(theta)) * u_screen;
vec2 offset = vec2(cos(invSamples), sin(invSamples));
for(int i = 0; i < SAMPLES; ++i) {
@ -52,9 +52,9 @@ void main(void)
m = m + .5;
ivec2 ioccluder_uv = ivec2(x, y) + ivec2(localoffset);
if (ioccluder_uv.x < 0 || ioccluder_uv.x > int(screen.x) || ioccluder_uv.y < 0 || ioccluder_uv.y > int(screen.y)) continue;
if (ioccluder_uv.x < 0 || ioccluder_uv.x > int(u_screen.x) || ioccluder_uv.y < 0 || ioccluder_uv.y > int(u_screen.y)) continue;
float LinearoccluderFragmentDepth = textureLod(dtex, vec2(ioccluder_uv) / screen, max(m, 0.)).x;
float LinearoccluderFragmentDepth = textureLod(dtex, vec2(ioccluder_uv) / u_screen, max(m, 0.)).x;
vec3 OccluderPos = getXcYcZc(ioccluder_uv.x, ioccluder_uv.y, LinearoccluderFragmentDepth);
vec3 vi = OccluderPos - FragPos;

View File

@ -1,6 +1,9 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform vec3 sundirection;
uniform vec3 sun_color;
#ifdef GL_ES
layout (location = 0) out vec4 Diff;
layout (location = 1) out vec4 Spec;
@ -16,9 +19,9 @@ out vec4 Spec;
#stk_include "utils/SunMRP.frag"
void main() {
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
float roughness = texture(ntex, uv).z;
@ -30,8 +33,8 @@ void main() {
vec3 Specular = SpecularBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
vec3 Diffuse = DiffuseBRDF(norm, eyedir, Lightdir, vec3(1.), roughness);
Diff = vec4(NdotL * Diffuse * sun_col, 1.);
Spec = vec4(NdotL * Specular * sun_col, 1.);
Diff = vec4(NdotL * Diffuse * sun_color, 1.);
Spec = vec4(NdotL * Specular * sun_color, 1.);
/* if (hasclouds == 1)
{

View File

@ -8,6 +8,9 @@ uniform float split2;
uniform float splitmax;
uniform float shadow_res;
uniform vec3 sundirection;
uniform vec3 sun_color;
in vec2 uv;
#ifdef GL_ES
layout (location = 0) out vec4 Diff;
@ -25,7 +28,7 @@ out vec4 Spec;
float getShadowFactor(vec3 pos, int index)
{
vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0));
vec4 shadowcoord = (u_shadow_projection_view_matrices[index] * u_inverse_view_matrix * vec4(pos, 1.0));
shadowcoord.xy /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
//float d = .5 * shadowcoord.z + .5;
@ -45,9 +48,9 @@ float getShadowFactor(vec3 pos, int index)
}
void main() {
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
float roughness =texture(ntex, uv).z;
@ -72,6 +75,6 @@ void main() {
else
factor = 1.;
Diff = vec4(factor * NdotL * Diffuse * sun_col, 1.);
Spec = vec4(factor * NdotL * Specular * sun_col, 1.);
Diff = vec4(factor * NdotL * Diffuse * sun_color, 1.);
Spec = vec4(factor * NdotL * Specular * sun_color, 1.);
}

View File

@ -24,7 +24,7 @@ out vec4 Spec;
float getShadowFactor(vec3 pos, int index)
{
vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0));
vec4 shadowcoord = (u_shadow_projection_view_matrices[index] * u_inverse_view_matrix * vec4(pos, 1.0));
shadowcoord.xy /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
@ -34,9 +34,9 @@ float getShadowFactor(vec3 pos, int index)
}
void main() {
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
float z = texture(dtex, uv).x;
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
vec4 xpos = getPosFromUVDepth(vec3(uv, z), u_inverse_projection_matrix);
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
float roughness =texture(ntex, uv).z;

View File

@ -8,7 +8,7 @@ out vec4 FragColor;
void main()
{
vec2 uv = gl_FragCoord.xy / screen;
vec2 uv = gl_FragCoord.xy / u_screen;
vec4 col = texture(tex, uv);
// Uncharted2 tonemap with Auria's custom coefficients

View File

@ -27,11 +27,11 @@ void main()
#endif
diffusecolor.xyz *= pow(color.xyz, vec3(2.2));
diffusecolor.a *= color.a;
vec3 tmp = vec3(gl_FragCoord.xy / screen, gl_FragCoord.z);
vec3 tmp = vec3(gl_FragCoord.xy / u_screen, gl_FragCoord.z);
tmp = 2. * tmp - 1.;
vec4 xpos = vec4(tmp, 1.0);
xpos = InverseProjectionMatrix * xpos;
xpos = u_inverse_projection_matrix * xpos;
xpos.xyz /= xpos.w;
float dist = length(xpos.xyz);

View File

@ -17,7 +17,7 @@ mat4 getMatrix(float L00, float L1m1, float L10, float L11, float L2m2, float L2
vec3 DiffuseIBL(vec3 normal)
{
// Convert normal in wobLd space (where SH coordinates were computed)
vec4 extendednormal = transpose(ViewMatrix) * vec4(normal, 0.);
vec4 extendednormal = transpose(u_view_matrix) * vec4(normal, 0.);
extendednormal.w = 1.;
#ifdef UBO_DISABLED

View File

@ -3,7 +3,7 @@ uniform samplerCube probe;
vec3 SpecularIBL(vec3 normal, vec3 V, float roughness)
{
vec3 sampleDirection = reflect(-V, normal);
sampleDirection = (InverseViewMatrix * vec4(sampleDirection, 0.)).xyz;
sampleDirection = (u_inverse_view_matrix * vec4(sampleDirection, 0.)).xyz;
// Assume 8 level of lod (ie 256x256 texture)
float lodval = 7. * (1. - roughness);

View File

@ -2,7 +2,7 @@
// From "Frostbite going PBR" paper
vec3 SunMRP(vec3 normal, vec3 eyedir)
{
vec3 local_sundir = normalize((transpose(InverseViewMatrix) * vec4(sun_direction, 0.)).xyz);
vec3 local_sundir = normalize((transpose(u_inverse_view_matrix) * vec4(sundirection, 0.)).xyz);
vec3 R = reflect(-eyedir, normal);
float angularRadius = 3.14 * sun_angle / 180.;
vec3 D = local_sundir;

View File

@ -11,7 +11,7 @@ uniform sampler2D SSAO;
vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue)
{
#if defined(Advanced_Lighting_Enabled)
vec2 tc = gl_FragCoord.xy / screen;
vec2 tc = gl_FragCoord.xy / u_screen;
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;

View File

@ -1,8 +1,8 @@
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix)
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 u_inverse_projection_matrix)
{
vec4 pos = 2.0 * vec4(uvDepth, 1.0) - 1.0;
pos.xy *= vec2(InverseProjectionMatrix[0][0], InverseProjectionMatrix[1][1]);
pos.zw = vec2(pos.z * InverseProjectionMatrix[2][2] + pos.w, pos.z * InverseProjectionMatrix[2][3] + pos.w);
pos.xy *= vec2(u_inverse_projection_matrix[0][0], u_inverse_projection_matrix[1][1]);
pos.zw = vec2(pos.z * u_inverse_projection_matrix[2][2] + pos.w, pos.z * u_inverse_projection_matrix[2][3] + pos.w);
pos /= pos.w;
return pos;
}

View File

@ -0,0 +1,34 @@
vec3 rotateVector(vec4 quat, vec3 vec)
{
return vec + 2.0 * cross(cross(vec, quat.xyz) + quat.w * vec, quat.xyz);
}
vec4 getWorldPosition(vec3 origin, vec4 rotation, vec3 scale, vec3 local_pos)
{
local_pos = local_pos * scale;
local_pos = rotateVector(rotation, local_pos);
local_pos = local_pos + origin;
return vec4(local_pos, 1.0);
}
vec4 convert10BitVector(int pked)
{
vec4 ret;
int part = pked & 1023;
float part_mix = float(clamp(int(part & 512), 0, 1));
ret.x = mix(float(part), float(-1024 + part), part_mix) * 0.00195694715;
part = (pked >> 10) & 1023;
part_mix = float(clamp(int(part & 512), 0, 1));
ret.y = mix(float(part), float(-1024 + part), part_mix) * 0.00195694715;
part = (pked >> 20) & 1023;
part_mix = float(clamp(int(part & 512), 0, 1));
ret.z = mix(float(part), float(-1024 + part), part_mix) * 0.00195694715;
part = pked >> 30;
part_mix = float(clamp(int(part & 2), 0, 1));
ret.w = mix(float(part), -1.0f, part_mix);
return ret;
}

View File

@ -27,11 +27,11 @@ void main()
#endif
diffusecolor.xyz *= pow(color.xyz, vec3(2.2));
diffusecolor.a *= color.a;
vec3 tmp = vec3(gl_FragCoord.xy / screen, gl_FragCoord.z);
vec3 tmp = vec3(gl_FragCoord.xy / u_screen, gl_FragCoord.z);
tmp = 2. * tmp - 1.;
vec4 xpos = vec4(tmp, 1.0);
xpos = InverseProjectionMatrix * xpos;
xpos = u_inverse_projection_matrix * xpos;
xpos.xyz /= xpos.w;
float dist = length(xpos.xyz);

View File

@ -3,11 +3,11 @@
<config>
<!-- Minimum and maximum kart versions that can be used by this binary.
Older version will be ignored. -->
<kart-version min="2" max="3"/>
<kart-version min="3" max="3"/>
<!-- Minimum and maxium track versions that be be read by this binary.
Older versions will be ignored. -->
<track-version min="6" max="7"/>
<track-version min="7" max="7"/>
<!-- Maximum number of karts to be used at the same time. This limit
can easily be increased, but some tracks might not have valid start
@ -467,4 +467,15 @@
so 1024 will work everywhere. -->
<skinning max-bones="1024"/>
<!-- For users with libsquish:
Use a slow but high quality colour compressor.
kColourClusterFit = (32),
Use a fast but low quality colour compressor.
kColourRangeFit = (64),
Use a very slow but very high quality colour compressor.
kColourIterativeClusterFit = (256),
STK default the low quality.
-->
<texture-compression quality="64"/>
</config>

View File

@ -95,6 +95,11 @@ namespace scene
//! Updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePositionOfAllChildren()=0;
virtual void setAbsoluteTransformation(const core::matrix4& m)
{
AbsoluteTransformation = m;
}
s32 positionHint;
s32 scaleHint;
s32 rotationHint;

View File

@ -1188,6 +1188,8 @@ namespace video
See IReferenceCounted::drop() for more information. */
virtual IImage* createImageFromFile(io::IReadFile* file, video::IImageLoader** loader = NULL) =0;
virtual video::IImageLoader* getImageLoaderForFile(const io::path& filename) = 0;
//! Writes the provided image to a file.
/** Requires that there is a suitable image writer registered
for writing the image.

View File

@ -253,8 +253,13 @@ struct S3DVertexTangents : public S3DVertex
}
};
struct S3DVertexSkinnedMesh : public S3DVertexTangents
struct S3DVertexSkinnedMesh
{
core::vector3df m_position;
u32 m_normal;
SColor m_color;
s16 m_all_uvs[4];
u32 m_tangent;
s16 m_joint_idx[4];
s16 m_weight[4];

View File

@ -7,7 +7,8 @@
#include "IMeshBuffer.h"
#include "S3DVertex.h"
#include "irrMap.h"
#include <utility>
namespace irr
{
@ -51,7 +52,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
case video::EVT_TANGENTS:
return (video::S3DVertex*)&Vertices_Tangents[index];
case video::EVT_SKINNED_MESH:
return (video::S3DVertex*)&Vertices_SkinnedMesh[index];
default:
return &Vertices_Standard[index];
}
@ -67,7 +67,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
case video::EVT_TANGENTS:
return Vertices_Tangents.const_pointer();
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh.const_pointer();
default:
return Vertices_Standard.const_pointer();
}
@ -82,8 +81,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords.pointer();
case video::EVT_TANGENTS:
return Vertices_Tangents.pointer();
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh.pointer();
default:
return Vertices_Standard.pointer();
}
@ -98,8 +95,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords.size();
case video::EVT_TANGENTS:
return Vertices_Tangents.size();
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh.size();
default:
return Vertices_Standard.size();
}
@ -188,18 +183,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
}
break;
}
case video::EVT_SKINNED_MESH:
{
if (Vertices_SkinnedMesh.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices_SkinnedMesh[0].Pos);
for (u32 i=1; i<Vertices_SkinnedMesh.size(); ++i)
BoundingBox.addInternalPoint(Vertices_SkinnedMesh[i].Pos);
}
break;
}
default:
break;
}
@ -232,50 +215,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
void convertForSkinning()
{
if (VertexType==video::EVT_STANDARD)
{
for(u32 n=0;n<Vertices_Standard.size();++n)
{
video::S3DVertexSkinnedMesh Vertex;
Vertex.Color=Vertices_Standard[n].Color;
Vertex.Pos=Vertices_Standard[n].Pos;
Vertex.Normal=Vertices_Standard[n].Normal;
Vertex.TCoords=Vertices_Standard[n].TCoords;
Vertex.Tangent=core::vector3df(0.0f, 0.0f, 0.0f);
Vertex.Binormal=core::vector3df(0.0f, 0.0f, 0.0f);
Vertex.m_joint_idx[0] = 0;
Vertex.m_joint_idx[1] = 0;
Vertex.m_joint_idx[2] = 0;
Vertex.m_joint_idx[3] = 0;
Vertex.m_weight[0] = 0;
Vertex.m_weight[1] = 0;
Vertex.m_weight[2] = 0;
Vertex.m_weight[3] = 0;
Vertices_SkinnedMesh.push_back(Vertex);
}
}
else if (VertexType==video::EVT_TANGENTS)
{
for(u32 n=0;n<Vertices_Tangents.size();++n)
{
video::S3DVertexSkinnedMesh Vertex;
Vertex.Color=Vertices_Tangents[n].Color;
Vertex.Pos=Vertices_Tangents[n].Pos;
Vertex.Normal=Vertices_Tangents[n].Normal;
Vertex.TCoords=Vertices_Tangents[n].TCoords;
Vertex.Tangent=Vertices_Tangents[n].Tangent;
Vertex.Binormal=Vertices_Tangents[n].Binormal;
Vertex.m_joint_idx[0] = 0;
Vertex.m_joint_idx[1] = 0;
Vertex.m_joint_idx[2] = 0;
Vertex.m_joint_idx[3] = 0;
Vertex.m_weight[0] = 0;
Vertex.m_weight[1] = 0;
Vertex.m_weight[2] = 0;
Vertex.m_weight[3] = 0;
Vertices_SkinnedMesh.push_back(Vertex);
}
}
}
//! Convert to tangents vertex type
@ -320,8 +259,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Pos;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].Pos;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].Pos;
default:
return Vertices_Standard[i].Pos;
}
@ -336,8 +273,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Pos;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].Pos;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].Pos;
default:
return Vertices_Standard[i].Pos;
}
@ -352,8 +287,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Normal;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].Normal;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].Normal;
default:
return Vertices_Standard[i].Normal;
}
@ -368,8 +301,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].Normal;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].Normal;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].Normal;
default:
return Vertices_Standard[i].Normal;
}
@ -384,8 +315,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].TCoords;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].TCoords;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].TCoords;
default:
return Vertices_Standard[i].TCoords;
}
@ -400,8 +329,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
return Vertices_2TCoords[i].TCoords;
case video::EVT_TANGENTS:
return Vertices_Tangents[i].TCoords;
case video::EVT_SKINNED_MESH:
return Vertices_SkinnedMesh[i].TCoords;
default:
return Vertices_Standard[i].TCoords;
}
@ -463,7 +390,6 @@ struct SSkinMeshBuffer : public IMeshBuffer
core::array<video::S3DVertexTangents> Vertices_Tangents;
core::array<video::S3DVertex2TCoords> Vertices_2TCoords;
core::array<video::S3DVertexSkinnedMesh> Vertices_SkinnedMesh;
core::array<video::S3DVertex> Vertices_Standard;
core::array<u16> Indices;
@ -486,6 +412,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
//! What kind of primitives does this buffer contain? Default triangles
scene::E_PRIMITIVE_TYPE Primitive;
};

View File

@ -41,8 +41,6 @@ CAnimatedMeshSceneNode::CAnimatedMeshSceneNode(IAnimatedMesh* mesh,
#ifdef _DEBUG
setDebugName("CAnimatedMeshSceneNode");
#endif
setMesh(mesh);
}

View File

@ -176,7 +176,7 @@ namespace scene
virtual IMesh* getMeshForCurrentFrame(SkinningCallback sc = NULL, int offset = -1);
void buildFrameNr(u32 timeMs);
void checkJoints();
virtual void checkJoints();
void beginTransition();
core::array<video::SMaterial> Materials;

View File

@ -41,6 +41,12 @@ namespace scene
virtual void OnAnimate(u32 timeMs);
virtual void updateAbsolutePosition()
{
if (SkinningSpace == EBSS_GLOBAL) return;
IBoneSceneNode::updateAbsolutePosition();
}
virtual void updateAbsolutePositionOfAllChildren();
//! Writes attributes of the scene node.

View File

@ -112,7 +112,7 @@ void CImageLoaderJPG::output_message(j_common_ptr cinfo)
(*cinfo->err->format_message)(cinfo, temp1);
core::stringc errMsg("JPEG FATAL ERROR in ");
errMsg += core::stringc(Filename);
os::Printer::log(errMsg.c_str(),temp1, ELL_ERROR);
//os::Printer::log(errMsg.c_str(),temp1, ELL_ERROR);
}
#endif // _IRR_COMPILE_WITH_LIBJPEG_
@ -138,7 +138,7 @@ bool CImageLoaderJPG::isALoadableFileFormat(io::IReadFile* file) const
IImage* CImageLoaderJPG::loadImage(io::IReadFile* file, bool skip_checking) const
{
#ifndef _IRR_COMPILE_WITH_LIBJPEG_
os::Printer::log("Can't load as not compiled with _IRR_COMPILE_WITH_LIBJPEG_:", file->getFileName(), ELL_DEBUG);
//os::Printer::log("Can't load as not compiled with _IRR_COMPILE_WITH_LIBJPEG_:", file->getFileName(), ELL_DEBUG);
return 0;
#else

View File

@ -1328,6 +1328,25 @@ IImage* CNullDriver::createImageFromFile(io::IReadFile* file, video::IImageLoade
return 0; // failed to load
}
video::IImageLoader* CNullDriver::getImageLoaderForFile(const io::path& filename)
{
if (!filename.size())
return 0;
s32 i;
// try to load file based on file extension
for (i=SurfaceLoader.size()-1; i>=0; --i)
{
if (SurfaceLoader[i]->isALoadableFileExtension(filename))
{
return SurfaceLoader[i];
}
}
return 0; // failed to load
}
//! Writes the provided image to disk file
bool CNullDriver::writeImageToFile(IImage* image, const io::path& filename,u32 param)

View File

@ -350,6 +350,8 @@ namespace video
//! Creates a software image from a file.
virtual IImage* createImageFromFile(io::IReadFile* file, video::IImageLoader** loader = NULL);
virtual video::IImageLoader* getImageLoaderForFile(const io::path& filename);
//! Creates a software image from a byte array.
/** \param useForeignMemory: If true, the image will use the data pointer
directly and own it from now on, which means it will also try to delete [] the

View File

@ -416,7 +416,7 @@ IAnimatedMeshSceneNode* CSceneManager::addAnimatedMeshSceneNode(IAnimatedMesh* m
IAnimatedMeshSceneNode* node =
new CAnimatedMeshSceneNode(mesh, parent, this, id, position, rotation, scale);
node->drop();
node->setMesh(mesh);
return node;
}

View File

@ -1470,7 +1470,7 @@ bool CSkinnedMesh::sortJointInfluenceFunc(const JointInfluence& a,
void CSkinnedMesh::convertForSkinning()
{
if (HardwareSkinning) return;
/* if (HardwareSkinning) return;
setHardwareSkinning(true);
WeightInfluence wi;
@ -1534,7 +1534,7 @@ void CSkinnedMesh::convertForSkinning()
}
SkinnedLastFrame = false;
skinMesh();
m_total_joints = m_current_joint;
m_total_joints = m_current_joint;*/
}
void CSkinnedMesh::computeWeightInfluence(SJoint *joint, size_t &index, WeightInfluence& wi)
@ -1558,7 +1558,7 @@ void CSkinnedMesh::computeWeightInfluence(SJoint *joint, size_t &index, WeightIn
void CSkinnedMesh::convertMeshToTangents(bool(*predicate)(IMeshBuffer*))
{
bool recalculate_animation = false;
/* bool recalculate_animation = false;
toStaticPose();
for (u32 b = 0; b < LocalBuffers.size(); b++)
{
@ -1568,6 +1568,21 @@ void CSkinnedMesh::convertMeshToTangents(bool(*predicate)(IMeshBuffer*))
if (ssmb)
{
if (!predicate(ssmb)) continue;
ssmb->Vertices_Tangents.set_used(ssmb->Vertices_Standard.size());
for (unsigned i = 0; i < ssmb->Vertices_Tangents.size(); i++)
{
ssmb->Vertices_Tangents[i] = video::S3DVertexTangents(ssmb->Vertices_Standard[i].Pos,
ssmb->Vertices_Standard[i].Normal,ssmb->Vertices_Standard[i].Color,
ssmb->Vertices_Standard[i].TCoords);
if (!ssmb->m_tangents_map.empty())
{
ssmb->Vertices_Tangents[i].Tangent = ssmb->m_tangents_map.find(i)->getValue().first;
ssmb->Vertices_Tangents[i].Binormal = ssmb->m_tangents_map.find(i)->getValue().second.first;
ssmb->Vertices_Tangents[i].m_bitangent_sign = ssmb->m_tangents_map.find(i)->getValue().second.second;
}
}
recalculate_joints = true;
recalculate_animation = true;
@ -1596,43 +1611,62 @@ void CSkinnedMesh::convertMeshToTangents(bool(*predicate)(IMeshBuffer*))
const s32 index_count = tmp_indices.size();
u16* idx = tmp_indices.pointer();
video::S3DVertexTangents* v = ssmb->Vertices_Tangents.pointer();
core::vector3df local_normal;
for (s32 i = 0; i < index_count; i += 3)
core::vector3df local_normal;
if (!ssmb->m_tangents_map.empty())
{
for (unsigned i = 0; i < ssmb->Vertices_Tangents.size(); i++)
{
auto a = ssmb->m_tangents_map.find(v[i].Pos);
if (a)
{
v[i].Tangent = a->getValue().first;
v[i].Binormal = a->getValue().second.first;
v[i].m_bitangent_sign = a->getValue().second.second;
}
else
{
printf("ddd\n");
}
}
}
else
{
calculateTangents(
local_normal,
v[idx[i+0]].Tangent,
v[idx[i+0]].Binormal,
v[idx[i+0]].Pos,
v[idx[i+1]].Pos,
v[idx[i+2]].Pos,
v[idx[i+0]].TCoords,
v[idx[i+1]].TCoords,
v[idx[i+2]].TCoords);
for (s32 i = 0; i < index_count; i += 3)
{
calculateTangents(
local_normal,
v[idx[i+0]].Tangent,
v[idx[i+0]].Binormal,
v[idx[i+0]].Pos,
v[idx[i+1]].Pos,
v[idx[i+2]].Pos,
v[idx[i+0]].TCoords,
v[idx[i+1]].TCoords,
v[idx[i+2]].TCoords);
calculateTangents(
local_normal,
v[idx[i+1]].Tangent,
v[idx[i+1]].Binormal,
v[idx[i+1]].Pos,
v[idx[i+2]].Pos,
v[idx[i+0]].Pos,
v[idx[i+1]].TCoords,
v[idx[i+2]].TCoords,
v[idx[i+0]].TCoords);
calculateTangents(
local_normal,
v[idx[i+1]].Tangent,
v[idx[i+1]].Binormal,
v[idx[i+1]].Pos,
v[idx[i+2]].Pos,
v[idx[i+0]].Pos,
v[idx[i+1]].TCoords,
v[idx[i+2]].TCoords,
v[idx[i+0]].TCoords);
calculateTangents(
local_normal,
v[idx[i+2]].Tangent,
v[idx[i+2]].Binormal,
v[idx[i+2]].Pos,
v[idx[i+0]].Pos,
v[idx[i+1]].Pos,
v[idx[i+2]].TCoords,
v[idx[i+0]].TCoords,
v[idx[i+1]].TCoords);
}
calculateTangents(
local_normal,
v[idx[i+2]].Tangent,
v[idx[i+2]].Binormal,
v[idx[i+2]].Pos,
v[idx[i+0]].Pos,
v[idx[i+1]].Pos,
v[idx[i+2]].TCoords,
v[idx[i+0]].TCoords,
v[idx[i+1]].TCoords);
}
ssmb->Indices = tmp_indices;
ssmb->Vertices_Standard.clear();
ssmb->VertexType = video::EVT_TANGENTS;
}
@ -1661,7 +1695,7 @@ void CSkinnedMesh::convertMeshToTangents(bool(*predicate)(IMeshBuffer*))
{
PreparedForSkinning = false;
checkForAnimation();
}
}*/
}
void CSkinnedMesh::calculateTangents(

View File

@ -0,0 +1,88 @@
# cmake build file for squish
# by Stefan Roettger (snroettg@gmail.com)
# updated by Simon Brown (si@sjbrown.co.uk)
# features:
# uses -fopenmp when available
# use BUILD_SQUISH_WITH_OPENMP to override
# Xcode: builds universal binaries, uses SSE2 on i386 and Altivec on ppc
# Unix and VS: SSE2 support is enabled by default
# use BUILD_SQUISH_WITH_SSE2 and BUILD_SQUISH_WITH_ALTIVEC to override
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
OPTION(BUILD_SQUISH_WITH_OPENMP "Build with OpenMP." OFF)
OPTION(BUILD_SQUISH_WITH_SSE2 "Build with SSE2." ON)
OPTION(BUILD_SQUISH_WITH_ALTIVEC "Build with Altivec." OFF)
OPTION(BUILD_SHARED_LIBS "Build shared libraries." OFF)
OPTION(BUILD_SQUISH_EXTRA "Build extra source code." OFF)
IF (BUILD_SQUISH_WITH_OPENMP)
FIND_PACKAGE(OpenMP)
IF (OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ADD_DEFINITIONS(-DSQUISH_USE_OPENMP)
ENDIF()
ENDIF()
IF (CMAKE_GENERATOR STREQUAL "Xcode")
SET(CMAKE_OSX_ARCHITECTURES "i386;ppc")
ELSE (CMAKE_GENERATOR STREQUAL "Xcode")
IF (BUILD_SQUISH_WITH_SSE2 AND NOT WIN32)
ADD_DEFINITIONS(-DSQUISH_USE_SSE=2 -msse2)
ENDIF (BUILD_SQUISH_WITH_SSE2 AND NOT WIN32)
IF (BUILD_SQUISH_WITH_ALTIVEC AND NOT WIN32)
ADD_DEFINITIONS(-DSQUISH_USE_ALTIVEC=1 -maltivec)
ENDIF (BUILD_SQUISH_WITH_ALTIVEC AND NOT WIN32)
ENDIF (CMAKE_GENERATOR STREQUAL "Xcode")
SET(SQUISH_HDRS
squish.h
)
SET(SQUISH_SRCS
alpha.cpp
alpha.h
clusterfit.cpp
clusterfit.h
colourblock.cpp
colourblock.h
colourfit.cpp
colourfit.h
colourset.cpp
colourset.h
maths.cpp
maths.h
rangefit.cpp
rangefit.h
simd.h
simd_float.h
simd_sse.h
simd_ve.h
singlecolourfit.cpp
singlecolourfit.h
singlecolourlookup.inl
squish.cpp
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_LIBRARY(squish ${SQUISH_SRCS} ${SQUISH_HDRS})
SET_TARGET_PROPERTIES(
squish PROPERTIES
PUBLIC_HEADER "${SQUISH_HDRS}"
VERSION 0.0
SOVERSION 0.0
DEBUG_POSTFIX "d"
XCODE_ATTRIBUTE_GCC_PREPROCESSOR_DEFINITIONS "$(SQUISH_CPP_$(CURRENT_ARCH))"
XCODE_ATTRIBUTE_OTHER_CFLAGS "$(SQUISH_CFLAGS_$(CURRENT_ARCH))"
XCODE_ATTRIBUTE_SQUISH_CPP_i386 "SQUISH_USE_SSE=2"
XCODE_ATTRIBUTE_SQUISH_CFLAGS_i386 ""
XCODE_ATTRIBUTE_SQUISH_CPP_ppc "SQUISH_USE_ALTIVEC=1"
XCODE_ATTRIBUTE_SQUISH_CFLAGS_ppc "-maltivec"
)

View File

@ -0,0 +1,66 @@
1.15
* parallel compression using openmp with cmake (Marian Krivos / Stefan Roettger)
* parallel decompression using openmp with cmake (Stefan Roettger)
1.14
* backport BGRA support
* backport BC4 and BC5 support
* backport BlockMSE support
1.11-1.13
* added support for CMake and QMake (Stefan Roettger)
* misc. minor changes on the build system (Stefan Roettger)
* added svg icon (Stefan Roettger)
1.10
* Iterative cluster fit is now considered to be a new compression mode
* The core cluster fit is now 4x faster using contributions by Ignacio
Castano from NVIDIA
* The single colour lookup table has been halved by exploiting symmetry
1.9
* Added contributed SSE1 truncate implementation
* Changed use of SQUISH_USE_SSE to be 1 for SSE and 2 for SSE2 instructions
* Cluster fit is now iterative to further reduce image error
1.8
* Switched from using floor to trunc for much better SSE performance (again)
* Xcode build now expects libpng in /usr/local for extra/squishpng
1.7
* Fixed floating-point equality issue in clusterfit sort (x86 affected only)
* Implemented proper SSE(2) floor function for 50% speedup on SSE builds
* The range fit implementation now uses the correct colour metric
1.6
* Fixed bug in CompressImage where masked pixels were not skipped over
* DXT3 and DXT5 alpha compression now properly use the mask to ignore pixels
* Fixed major DXT1 bug that can generate unexpected transparent pixels
1.5
* Added CompressMasked function to handle incomplete DXT blocks more cleanly
* Added kWeightColourByAlpha flag for better quality images when alpha blending
1.4
* Fixed stack overflow in rangefit
1.3
* Worked around SSE floor implementation bug, proper fix needed!
* This release has visual studio and makefile builds that work
1.2
* Added provably optimal single colour compressor
* Added extra/squishgen.cpp that generates single colour lookup tables
1.1
* Fixed a DXT1 colour output bug
* Changed argument order for Decompress function to match Compress
* Added GetStorageRequirements function
* Added CompressImage function
* Added DecompressImage function
* Moved squishtool.cpp to extra/squishpng.cpp
* Added extra/squishtest.cpp
1.0
* Initial release

214
lib/libsquish/Doxyfile Normal file
View File

@ -0,0 +1,214 @@
# Doxyfile 1.4.6
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = squish
PROJECT_NUMBER = 1.14
OUTPUT_DIRECTORY = docs
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = NO
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = squish.h
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOTFILE_DIRS =
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO

20
lib/libsquish/LICENSE.txt Normal file
View File

@ -0,0 +1,20 @@
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

65
lib/libsquish/Makefile Normal file
View File

@ -0,0 +1,65 @@
include config
VER = 1.15
SOVER = 0
SRC = alpha.cpp clusterfit.cpp colourblock.cpp colourfit.cpp colourset.cpp maths.cpp rangefit.cpp singlecolourfit.cpp squish.cpp
HDR = alpha.h clusterfit.h colourblock.h colourfit.h colourset.h maths.h rangefit.h singlecolourfit.h squish.h
HDR += config.h simd.h simd_float.h simd_sse.h simd_ve.h singlecolourlookup.inl
OBJ = $(SRC:%.cpp=%.o)
SOLIB = libsquish.so.$(SOVER)
LIB = $(SOLIB).0
CPPFLAGS += -fPIC
LIBA = libsquish.a
.PHONY: all install uninstall docs tgz clean
all: $(LIB) $(LIBA) docs libsquish.pc
install: $(LIB) $(LIBA) libsquish.pc
$(INSTALL_DIRECTORY) $(INSTALL_DIR)/include $(INSTALL_DIR)/$(LIB_PATH)
$(INSTALL_FILE) squish.h $(INSTALL_DIR)/include
$(INSTALL_FILE) $(LIBA) $(INSTALL_DIR)/$(LIB_PATH)
ifneq ($(USE_SHARED),0)
$(INSTALL_FILE) $(LIB) $(INSTALL_DIR)/$(LIB_PATH)
ln -s $(LIB) $(INSTALL_DIR)/$(LIB_PATH)/$(SOLIB)
ln -s $(LIB) $(INSTALL_DIR)/$(LIB_PATH)/libsquish.so
$(INSTALL_DIRECTORY) $(INSTALL_DIR)/$(LIB_PATH)/pkgconfig
$(INSTALL_FILE) libsquish.pc $(INSTALL_DIR)/$(LIB_PATH)/pkgconfig
endif
uninstall:
$(RM) $(INSTALL_DIR)/include/squish.h
$(RM) $(INSTALL_DIR)/$(LIB_PATH)/$(LIBA)
-$(RM) $(INSTALL_DIR)/$(LIB_PATH)/$(LIB)
-$(RM) $(INSTALL_DIR)/$(LIB_PATH)/$(SOLIB)
-$(RM) $(INSTALL_DIR)/$(LIB_PATH)/libsquish.so
-$(RM) $(INSTALL_DIR)/$(LIB_PATH)/pkgconfig/libsquish.pc
$(LIB): $(OBJ)
ifneq ($(USE_SHARED),0)
$(CXX) $(LDFLAGS) -shared -Wl,-soname,$(SOLIB) -o $@ $(OBJ)
endif
$(LIBA): $(OBJ)
$(AR) cr $@ $?
@ranlib $@
docs: $(SRC) $(HDR)
@if [ -x "`command -v doxygen`" ]; then doxygen; fi
libsquish.pc: libsquish.pc.in
@sed 's|@PREFIX@|$(PREFIX)|;s|@LIB_PATH@|$(LIB_PATH)|' $@.in > $@
tgz: clean
tar zcf libsquish-$(VER).tgz $(SRC) $(HDR) Makefile config CMakeLists.txt CMakeModules libSquish.* README.txt LICENSE.txt ChangeLog.txt Doxyfile libsquish.pc.in extra --exclude \*.svn\*
%.o: %.cpp
$(CXX) $(CPPFLAGS) -I. $(CXXFLAGS) -o $@ -c $<
clean:
$(RM) $(OBJ) $(LIB) $(LIBA) libsquish.pc
@-$(RM) -rf docs

18
lib/libsquish/README.txt Normal file
View File

@ -0,0 +1,18 @@
LICENSE
-------
The squish library is distributed under the terms and conditions of the MIT
license. This license is specified at the top of each source file and must be
preserved in its entirety.
BUILDING AND INSTALLING THE LIBRARY
-----------------------------------
The preferred way to install the library on Unix/Mac (and Windows) is via cmake:
cmake . && make && sudo make install
REPORTING BUGS OR FEATURE REQUESTS
----------------------------------
Feedback can be sent to Simon Brown (the developer) at si@sjbrown.co.uk
Feedback can also be sent to Stefan Roettger (the maintainer) at snroettg@gmail.com

350
lib/libsquish/alpha.cpp Normal file
View File

@ -0,0 +1,350 @@
/* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */
#include "alpha.h"
#include <climits>
#include <algorithm>
namespace squish {
static int FloatToInt( float a, int limit )
{
// use ANSI round-to-zero behaviour to get round-to-nearest
int i = ( int )( a + 0.5f );
// clamp to the limit
if( i < 0 )
i = 0;
else if( i > limit )
i = limit;
// done
return i;
}
void CompressAlphaDxt3( u8 const* rgba, int mask, void* block )
{
u8* bytes = reinterpret_cast< u8* >( block );
// quantise and pack the alpha values pairwise
for( int i = 0; i < 8; ++i )
{
// quantise down to 4 bits
float alpha1 = ( float )rgba[8*i + 3] * ( 15.0f/255.0f );
float alpha2 = ( float )rgba[8*i + 7] * ( 15.0f/255.0f );
int quant1 = FloatToInt( alpha1, 15 );
int quant2 = FloatToInt( alpha2, 15 );
// set alpha to zero where masked
int bit1 = 1 << ( 2*i );
int bit2 = 1 << ( 2*i + 1 );
if( ( mask & bit1 ) == 0 )
quant1 = 0;
if( ( mask & bit2 ) == 0 )
quant2 = 0;
// pack into the byte
bytes[i] = ( u8 )( quant1 | ( quant2 << 4 ) );
}
}
void DecompressAlphaDxt3( u8* rgba, void const* block )
{
u8 const* bytes = reinterpret_cast< u8 const* >( block );
// unpack the alpha values pairwise
for( int i = 0; i < 8; ++i )
{
// quantise down to 4 bits
u8 quant = bytes[i];
// unpack the values
u8 lo = quant & 0x0f;
u8 hi = quant & 0xf0;
// convert back up to bytes
rgba[8*i + 3] = lo | ( lo << 4 );
rgba[8*i + 7] = hi | ( hi >> 4 );
}
}
static void FixRange( int& min, int& max, int steps )
{
if( max - min < steps )
max = std::min( min + steps, 255 );
if( max - min < steps )
min = std::max( 0, max - steps );
}
static int FitCodes( u8 const* rgba, int mask, u8 const* codes, u8* indices )
{
// fit each alpha value to the codebook
int err = 0;
for( int i = 0; i < 16; ++i )
{
// check this pixel is valid
int bit = 1 << i;
if( ( mask & bit ) == 0 )
{
// use the first code
indices[i] = 0;
continue;
}
// find the least error and corresponding index
int value = rgba[4*i + 3];
int least = INT_MAX;
int index = 0;
for( int j = 0; j < 8; ++j )
{
// get the squared error from this code
int dist = ( int )value - ( int )codes[j];
dist *= dist;
// compare with the best so far
if( dist < least )
{
least = dist;
index = j;
}
}
// save this index and accumulate the error
indices[i] = ( u8 )index;
err += least;
}
// return the total error
return err;
}
static void WriteAlphaBlock( int alpha0, int alpha1, u8 const* indices, void* block )
{
u8* bytes = reinterpret_cast< u8* >( block );
// write the first two bytes
bytes[0] = ( u8 )alpha0;
bytes[1] = ( u8 )alpha1;
// pack the indices with 3 bits each
u8* dest = bytes + 2;
u8 const* src = indices;
for( int i = 0; i < 2; ++i )
{
// pack 8 3-bit values
int value = 0;
for( int j = 0; j < 8; ++j )
{
int index = *src++;
value |= ( index << 3*j );
}
// store in 3 bytes
for( int j = 0; j < 3; ++j )
{
int byte = ( value >> 8*j ) & 0xff;
*dest++ = ( u8 )byte;
}
}
}
static void WriteAlphaBlock5( int alpha0, int alpha1, u8 const* indices, void* block )
{
// check the relative values of the endpoints
if( alpha0 > alpha1 )
{
// swap the indices
u8 swapped[16];
for( int i = 0; i < 16; ++i )
{
u8 index = indices[i];
if( index == 0 )
swapped[i] = 1;
else if( index == 1 )
swapped[i] = 0;
else if( index <= 5 )
swapped[i] = 7 - index;
else
swapped[i] = index;
}
// write the block
WriteAlphaBlock( alpha1, alpha0, swapped, block );
}
else
{
// write the block
WriteAlphaBlock( alpha0, alpha1, indices, block );
}
}
static void WriteAlphaBlock7( int alpha0, int alpha1, u8 const* indices, void* block )
{
// check the relative values of the endpoints
if( alpha0 < alpha1 )
{
// swap the indices
u8 swapped[16];
for( int i = 0; i < 16; ++i )
{
u8 index = indices[i];
if( index == 0 )
swapped[i] = 1;
else if( index == 1 )
swapped[i] = 0;
else
swapped[i] = 9 - index;
}
// write the block
WriteAlphaBlock( alpha1, alpha0, swapped, block );
}
else
{
// write the block
WriteAlphaBlock( alpha0, alpha1, indices, block );
}
}
void CompressAlphaDxt5( u8 const* rgba, int mask, void* block )
{
// get the range for 5-alpha and 7-alpha interpolation
int min5 = 255;
int max5 = 0;
int min7 = 255;
int max7 = 0;
for( int i = 0; i < 16; ++i )
{
// check this pixel is valid
int bit = 1 << i;
if( ( mask & bit ) == 0 )
continue;
// incorporate into the min/max
int value = rgba[4*i + 3];
if( value < min7 )
min7 = value;
if( value > max7 )
max7 = value;
if( value != 0 && value < min5 )
min5 = value;
if( value != 255 && value > max5 )
max5 = value;
}
// handle the case that no valid range was found
if( min5 > max5 )
min5 = max5;
if( min7 > max7 )
min7 = max7;
// fix the range to be the minimum in each case
FixRange( min5, max5, 5 );
FixRange( min7, max7, 7 );
// set up the 5-alpha code book
u8 codes5[8];
codes5[0] = ( u8 )min5;
codes5[1] = ( u8 )max5;
for( int i = 1; i < 5; ++i )
codes5[1 + i] = ( u8 )( ( ( 5 - i )*min5 + i*max5 )/5 );
codes5[6] = 0;
codes5[7] = 255;
// set up the 7-alpha code book
u8 codes7[8];
codes7[0] = ( u8 )min7;
codes7[1] = ( u8 )max7;
for( int i = 1; i < 7; ++i )
codes7[1 + i] = ( u8 )( ( ( 7 - i )*min7 + i*max7 )/7 );
// fit the data to both code books
u8 indices5[16];
u8 indices7[16];
int err5 = FitCodes( rgba, mask, codes5, indices5 );
int err7 = FitCodes( rgba, mask, codes7, indices7 );
// save the block with least error
if( err5 <= err7 )
WriteAlphaBlock5( min5, max5, indices5, block );
else
WriteAlphaBlock7( min7, max7, indices7, block );
}
void DecompressAlphaDxt5( u8* rgba, void const* block )
{
// get the two alpha values
u8 const* bytes = reinterpret_cast< u8 const* >( block );
int alpha0 = bytes[0];
int alpha1 = bytes[1];
// compare the values to build the codebook
u8 codes[8];
codes[0] = ( u8 )alpha0;
codes[1] = ( u8 )alpha1;
if( alpha0 <= alpha1 )
{
// use 5-alpha codebook
for( int i = 1; i < 5; ++i )
codes[1 + i] = ( u8 )( ( ( 5 - i )*alpha0 + i*alpha1 )/5 );
codes[6] = 0;
codes[7] = 255;
}
else
{
// use 7-alpha codebook
for( int i = 1; i < 7; ++i )
codes[1 + i] = ( u8 )( ( ( 7 - i )*alpha0 + i*alpha1 )/7 );
}
// decode the indices
u8 indices[16];
u8 const* src = bytes + 2;
u8* dest = indices;
for( int i = 0; i < 2; ++i )
{
// grab 3 bytes
int value = 0;
for( int j = 0; j < 3; ++j )
{
int byte = *src++;
value |= ( byte << 8*j );
}
// unpack 8 3-bit values from it
for( int j = 0; j < 8; ++j )
{
int index = ( value >> 3*j ) & 0x7;
*dest++ = ( u8 )index;
}
}
// write out the indexed codebook values
for( int i = 0; i < 16; ++i )
rgba[4*i + 3] = codes[indices[i]];
}
} // namespace squish

41
lib/libsquish/alpha.h Normal file
View File

@ -0,0 +1,41 @@
/* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */
#ifndef SQUISH_ALPHA_H
#define SQUISH_ALPHA_H
#include "squish.h"
namespace squish {
void CompressAlphaDxt3( u8 const* rgba, int mask, void* block );
void CompressAlphaDxt5( u8 const* rgba, int mask, void* block );
void DecompressAlphaDxt3( u8* rgba, void const* block );
void DecompressAlphaDxt5( u8* rgba, void const* block );
} // namespace squish
#endif // ndef SQUISH_ALPHA_H

View File

@ -0,0 +1,392 @@
/* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Copyright (c) 2007 Ignacio Castano icastano@nvidia.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */
#include "clusterfit.h"
#include "colourset.h"
#include "colourblock.h"
#include <cfloat>
namespace squish {
ClusterFit::ClusterFit( ColourSet const* colours, int flags, float* metric )
: ColourFit( colours, flags )
{
// set the iteration count
m_iterationCount = ( m_flags & kColourIterativeClusterFit ) ? kMaxIterations : 1;
// initialise the metric (old perceptual = 0.2126f, 0.7152f, 0.0722f)
if( metric )
m_metric = Vec4( metric[0], metric[1], metric[2], 1.0f );
else
m_metric = VEC4_CONST( 1.0f );
// initialise the best error
m_besterror = VEC4_CONST( FLT_MAX );
// cache some values
int const count = m_colours->GetCount();
Vec3 const* values = m_colours->GetPoints();
// get the covariance matrix
Sym3x3 covariance = ComputeWeightedCovariance( count, values, m_colours->GetWeights() );
// compute the principle component
m_principle = ComputePrincipleComponent( covariance );
}
bool ClusterFit::ConstructOrdering( Vec3 const& axis, int iteration )
{
// cache some values
int const count = m_colours->GetCount();
Vec3 const* values = m_colours->GetPoints();
// build the list of dot products
float dps[16];
u8* order = ( u8* )m_order + 16*iteration;
for( int i = 0; i < count; ++i )
{
dps[i] = Dot( values[i], axis );
order[i] = ( u8 )i;
}
// stable sort using them
for( int i = 0; i < count; ++i )
{
for( int j = i; j > 0 && dps[j] < dps[j - 1]; --j )
{
std::swap( dps[j], dps[j - 1] );
std::swap( order[j], order[j - 1] );
}
}
// check this ordering is unique
for( int it = 0; it < iteration; ++it )
{
u8 const* prev = ( u8* )m_order + 16*it;
bool same = true;
for( int i = 0; i < count; ++i )
{
if( order[i] != prev[i] )
{
same = false;
break;
}
}
if( same )
return false;
}
// copy the ordering and weight all the points
Vec3 const* unweighted = m_colours->GetPoints();
float const* weights = m_colours->GetWeights();
m_xsum_wsum = VEC4_CONST( 0.0f );
for( int i = 0; i < count; ++i )
{
int j = order[i];
Vec4 p( unweighted[j].X(), unweighted[j].Y(), unweighted[j].Z(), 1.0f );
Vec4 w( weights[j] );
Vec4 x = p*w;
m_points_weights[i] = x;
m_xsum_wsum += x;
}
return true;
}
void ClusterFit::Compress3( void* block )
{
// declare variables
int const count = m_colours->GetCount();
Vec4 const two = VEC4_CONST( 2.0 );
Vec4 const one = VEC4_CONST( 1.0f );
Vec4 const half_half2( 0.5f, 0.5f, 0.5f, 0.25f );
Vec4 const zero = VEC4_CONST( 0.0f );
Vec4 const half = VEC4_CONST( 0.5f );
Vec4 const grid( 31.0f, 63.0f, 31.0f, 0.0f );
Vec4 const gridrcp( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f, 0.0f );
// prepare an ordering using the principle axis
ConstructOrdering( m_principle, 0 );
// check all possible clusters and iterate on the total order
Vec4 beststart = VEC4_CONST( 0.0f );
Vec4 bestend = VEC4_CONST( 0.0f );
Vec4 besterror = m_besterror;
u8 bestindices[16];
int bestiteration = 0;
int besti = 0, bestj = 0;
// loop over iterations (we avoid the case that all points in first or last cluster)
for( int iterationIndex = 0;; )
{
// first cluster [0,i) is at the start
Vec4 part0 = VEC4_CONST( 0.0f );
for( int i = 0; i < count; ++i )
{
// second cluster [i,j) is half along
Vec4 part1 = ( i == 0 ) ? m_points_weights[0] : VEC4_CONST( 0.0f );
int jmin = ( i == 0 ) ? 1 : i;
for( int j = jmin;; )
{
// last cluster [j,count) is at the end
Vec4 part2 = m_xsum_wsum - part1 - part0;
// compute least squares terms directly
Vec4 alphax_sum = MultiplyAdd( part1, half_half2, part0 );
Vec4 alpha2_sum = alphax_sum.SplatW();
Vec4 betax_sum = MultiplyAdd( part1, half_half2, part2 );
Vec4 beta2_sum = betax_sum.SplatW();
Vec4 alphabeta_sum = ( part1*half_half2 ).SplatW();
// compute the least-squares optimal points
Vec4 factor = Reciprocal( NegativeMultiplySubtract( alphabeta_sum, alphabeta_sum, alpha2_sum*beta2_sum ) );
Vec4 a = NegativeMultiplySubtract( betax_sum, alphabeta_sum, alphax_sum*beta2_sum )*factor;
Vec4 b = NegativeMultiplySubtract( alphax_sum, alphabeta_sum, betax_sum*alpha2_sum )*factor;
// clamp to the grid
a = Min( one, Max( zero, a ) );
b = Min( one, Max( zero, b ) );
a = Truncate( MultiplyAdd( grid, a, half ) )*gridrcp;
b = Truncate( MultiplyAdd( grid, b, half ) )*gridrcp;
// compute the error (we skip the constant xxsum)
Vec4 e1 = MultiplyAdd( a*a, alpha2_sum, b*b*beta2_sum );
Vec4 e2 = NegativeMultiplySubtract( a, alphax_sum, a*b*alphabeta_sum );
Vec4 e3 = NegativeMultiplySubtract( b, betax_sum, e2 );
Vec4 e4 = MultiplyAdd( two, e3, e1 );
// apply the metric to the error term
Vec4 e5 = e4*m_metric;
Vec4 error = e5.SplatX() + e5.SplatY() + e5.SplatZ();
// keep the solution if it wins
if( CompareAnyLessThan( error, besterror ) )
{
beststart = a;
bestend = b;
besti = i;
bestj = j;
besterror = error;
bestiteration = iterationIndex;
}
// advance
if( j == count )
break;
part1 += m_points_weights[j];
++j;
}
// advance
part0 += m_points_weights[i];
}
// stop if we didn't improve in this iteration
if( bestiteration != iterationIndex )
break;
// advance if possible
++iterationIndex;
if( iterationIndex == m_iterationCount )
break;
// stop if a new iteration is an ordering that has already been tried
Vec3 axis = ( bestend - beststart ).GetVec3();
if( !ConstructOrdering( axis, iterationIndex ) )
break;
}
// save the block if necessary
if( CompareAnyLessThan( besterror, m_besterror ) )
{
// remap the indices
u8 const* order = ( u8* )m_order + 16*bestiteration;
u8 unordered[16];
for( int m = 0; m < besti; ++m )
unordered[order[m]] = 0;
for( int m = besti; m < bestj; ++m )
unordered[order[m]] = 2;
for( int m = bestj; m < count; ++m )
unordered[order[m]] = 1;
m_colours->RemapIndices( unordered, bestindices );
// save the block
WriteColourBlock3( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error
m_besterror = besterror;
}
}
void ClusterFit::Compress4( void* block )
{
// declare variables
int const count = m_colours->GetCount();
Vec4 const two = VEC4_CONST( 2.0f );
Vec4 const one = VEC4_CONST( 1.0f );
Vec4 const onethird_onethird2( 1.0f/3.0f, 1.0f/3.0f, 1.0f/3.0f, 1.0f/9.0f );
Vec4 const twothirds_twothirds2( 2.0f/3.0f, 2.0f/3.0f, 2.0f/3.0f, 4.0f/9.0f );
Vec4 const twonineths = VEC4_CONST( 2.0f/9.0f );
Vec4 const zero = VEC4_CONST( 0.0f );
Vec4 const half = VEC4_CONST( 0.5f );
Vec4 const grid( 31.0f, 63.0f, 31.0f, 0.0f );
Vec4 const gridrcp( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f, 0.0f );
// prepare an ordering using the principle axis
ConstructOrdering( m_principle, 0 );
// check all possible clusters and iterate on the total order
Vec4 beststart = VEC4_CONST( 0.0f );
Vec4 bestend = VEC4_CONST( 0.0f );
Vec4 besterror = m_besterror;
u8 bestindices[16];
int bestiteration = 0;
int besti = 0, bestj = 0, bestk = 0;
// loop over iterations (we avoid the case that all points in first or last cluster)
for( int iterationIndex = 0;; )
{
// first cluster [0,i) is at the start
Vec4 part0 = VEC4_CONST( 0.0f );
for( int i = 0; i < count; ++i )
{
// second cluster [i,j) is one third along
Vec4 part1 = VEC4_CONST( 0.0f );
for( int j = i;; )
{
// third cluster [j,k) is two thirds along
Vec4 part2 = ( j == 0 ) ? m_points_weights[0] : VEC4_CONST( 0.0f );
int kmin = ( j == 0 ) ? 1 : j;
for( int k = kmin;; )
{
// last cluster [k,count) is at the end
Vec4 part3 = m_xsum_wsum - part2 - part1 - part0;
// compute least squares terms directly
Vec4 const alphax_sum = MultiplyAdd( part2, onethird_onethird2, MultiplyAdd( part1, twothirds_twothirds2, part0 ) );
Vec4 const alpha2_sum = alphax_sum.SplatW();
Vec4 const betax_sum = MultiplyAdd( part1, onethird_onethird2, MultiplyAdd( part2, twothirds_twothirds2, part3 ) );
Vec4 const beta2_sum = betax_sum.SplatW();
Vec4 const alphabeta_sum = twonineths*( part1 + part2 ).SplatW();
// compute the least-squares optimal points
Vec4 factor = Reciprocal( NegativeMultiplySubtract( alphabeta_sum, alphabeta_sum, alpha2_sum*beta2_sum ) );
Vec4 a = NegativeMultiplySubtract( betax_sum, alphabeta_sum, alphax_sum*beta2_sum )*factor;
Vec4 b = NegativeMultiplySubtract( alphax_sum, alphabeta_sum, betax_sum*alpha2_sum )*factor;
// clamp to the grid
a = Min( one, Max( zero, a ) );
b = Min( one, Max( zero, b ) );
a = Truncate( MultiplyAdd( grid, a, half ) )*gridrcp;
b = Truncate( MultiplyAdd( grid, b, half ) )*gridrcp;
// compute the error (we skip the constant xxsum)
Vec4 e1 = MultiplyAdd( a*a, alpha2_sum, b*b*beta2_sum );
Vec4 e2 = NegativeMultiplySubtract( a, alphax_sum, a*b*alphabeta_sum );
Vec4 e3 = NegativeMultiplySubtract( b, betax_sum, e2 );
Vec4 e4 = MultiplyAdd( two, e3, e1 );
// apply the metric to the error term
Vec4 e5 = e4*m_metric;
Vec4 error = e5.SplatX() + e5.SplatY() + e5.SplatZ();
// keep the solution if it wins
if( CompareAnyLessThan( error, besterror ) )
{
beststart = a;
bestend = b;
besterror = error;
besti = i;
bestj = j;
bestk = k;
bestiteration = iterationIndex;
}
// advance
if( k == count )
break;
part2 += m_points_weights[k];
++k;
}
// advance
if( j == count )
break;
part1 += m_points_weights[j];
++j;
}
// advance
part0 += m_points_weights[i];
}
// stop if we didn't improve in this iteration
if( bestiteration != iterationIndex )
break;
// advance if possible
++iterationIndex;
if( iterationIndex == m_iterationCount )
break;
// stop if a new iteration is an ordering that has already been tried
Vec3 axis = ( bestend - beststart ).GetVec3();
if( !ConstructOrdering( axis, iterationIndex ) )
break;
}
// save the block if necessary
if( CompareAnyLessThan( besterror, m_besterror ) )
{
// remap the indices
u8 const* order = ( u8* )m_order + 16*bestiteration;
u8 unordered[16];
for( int m = 0; m < besti; ++m )
unordered[order[m]] = 0;
for( int m = besti; m < bestj; ++m )
unordered[order[m]] = 2;
for( int m = bestj; m < bestk; ++m )
unordered[order[m]] = 3;
for( int m = bestk; m < count; ++m )
unordered[order[m]] = 1;
m_colours->RemapIndices( unordered, bestindices );
// save the block
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error
m_besterror = besterror;
}
}
} // namespace squish

Some files were not shown because too many files have changed in this diff Show More