Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
commonMain.ru.casperix.opengl.renderer.generated.Resources.kt Maven / Gradle / Ivy
package ru.casperix.opengl.renderer.generated
/**
* Resources.
*
* Don't edit manually.
*
* Autogenerated at Thu Sep 19 15:05:00 MSK 2024
*/
object Resources {
val `shader2d_frag` =
"""
uniform vec3 uAmbientColor;
#ifdef VERTEX_TEXTURE_COORD
in vec2 TexCoord;
#endif
#ifdef MATERIAL_TILE_MAP
uniform sampler2D uTileMapTexture;
uniform vec2 uTexScale;
uniform int uTileSmoothMode;
#endif
#ifdef MATERIAL_TEXTURE_ARRAY
uniform mediump sampler2DArray uTextureArray;
#endif
#ifdef MATERIAL_ALBEDO_MAP
uniform sampler2D uAlbedoTexture;
#endif
#ifdef MATERIAL_NORMAL_MAP
uniform sampler2D uNormalTexture;
#endif
#ifdef MATERIAL_NORMAL
in vec3 LightPosTS;
in vec3 PosTS;
#endif
#ifdef VERTEX_COLOR
in vec4 VertexColor;
#endif
#ifdef MATERIAL_COLOR
in vec4 MaterialColor;
#endif
out vec4 FragColor;
int getBestIndex(ivec4 tiles, vec4 weights) {
float c1 = dot(weights, vec4(equal(tiles, ivec4(tiles[0]))));
float c2 = dot(weights, vec4(equal(tiles, ivec4(tiles[1]))));
float c3 = dot(weights, vec4(equal(tiles, ivec4(tiles[2]))));
float c4 = dot(weights, vec4(equal(tiles, ivec4(tiles[3]))));
if (c1 >= c2 && c1 >= c3 && c1 >= c4) return 0;
if (c2 >= c1 && c2 >= c3 && c2 >= c4) return 1;
if (c3 >= c1 && c3 >= c2 && c3 >= c4) return 2;
if (c4 >= c1 && c4 >= c2 && c4 >= c3) return 3;
return 0;
}
#ifdef MATERIAL_TILE_MAP
ivec4 getTileType(vec2 texCoord) {
return ivec4(255.0 * texture(uTileMapTexture, texCoord));
}
#endif
float weight(vec2 offset) {
return 1.0 / length(offset);
}
#ifdef MATERIAL_NORMAL
float getLightByNormalTexture(vec3 normalColor) {
vec3 normalTS = normalize(normalColor * 2.0 - 1.0);
vec3 lightDir = normalize(LightPosTS - PosTS);
float lightness = max(0.0, dot(lightDir, normalTS));
return lightness;
}
#endif
int tileTypeHash(ivec4 source) {
return source.x + source.y * 256 + source.z * 65536;
}
void main() {
float lightness = 1.0;
vec4 albedoColor = vec4(1.0);
vec2 texScale = vec2(1.0);
#ifdef MATERIAL_TILE_MAP
vec2 tileMapSize = vec2(textureSize(uTileMapTexture, 0));
vec2 P = fract(TexCoord * tileMapSize + vec2(0.5));
vec2 weightMin = vec2(1.0) - P;
vec2 weightMax = P;
if (uTileSmoothMode == 2) {
weightMin = smoothstep(vec2(0, 0), vec2(1, 1), weightMin);
weightMax = smoothstep(vec2(0, 0), vec2(1, 1), weightMax);
}
float wA = weightMin.x * weightMin.y;
float wB = weightMax.x * weightMin.y;
float wC = weightMin.x * weightMax.y;
float wD = weightMax.x * weightMax.y;
float dtex = 0.5 / tileMapSize.x;
int albedoIndex = 0;
int normalIndex = 0;
if (uTileSmoothMode == 0) {
ivec4 tile = getTileType(TexCoord);
albedoIndex = tile.x;
normalIndex = tile.y;
} else if (uTileSmoothMode == 1 || uTileSmoothMode == 2) {
ivec4 tileA = getTileType(TexCoord + vec2(-dtex, -dtex));
ivec4 tileB = getTileType(TexCoord + vec2(dtex, -dtex));
ivec4 tileC = getTileType(TexCoord + vec2(-dtex, dtex));
ivec4 tileD = getTileType(TexCoord + vec2(dtex, dtex));
vec4 weights = vec4(wA, wB, wC, wD);
ivec4 hashList = ivec4(tileTypeHash(tileA), tileTypeHash(tileB), tileTypeHash(tileC), tileTypeHash(tileD));
int tileIndex = getBestIndex(hashList, weights);
ivec4 albedoList = ivec4(tileA.x, tileB.x, tileC.x, tileD.x);
ivec4 normalList = ivec4(tileA.y, tileB.y, tileC.y, tileD.y);
albedoIndex = albedoList[tileIndex];
normalIndex = normalList[tileIndex];
}
texScale = uTexScale * tileMapSize;
#endif
#ifdef MATERIAL_NORMAL_MAP
vec3 normalColor = texture(uNormalTexture, TexCoord * texScale).rgb;
lightness = getLightByNormalTexture(normalColor);
#endif
#ifdef MATERIAL_ALBEDO_MAP
albedoColor *= texture(uAlbedoTexture, TexCoord * texScale);
#endif
#ifdef MATERIAL_TEXTURE_ARRAY
#ifdef MATERIAL_NORMAL
vec3 normalColor = texture(uTextureArray, vec3(TexCoord * texScale, normalIndex)).rgb;
lightness = getLightByNormalTexture(normalColor);
#endif
albedoColor *= texture(uTextureArray, vec3(TexCoord * texScale, albedoIndex));
#endif
#ifdef VERTEX_COLOR
albedoColor *= VertexColor;
#endif
#ifdef MATERIAL_COLOR
albedoColor *= MaterialColor;
#endif
vec4 outputColor = albedoColor * lightness + albedoColor * vec4(uAmbientColor, 1.0);
#ifdef MATERIAL_TILE_GIRD
vec2 gird = fract(TexCoord * tileMapSize);
float border = 0.02;
if (abs(gird.x) < border || abs(gird.y) < border || abs(gird.x) > 1.0 - border || abs(gird.y) > 1.0 - border) {
outputColor.rgb = vec3(0.0);
}
#endif
#ifdef CONFIG_DISCARD_ALPHA
if (outputColor.a <= 0.01) {
discard;
}
#endif
#ifdef CONFIG_GAMMA_CORRECTION
float gamma = 2.2;
outputColor.rgb = pow(outputColor.rgb, vec3(1.0/gamma));
#endif
FragColor = outputColor;
}
"""
val `shader2d_vert` =
"""
layout (location = 1) in vec2 aPos;
#ifdef VERTEX_TEXTURE_COORD
layout (location = 2) in vec2 aTexCoord;
out vec2 TexCoord;
#endif
#ifdef VERTEX_COLOR3
layout (location = 3) in vec3 aVertexColor3;
#endif
#ifdef VERTEX_COLOR4
layout (location = 3) in vec4 aVertexColor4;
#endif
#ifdef VERTEX_COLOR
out vec4 VertexColor;
#endif
#ifdef MATERIAL_NORMAL
uniform vec3 uLightPos;
uniform vec3 uViewPos;
layout (location = 4) in vec2 aTangent;
out vec3 LightPosTS;
out vec3 ViewPosTS;
out vec3 PosTS;
#endif
uniform mat3 uModel;
uniform mat3 uProjectionViewModel;
#ifdef MATERIAL_COLOR
uniform vec4 uMaterialColor;
out vec4 MaterialColor;
#endif
void main()
{
#ifdef MATERIAL_NORMAL
mat3 normalMatrix = transpose(inverse(mat3(uModel)));
vec3 T = normalize(normalMatrix*vec3(aTangent, 0.0));
vec3 N = normalize(normalMatrix*vec3(0.0, 0.0, 1.0));
T = normalize(T - dot(T, N) * N);
vec3 B = cross(T, N);
mat3 TBN = transpose(mat3(T, B, N));
vec3 pos = uModel * vec3(aPos, 1.0);
LightPosTS = TBN * uLightPos;
ViewPosTS = TBN * uViewPos;
PosTS = TBN * pos;
#endif
gl_Position = vec4(uProjectionViewModel * vec3(aPos, 1.0), 1.0);
#ifdef VERTEX_TEXTURE_COORD
TexCoord = aTexCoord;
#endif
#ifdef VERTEX_COLOR3
VertexColor = vec4(aVertexColor3, 1.0);
#endif
#ifdef VERTEX_COLOR4
VertexColor = aVertexColor4;
#endif
#ifdef MATERIAL_COLOR
MaterialColor = uMaterialColor;
#endif
}
"""
}