Lumina is a wrapper around GLSL behavior, designed to simplify the creation of shader programs. It introduces a structured syntax for defining inputs, outputs, structures, uniform blocks, and shader stages.
Lumina supports both single-line and multi-line comments for documenting your code, explaining complex logic, or temporarily disabling code.
#include <screenConstants>
#include "shader/customInclude.lum"
Input -> VertexPass: Vector3 vertexPosition;
Input -> VertexPass: Vector3 vertexNormal;
Input -> VertexPass: Vector2 vertexUV;
VertexPass -> FragmentPass: Vector3 fragPosition;
VertexPass -> FragmentPass: Vector3 fragNormal;
VertexPass -> FragmentPass: Vector2 fragUV;
struct Material
{
Vector3 diffuseColor;
Vector3 specularColor;
float shininess;
};
Texture diffuseTexture;
DataBlock modelAttributes as attribute
{
Matrix4x4 modelMatrix;
Matrix4x4 normalMatrix;
};
DataBlock lightingConstants
{
Vector3 lightPosition;
Vector3 lightColor;
float ambientIntensity;
};
namespace Lighting
{
Vector3 calculateDiffuse(Vector3 normal, Vector3 lightDir, Vector3 lightColor)
{
float diff = max(dot(normal, lightDir), 0.0);
return diff * lightColor;
}
Vector3 calculateSpecular(Vector3 normal, Vector3 lightDir, Vector3 viewDir, float shininess, Vector3 lightColor)
{
Vector3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
return spec * lightColor;
}
}
VertexPass()
{
Vector4 worldPosition = modelAttributes.modelMatrix * Vector4(vertexPosition, 1.0);
fragPosition = worldPosition.xyz;
fragNormal = mat3(modelAttributes.normalMatrix) * vertexNormal;
fragUV = vertexUV;
Vector4 clipSpacePosition = worldPosition;
pixelPosition = clipSpacePosition;
}
FragmentPass()
{
float ambientIntensity = lightingConstants.ambientIntensity.
clamp(0.0, 1.0);
Vector3 normal = normalize(fragNormal);
Vector3 lightDir = normalize(lightingConstants.lightPosition - fragPosition);
Vector3 viewDir = normalize(-fragPosition);
Vector3 ambient = ambientIntensity * lightingConstants.lightColor;
Vector3 diffuse = Lighting::calculateDiffuse(normal, lightDir, lightingConstants.lightColor);
Material material;
Vector3 specular = Lighting::calculateSpecular(normal, lightDir, viewDir, material.shininess, lightingConstants.lightColor);
Vector3 finalColor = ambient + diffuse * material.diffuseColor + specular * material.specularColor;
Vector4 textureColor = getPixel(diffuseTexture, fragUV);
finalColor *= textureColor.rgb;
if (textureColor.a == 0)
{
discard;
}
pixelColor = Vector4(finalColor, textureColor.a);
}
static IVector4 clamp(const IVector4 &p_value, const IVector4 &p_boundA, const IVector4 &p_boundB)
Clamps each component of a vector between two bounds.
Definition spk_vector4.hpp:770
This cheat sheet covers the essential elements of the Lumina language to help you create and manage shaders efficiently. Happy coding!