Unfinished stuff.

This commit is contained in:
IntegratedQuantum 2022-12-09 20:28:15 +01:00
parent 48cfbc5c20
commit a1dcfd6ebf
5 changed files with 79 additions and 9 deletions

View File

@ -0,0 +1,28 @@
{
"colors": [
{"diffuse" : 0x535353},
{"diffuse" : 0x3d3d3d},
{"diffuse" : 0x333333},
{"diffuse" : 0x2b2b2b},
{"diffuse" : 0x252525}
],
"simplex1Wavelength": [2.0, 2.0, 2.0],
"simplex1Weight": 0.0,
"simplex2Wavelength": [8.0, 8.0, 8.0],
"simplex2DomainWarp": [0.1, 0.1, 0.1],
"//simplex2Weight": 3.5,
"simplex3Wavelength": [1.0, 1.0, 1.0],
"simplex3Weight": 0.0,
"worleyWavelength": [4.0, 4.0, 4.0],
"worleyWeight": 4,
"brightnessOffset": -3.0,
"randomness": 0,
}

View File

@ -10,11 +10,11 @@
"simplex1Wavelength": [20000.0, 4000.0, 20000.0],
"simplex1Wavelength": [1024.0, 1024.0, 1024.0],
"simplex1Weight": 0.0,
"simplex2Wavelength": [0.0, 0.0, 0.0],
"simplex2DomainWarp": [250, 250, 250],
"simplex2Wavelength": [32.0, 2.5, 32.0],
"simplex2DomainWarp": [0.0, 32.0, 0.0],
"simplex2Weight": 2.5,
"simplex3Wavelength": [3.0, 8.0, 6.0],

View File

@ -6,5 +6,7 @@
],
"emittedLight" : 0x111111,
"model" : "cube",
"texture" : "cubyz:glow_crystal/black"
"palette" : [
"cubyz:glow_crystal/black"
]
}

View File

@ -28,6 +28,9 @@ struct ProceduralMaterial {
float randomness;
vec3 worleyWavelength;
float worleyWeight;
MaterialColor colors[8];
};
@ -58,6 +61,31 @@ ivec3 random3to3(ivec3 v) {
return v;
}
float length2(vec3 i) {
return abs(i.x) + abs(i.y) + abs(i.z);
}
float worley(vec3 v) {
ivec3 start = ivec3(floor(v - 0.5));
float totalMax = 1.0;
for(int x = 0; x <= 1; x++) {
for(int y = 0; y <= 1; y++) {
for(int z = 0; z <= 1; z++) {
ivec3 integerPos = ivec3(x, y, z) + start;
ivec3 seed = random3to3(integerPos);
vec3 pos = vec3(integerPos) + vec3(uvec3(seed)/(65536.0*65536.0));
float dist1 = length2(pos - v);
seed = random3to3(integerPos);
pos = vec3(integerPos) + vec3(uvec3(seed)/(65536.0*65536.0));
float dist2 = length2(pos - v);
totalMax = min(totalMax, min(dist1, dist2));
}
}
}
return totalMax;
}
float simplex(vec3 v){
const vec2 C = vec2(1.0/6.0, 1.0/3.0);
@ -138,7 +166,7 @@ vec3 tripleSimplex(vec3 v){
result.x = (42.0/(1 << 31))*dot(m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));
}
i += 5642.0;
i += 5642.3333333;
{
// Get gradients:
@ -158,7 +186,7 @@ vec3 tripleSimplex(vec3 v){
result.y = (42.0/(1 << 31))*dot(m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3)));
}
i -= 11202.0;
i -= 11202.6666666;
{
// Get gradients:
@ -200,7 +228,9 @@ void main() {
float simplex2 = simplex(voxelPos*material.simplex2Wavelength + simplex1*material.simplex2DomainWarp);
float simplex3 = simplex(voxelPos*material.simplex3Wavelength + simplex1*material.simplex3DomainWarp);
float brightness = simplex1.x*material.simplex1Weight + simplex2*material.simplex2Weight + simplex3*material.simplex3Weight + randomValues.x*material.randomness + material.brightnessOffset + 3;
float brightness = simplex1.x*material.simplex1Weight + simplex2*material.simplex2Weight + simplex3*material.simplex3Weight;
brightness += randomValues.x*material.randomness + material.brightnessOffset + 3;
brightness += worley(voxelPos*material.worleyWavelength)*material.worleyWeight;
int colorIndex = min(7, max(0, int(brightness)));
fragmentColor.rgb = unpackColor(material.colors[colorIndex].diffuse)*(ambientLight*normalVariation)/4;
fragmentColor.a = 1;

View File

@ -216,9 +216,12 @@ pub const meshes = struct {
randomness: f32,
colors: [8]MaterialColor,
__padding4: [2]f32,
__paddingTotal: [2]f32,
worleyWavelength: ExternVec3f,
worleyWeight: f32,
colors: [8]MaterialColor,
};
const Palette = extern struct {
@ -353,6 +356,13 @@ pub const meshes = struct {
materials[numericalID].randomness = json.get(f32, "randomness", 0.0);
materials[numericalID].worleyWavelength = .{
saveInverse(json.getChild("worleyWavelength").getAtIndex(f32, 0, 0.0)),
saveInverse(json.getChild("worleyWavelength").getAtIndex(f32, 1, 0.0)),
saveInverse(json.getChild("worleyWavelength").getAtIndex(f32, 2, 0.0))
};
materials[numericalID].worleyWeight = json.get(f32, "worleyWeight", 0.0);
const colors = json.getChild("colors");
for(materials[numericalID].colors) |*color, i| {
const colorJson = colors.getChildAtIndex(i);