Thank you for the encouragement yojimbo2000
this is an older thing I wrote a while ago… but I’ll put it here anyway
At the moment I made it so you can change the colours for two different block colours using parameters, but it’ll be relatively straightforward to add more colours for blocks. And it picks random colours each time you restart the project too.
Valgo’s code for generating structures is still there (I put it under a tab called SceneDataModel)
Here is a quick pic of a structure I just decided to try out:
And here is the link to the code in a pastebin, but if anyone happens to take a peek at it, you’re going to have to forgive me — things are all over the place I’m still learning I’d greatly appreciate any tips or ideas anyone may have too.
(I liked being able to separate things into different tabs but wasn’t sure in many cases whether a new class might work better or if just a file would be fine. I can find things when I need to in either case, but it probably doesn’t make much sense to anyone else at the moment which isn’t ideal )
Right now I know which part does the gradient (it’s in SceneRenderer) and I thought I made it so that it works like this:
- For each vertex in the vertices for the cube mesh:
- Get the distance between that vertex and a reference point, and mix in an amount of black according to that distance (more black if closer, less if further away)
And here was the code that I did:
function SceneRenderer:cubeColor(col, vecX, vecY, vecZ)
local ret = {}
vecRefPoint = vec3(-shapeWidth,-shapeWidth,-shapeWidth)
for vertIdx, vertVec in ipairs(cubeMeshVerts) do
--Base shading for perspective
local baseShadeColr = col:mix(color(0, 0, 0, col.a), 1 - math.floor(((vertIdx - 1) % 18) / 6) * 0.15)
--Shading for gradient
vecToPoint = vec3((cubeSize*vecX)+vertVec.x,(cubeSize*vecY)+vertVec.y,(cubeSize*vecZ)+vertVec.z)
distToRefPoint = vecRefPoint:dist(vecToPoint)
maxDistAcross = vec3(-shapeWidth,-shapeWidth,-shapeWidth):dist(vec3(shapeWidth,shapeWidth,shapeWidth))
baseShadeColr = baseShadeColr:mix(color(0), distToRefPoint/(maxDistAcross))
table.insert(ret, baseShadeColr)
end
return ret
end
However, when I change the coordinates for vecRefPoint
it doesn’t seem to change where the lighting is coming from; the darkest part still seems to be at (0,0,0)
. But maybe I just haven’t tried enough coordinates and enough structures to see yet, so I’ll take a look at a few more.
Since then, I don’t know if I changed the code but most recent pastebin here and since then, I did a random super long explanation of it here :lol: