No automerge

I'm not very keen on open source, due to personal reasons. My plan was to make a basic sort of library for people to use, but people would probably just be confused by that. I know I was confused when I was looking at the source code for 3D stuff back when I didn't know anything about it. So instead I started making tutorials. I think that's the best way for me to release my code, really. Because to be quite honest, if I release the current stuff I use, very few people will actually understand it. And while it's fun to play around with the demo (as demonstrated by my brothers, who got captivated it xD), as a programmer it's a whole lot more fun to be able to play around with the code itself. Understand each part of it, so you don't have to do extensive trial & error just to draw a few polygons.adnzzzzZ wrote:Is this going to be released as a library or anything of the sort?
Code: Select all
local lightPos = {}
local lightAtt = {}
local lightCol = {}
lightPos[1] = vec3.new(10, 15, -20):unit() * 1e10
lightAtt[1] = vec3.new(1, 0, 0)
lightCol[1] = vec3.new(1, 1, 1)
Code: Select all
shaders.mainShader.shader:sendInt("numLights", #lightPos)
shaders.mainShader.shader:send("lightPos", unpack(lightPos))
shaders.mainShader.shader:send("lightAtt", unpack(lightAtt))
shaders.mainShader.shader:send("lightCol", unpack(lightCol))
Code: Select all
// Lights
for (int i = 0; i < numLights; i++) {
vec3 pos = lightPos[i];
vec3 att = lightAtt[i];
vec3 col = lightCol[i];
vec3 dif = pos - p; // vector from the 3D pixel position to the light position
if (dot(dif, n) > 0.0) { // make sure the normal is facing the light
vec3 lightDir = normalize(dif);
float dist = length(dif);
float atten = 1.0 / (att.x + att.y*dist + att.z*dist*dist); // calculate attenuation
bool shade = true; // ugly hax to make shadows only work for light 0
// Shadows for directional light
if (i == 0) {
// project the 3D position of the pixel into the sun's view
vec3 proj = (sunInv * vec4(p, 1.0)).xyz;
float z = -proj.z;
float x = 0.5 + 0.5*proj.x/z * sunfMul;
float y = 0.5 - 0.5*proj.y/z * sunfMul;
// get the pixel stored in the shadow map (a depth buffer) at that pixel
vec4 dc = texture2D(sunMap, vec2(x, y));
float d = dc.r*255.0*255.0 + dc.g*255.0 + dc.b; // convert my depth format to a float
if (dc.a == 1.0 && z > d + 0.01) // if the pixel is occluded by another object, don't shade it
shade = false;
}
// Do shading
if (shade) {
// Diffuse
float diff = dot(n, lightDir);
if (diff > 0.0)
color += texColor.rgb * diff * col * atten; // add to main color
// Specular
vec3 R = dir - 2.0*n*dot(n, dir); // reflect 'dir' on 'n'
float spec = dot(R, lightDir);
if (spec > 0.0)
color += col * pow(spec, 50.0) * 0.5 * atten; // add to main color
}
}
}
Users browsing this forum: No registered users and 7 guests