mirror of
https://github.com/transatoshi-mw/grin-web-wallet.git
synced 2025-10-07 00:02:47 +00:00
contents of zip
This commit is contained in:
172
shaders/logo.frag
Executable file
172
shaders/logo.frag
Executable file
@@ -0,0 +1,172 @@
|
||||
// Percision
|
||||
precision highp int;
|
||||
precision highp float;
|
||||
|
||||
|
||||
// Structures
|
||||
|
||||
// Material
|
||||
struct Material {
|
||||
sampler2D diffuseMap;
|
||||
bool hasSpecularMap;
|
||||
sampler2D specularMap;
|
||||
bool hasEmissionMap;
|
||||
sampler2D emissionMap;
|
||||
bool hasNormalMap;
|
||||
sampler2D normalMap;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
// Light
|
||||
struct Light {
|
||||
int type;
|
||||
vec3 position;
|
||||
float constantAttenuationFactor;
|
||||
float linearAttenuationFactor;
|
||||
float quadraticAttenuationFactor;
|
||||
vec3 direction;
|
||||
float innerCutOffAngle;
|
||||
float outerCutOffAngle;
|
||||
vec3 ambientColor;
|
||||
vec3 diffuseColor;
|
||||
vec3 specularColor;
|
||||
};
|
||||
|
||||
|
||||
// Inputs
|
||||
varying vec2 textureCoordinateLocalSpace;
|
||||
varying vec3 directionTowardCameraTangentSpace;
|
||||
varying vec3 directionTowardLightTangentSpaces[MAX_NUMBER_OF_LIGHTS];
|
||||
varying vec3 positionWorldSpace;
|
||||
|
||||
|
||||
// Uniforms
|
||||
uniform Material material;
|
||||
uniform Light lights[MAX_NUMBER_OF_LIGHTS];
|
||||
|
||||
|
||||
// Constants
|
||||
|
||||
// Phong to Blinn shininess factor
|
||||
const int PHONG_TO_BLINN_SHININESS_FACTOR = 4;
|
||||
|
||||
// Gamma factor
|
||||
const float GAMMA_FACTOR = 2.2;
|
||||
|
||||
|
||||
// Supporting function implementation
|
||||
|
||||
// To gamma
|
||||
vec3 toGamma(vec3 value) {
|
||||
|
||||
// Return color in gamma space
|
||||
return pow(value, vec3(float(1) / GAMMA_FACTOR));
|
||||
}
|
||||
|
||||
// To gamma
|
||||
vec4 toGamma(vec4 value) {
|
||||
|
||||
// Return color in gamma space
|
||||
return vec4(toGamma(value.rgb), value.a);
|
||||
}
|
||||
|
||||
// To linear
|
||||
vec3 toLinear(vec3 value) {
|
||||
|
||||
// Return color in linear space
|
||||
return pow(value, vec3(GAMMA_FACTOR));
|
||||
}
|
||||
|
||||
// To linear
|
||||
vec4 toLinear(vec4 value) {
|
||||
|
||||
// Return color in linear space
|
||||
return vec4(toLinear(value.rgb), value.a);
|
||||
}
|
||||
|
||||
|
||||
// Main function
|
||||
void main(void) {
|
||||
|
||||
// Get diffuse texture color
|
||||
vec4 diffuseTextureColor = toLinear(texture2D(material.diffuseMap, textureCoordinateLocalSpace));
|
||||
|
||||
// Get normalized normal in tangent space
|
||||
vec3 unitNormalTangentSpace = vec3(0, 0, 1);
|
||||
if(material.hasNormalMap)
|
||||
unitNormalTangentSpace = normalize(texture2D(material.normalMap, textureCoordinateLocalSpace).rgb * float(2) - float(1));
|
||||
|
||||
// Get normalized direction toward camera in tangent space
|
||||
vec3 unitTowardCameraTangentSpace = normalize(directionTowardCameraTangentSpace);
|
||||
|
||||
// Go through all lights
|
||||
vec3 combinedColor = vec3(0);
|
||||
for(int i = 0; i < MAX_NUMBER_OF_LIGHTS; ++i) {
|
||||
|
||||
// Check if light isn't used
|
||||
if(lights[i].type == INVALID_LIGHT_TYPE)
|
||||
|
||||
// Break
|
||||
break;
|
||||
|
||||
// Check if light is a point light or spot light
|
||||
float attenuation = float(1);
|
||||
float intensity = float(1);
|
||||
if(lights[i].type == POINT_LIGHT_TYPE || lights[i].type == SPOT_LIGHT_TYPE) {
|
||||
|
||||
// Get distance to light in world space
|
||||
float distanceToLightWorldSpace = length(lights[i].position - positionWorldSpace);
|
||||
|
||||
// Set attenuation based on distance
|
||||
attenuation = float(1) / (lights[i].constantAttenuationFactor + lights[i].linearAttenuationFactor * distanceToLightWorldSpace + lights[i].quadraticAttenuationFactor * pow(distanceToLightWorldSpace, float(2)));
|
||||
|
||||
// Check if light is a spot light
|
||||
if(lights[i].type == SPOT_LIGHT_TYPE) {
|
||||
|
||||
// Get direction toward light in world space
|
||||
vec3 directionTowardLightWorldSpace = normalize(lights[i].position - positionWorldSpace);
|
||||
|
||||
// Get angle to light direction
|
||||
float angleToLightDirection = dot(directionTowardLightWorldSpace, normalize(-lights[i].direction));
|
||||
|
||||
// Set intensity based on angle
|
||||
intensity = clamp((angleToLightDirection - lights[i].outerCutOffAngle) / (lights[i].innerCutOffAngle - lights[i].outerCutOffAngle), float(0), float(1));
|
||||
}
|
||||
}
|
||||
|
||||
// Get ambient light color
|
||||
vec3 ambientLightColor = lights[i].ambientColor * diffuseTextureColor.rgb;
|
||||
combinedColor += ambientLightColor * attenuation * intensity;
|
||||
|
||||
// Get normalized direction toward light in tangent space
|
||||
vec3 unitTowardLightTangentSpace = normalize(directionTowardLightTangentSpaces[i]);
|
||||
|
||||
// Get diffuse light color
|
||||
float diffuseBrightness = max(dot(unitNormalTangentSpace, unitTowardLightTangentSpace), float(0));
|
||||
vec3 diffuseLightColor = lights[i].diffuseColor * diffuseBrightness * diffuseTextureColor.rgb;
|
||||
combinedColor += diffuseLightColor * attenuation * intensity;
|
||||
|
||||
// Check if material has a specular map
|
||||
if(material.hasSpecularMap) {
|
||||
|
||||
// Get normalized direction halfway between the direction toward light and direction toward camera in tangent space
|
||||
vec3 unitHalfwayTangentSpace = normalize(unitTowardLightTangentSpace + unitTowardCameraTangentSpace);
|
||||
|
||||
// Get specular light color
|
||||
float specularLightFactor = pow(max(dot(unitNormalTangentSpace, unitHalfwayTangentSpace), float(0)), material.shininess * float(PHONG_TO_BLINN_SHININESS_FACTOR));
|
||||
vec3 specularLightColor = lights[i].specularColor * specularLightFactor * texture2D(material.specularMap, textureCoordinateLocalSpace).rgb;
|
||||
combinedColor += specularLightColor * attenuation * intensity;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if material has an emission map
|
||||
if(material.hasEmissionMap) {
|
||||
|
||||
// Get emission light color
|
||||
vec3 emissionLightColor = toLinear(texture2D(material.emissionMap, textureCoordinateLocalSpace).rgb);
|
||||
combinedColor += emissionLightColor;
|
||||
}
|
||||
|
||||
// Set color
|
||||
gl_FragColor = toGamma(vec4(combinedColor, diffuseTextureColor.a));
|
||||
}
|
160
shaders/logo.vert
Executable file
160
shaders/logo.vert
Executable file
@@ -0,0 +1,160 @@
|
||||
// Percision
|
||||
precision highp int;
|
||||
precision highp float;
|
||||
|
||||
|
||||
// Structures
|
||||
|
||||
// Light
|
||||
struct Light {
|
||||
int type;
|
||||
vec3 position;
|
||||
float constantAttenuationFactor;
|
||||
float linearAttenuationFactor;
|
||||
float quadraticAttenuationFactor;
|
||||
vec3 direction;
|
||||
float innerCutOffAngle;
|
||||
float outerCutOffAngle;
|
||||
vec3 ambientColor;
|
||||
vec3 diffuseColor;
|
||||
vec3 specularColor;
|
||||
};
|
||||
|
||||
|
||||
// Inputs
|
||||
attribute vec3 position;
|
||||
attribute vec2 textureCoordinate;
|
||||
attribute vec3 normal;
|
||||
attribute vec3 tangent;
|
||||
attribute vec3 bitangent;
|
||||
|
||||
|
||||
// Outputs
|
||||
varying vec2 textureCoordinateLocalSpace;
|
||||
varying vec3 directionTowardCameraTangentSpace;
|
||||
varying vec3 directionTowardLightTangentSpaces[MAX_NUMBER_OF_LIGHTS];
|
||||
varying vec3 positionWorldSpace;
|
||||
|
||||
|
||||
// Uniforms
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform Light lights[MAX_NUMBER_OF_LIGHTS];
|
||||
|
||||
|
||||
// Supporting function implementation
|
||||
|
||||
// Transpose
|
||||
mat3 transpose(mat3 matrix) {
|
||||
|
||||
// Return matrix's transpose
|
||||
return mat3(
|
||||
matrix[0][0], matrix[1][0], matrix[2][0],
|
||||
matrix[0][1], matrix[1][1], matrix[2][1],
|
||||
matrix[0][2], matrix[1][2], matrix[2][2]
|
||||
);
|
||||
}
|
||||
|
||||
// Transpose
|
||||
mat4 transpose(mat4 matrix) {
|
||||
|
||||
// Return matrix's transpose
|
||||
return mat4(
|
||||
matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],
|
||||
matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1],
|
||||
matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],
|
||||
matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]
|
||||
);
|
||||
}
|
||||
|
||||
// Inverse
|
||||
mat4 inverse(mat4 matrix) {
|
||||
|
||||
// Return matrix's inverse
|
||||
float crossProductOne = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
|
||||
float crossProductTwo = matrix[0][0] * matrix[1][2] - matrix[0][2] * matrix[1][0];
|
||||
float crossProductThree = matrix[0][0] * matrix[1][3] - matrix[0][3] * matrix[1][0];
|
||||
float crossProductFour = matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1];
|
||||
float crossProductFive = matrix[0][1] * matrix[1][3] - matrix[0][3] * matrix[1][1];
|
||||
float crossProductSix = matrix[0][2] * matrix[1][3] - matrix[0][3] * matrix[1][2];
|
||||
float crossProductSeven = matrix[2][0] * matrix[3][1] - matrix[2][1] * matrix[3][0];
|
||||
float crossProductEight = matrix[2][0] * matrix[3][2] - matrix[2][2] * matrix[3][0];
|
||||
float crossProductNine = matrix[2][0] * matrix[3][3] - matrix[2][3] * matrix[3][0];
|
||||
float crossProductTen = matrix[2][1] * matrix[3][2] - matrix[2][2] * matrix[3][1];
|
||||
float crossProductEleven = matrix[2][1] * matrix[3][3] - matrix[2][3] * matrix[3][1];
|
||||
float crossProductTwelve = matrix[2][2] * matrix[3][3] - matrix[2][3] * matrix[3][2];
|
||||
float determinant = crossProductOne * crossProductTwelve - crossProductTwo * crossProductEleven + crossProductThree * crossProductTen + crossProductFour * crossProductNine - crossProductFive * crossProductEight + crossProductSix * crossProductSeven;
|
||||
|
||||
return mat4(
|
||||
matrix[1][1] * crossProductTwelve - matrix[1][2] * crossProductEleven + matrix[1][3] * crossProductTen, matrix[0][2] * crossProductEleven - matrix[0][1] * crossProductTwelve - matrix[0][3] * crossProductTen, matrix[3][1] * crossProductSix - matrix[3][2] * crossProductFive + matrix[3][3] * crossProductFour, matrix[2][2] * crossProductFive - matrix[2][1] * crossProductSix - matrix[2][3] * crossProductFour,
|
||||
matrix[1][2] * crossProductNine - matrix[1][0] * crossProductTwelve - matrix[1][3] * crossProductEight, matrix[0][0] * crossProductTwelve - matrix[0][2] * crossProductNine + matrix[0][3] * crossProductEight, matrix[3][2] * crossProductThree - matrix[3][0] * crossProductSix - matrix[3][3] * crossProductTwo, matrix[2][0] * crossProductSix - matrix[2][2] * crossProductThree + matrix[2][3] * crossProductTwo,
|
||||
matrix[1][0] * crossProductEleven - matrix[1][1] * crossProductNine + matrix[1][3] * crossProductSeven, matrix[0][1] * crossProductNine - matrix[0][0] * crossProductEleven - matrix[0][3] * crossProductSeven, matrix[3][0] * crossProductFive - matrix[3][1] * crossProductThree + matrix[3][3] * crossProductOne, matrix[2][1] * crossProductThree - matrix[2][0] * crossProductFive - matrix[2][3] * crossProductOne,
|
||||
matrix[1][1] * crossProductEight - matrix[1][0] * crossProductTen - matrix[1][2] * crossProductSeven, matrix[0][0] * crossProductTen - matrix[0][1] * crossProductEight + matrix[0][2] * crossProductSeven, matrix[3][1] * crossProductTwo - matrix[3][0] * crossProductFour - matrix[3][2] * crossProductOne, matrix[2][0] * crossProductFour - matrix[2][1] * crossProductTwo + matrix[2][2] * crossProductOne
|
||||
) / determinant;
|
||||
}
|
||||
|
||||
|
||||
// Main function
|
||||
void main(void) {
|
||||
|
||||
// Get position in world space
|
||||
positionWorldSpace = vec3(modelMatrix * vec4(position, 1));
|
||||
|
||||
// Get view model matrix
|
||||
mat4 viewModelMatrix = viewMatrix * modelMatrix;
|
||||
|
||||
// Set position in clip space
|
||||
gl_Position = projectionMatrix * viewModelMatrix * vec4(position, 1);
|
||||
|
||||
// Set texture coordinate in local space
|
||||
textureCoordinateLocalSpace = textureCoordinate;
|
||||
|
||||
// Get normal in view space
|
||||
mat3 normalMatrix = mat3(transpose(inverse(viewModelMatrix)));
|
||||
vec3 normalViewSpace = normalize(normalMatrix * normal);
|
||||
|
||||
// Get tangent in view space
|
||||
vec3 tangentViewSpace = normalize(normalMatrix * tangent);
|
||||
|
||||
// Get bitangent in view space
|
||||
vec3 bitangentViewSpace = normalize(normalMatrix * bitangent);
|
||||
|
||||
// Get view to tangent matrix
|
||||
mat3 inverseTangentMatrix = transpose(mat3(tangentViewSpace, bitangentViewSpace, normalViewSpace));
|
||||
|
||||
// Get direction toward camera in tangent space
|
||||
vec3 positionViewSpace = vec3(viewModelMatrix * vec4(position, 1));
|
||||
vec3 directionTowardCameraViewSpace = normalize(-positionViewSpace);
|
||||
directionTowardCameraTangentSpace = normalize(inverseTangentMatrix * directionTowardCameraViewSpace);
|
||||
|
||||
// Go through all lights
|
||||
for(int i = 0; i < MAX_NUMBER_OF_LIGHTS; ++i) {
|
||||
|
||||
// Check if light isn't used
|
||||
if(lights[i].type == INVALID_LIGHT_TYPE)
|
||||
|
||||
// Break
|
||||
break;
|
||||
|
||||
// Check if light is a point light or spot light
|
||||
vec3 directionTowardLightViewSpace = vec3(0);
|
||||
if(lights[i].type == POINT_LIGHT_TYPE || lights[i].type == SPOT_LIGHT_TYPE) {
|
||||
|
||||
// Get direction toward light in view space
|
||||
vec3 lightPositionViewSpace = vec3(viewMatrix * vec4(lights[i].position, 1));
|
||||
directionTowardLightViewSpace = normalize(lightPositionViewSpace - positionViewSpace);
|
||||
}
|
||||
|
||||
// Otherwise check if light is a directional light
|
||||
else if(lights[i].type == DIRECTIONAL_LIGHT_TYPE) {
|
||||
|
||||
// Get direction toward light in view space
|
||||
vec3 lightDirectionViewSpace = normalize(vec3(viewMatrix * vec4(normalize(lights[i].direction), 0)));
|
||||
directionTowardLightViewSpace = -lightDirectionViewSpace;
|
||||
}
|
||||
|
||||
// Get direction toward light in tangent space
|
||||
directionTowardLightTangentSpaces[i] = normalize(inverseTangentMatrix * directionTowardLightViewSpace);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user