Shader fixes

This commit is contained in:
luboslenco 2018-02-27 20:27:27 +01:00
parent 49b1c830ea
commit f2465ab041
5 changed files with 73 additions and 11 deletions

View file

@ -71,10 +71,10 @@ vec4 traceDiffuse(const vec3 origin, const vec3 normal, sampler3D voxels) {
const float TAN_22_5 = 0.55785173935;
const float angleMix = 0.5f;
const float aperture = TAN_22_5;
const vec3 o1 = normalize(tangent(normal));
const vec3 o2 = normalize(cross(o1, normal));
const vec3 c1 = 0.5f * (o1 + o2);
const vec3 c2 = 0.5f * (o1 - o2);
vec3 o1 = normalize(tangent(normal));
vec3 o2 = normalize(cross(o1, normal));
vec3 c1 = 0.5f * (o1 + o2);
vec3 c2 = 0.5f * (o1 - o2);
const float offset = 1.5 * VOXEL_SIZE * voxelgiOffsetDiff;
#ifdef _VoxelCones1
@ -161,10 +161,10 @@ float traceAO(const vec3 origin, const vec3 normal, sampler3D voxels) {
const float TAN_22_5 = 0.55785173935;
const float angleMix = 0.5f;
const float aperture = TAN_22_5;
const vec3 o1 = normalize(tangent(normal));
const vec3 o2 = normalize(cross(o1, normal));
const vec3 c1 = 0.5f * (o1 + o2);
const vec3 c2 = 0.5f * (o1 - o2);
vec3 o1 = normalize(tangent(normal));
vec3 o2 = normalize(cross(o1, normal));
vec3 c1 = 0.5f * (o1 + o2);
vec3 c2 = 0.5f * (o1 - o2);
const float offset = 1.5 * VOXEL_SIZE * voxelgiOffsetDiff;
#ifdef _VoxelCones1

View file

@ -12,11 +12,11 @@ class Config {
}
public static function save() {
var data = haxe.io.Bytes.ofString(haxe.Json.stringify(raw)).getData();
var bytes = haxe.io.Bytes.ofString(haxe.Json.stringify(raw));
#if kha_krom
Krom.fileSaveBytes("./config.arm", data);
Krom.fileSaveBytes("./config.arm", bytes.getData());
#elseif kha_kore
File.saveBytes("./config.arm", data);
sys.io.File.saveBytes("./config.arm", bytes);
#end
}

View file

@ -155,4 +155,59 @@ class CyclesFunctions {
return 1.0 - r * r;
}
";
public static var str_traceAO = "
float traceConeAO(sampler3D voxels, const vec3 origin, vec3 dir, const float aperture, const float maxDist, const float offset) {
const ivec3 voxelgiResolution = ivec3(256, 256, 256);
const float voxelgiStep = 1.0;
const float VOXEL_SIZE = (2.0 / voxelgiResolution.x) * voxelgiStep;
dir = normalize(dir);
float sampleCol = 0.0;
float dist = offset;
float diam = dist * aperture;
vec3 samplePos;
while (sampleCol < 1.0 && dist < maxDist) {
samplePos = dir * dist + origin;
float mip = max(log2(diam * voxelgiResolution.x), 0);
float mipSample = textureLod(voxels, samplePos * 0.5 + vec3(0.5), mip).r;
sampleCol += (1 - sampleCol) * mipSample;
dist += max(diam / 2, VOXEL_SIZE);
diam = dist * aperture;
}
return sampleCol;
}
vec3 tangent(const vec3 n) {
vec3 t1 = cross(n, vec3(0, 0, 1));
vec3 t2 = cross(n, vec3(0, 1, 0));
if (length(t1) > length(t2)) return normalize(t1);
else return normalize(t2);
}
float traceAO(const vec3 origin, const vec3 normal, sampler3D voxels) {
const float TAN_22_5 = 0.55785173935;
const float angleMix = 0.5f;
const float aperture = TAN_22_5;
vec3 o1 = normalize(tangent(normal));
vec3 o2 = normalize(cross(o1, normal));
vec3 c1 = 0.5f * (o1 + o2);
vec3 c2 = 0.5f * (o1 - o2);
const float voxelgiOffset = 2.5;
const float voxelgiRange = 1.0;
const float MAX_DISTANCE = 1.73205080757 * voxelgiRange;
const ivec3 voxelgiResolution = ivec3(256, 256, 256);
const float voxelgiStep = 1.0;
const float VOXEL_SIZE = (2.0 / voxelgiResolution.x) * voxelgiStep;
const float offset = 1.5 * VOXEL_SIZE * voxelgiOffset;
float col = traceConeAO(voxels, origin, normal, aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, o1, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, o2, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, -c1, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, -c2, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, -o1, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, -o2, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, c1, angleMix), aperture, MAX_DISTANCE, offset);
col += traceConeAO(voxels, origin, mix(normal, c2, angleMix), aperture, MAX_DISTANCE, offset);
const float blendFac = 1.0;
return col / (9.0 * blendFac);
}
";
}

View file

@ -244,12 +244,15 @@ class Logic {
v = createClassInstance('StringNode', [tree, inp.default_value]);
}
else if (inp.type == 'VECTOR') {
if (inp.default_value == null) inp.default_value = [0, 0, 0]; // TODO
v = createClassInstance('VectorNode', [tree, inp.default_value[0], inp.default_value[1], inp.default_value[2]]);
}
else if (inp.type == 'RGBA') {
if (inp.default_value == null) inp.default_value = [0, 0, 0]; // TODO
v = createClassInstance('ColorNode', [tree, inp.default_value[0], inp.default_value[1], inp.default_value[2], inp.default_value[3]]);
}
else if (inp.type == 'RGB') {
if (inp.default_value == null) inp.default_value = [0, 0, 0]; // TODO
v = createClassInstance('ColorNode', [tree, inp.default_value[0], inp.default_value[1], inp.default_value[2]]);
}
else if (inp.type == 'VALUE') {

View file

@ -251,6 +251,7 @@ def write_config(resx, resy):
output['window_maximizable'] = wrd.arm_winmaximize
output['window_w'] = str(resx)
output['window_h'] = str(resy)
output['window_scale'] = 1.0
rpdat = arm.utils.get_rp()
output['window_msaa'] = rpdat.arm_samples_per_pixel
output['window_vsync'] = wrd.arm_vsync
@ -427,6 +428,7 @@ def write_indexhtml(w, h, is_publish):
</html>
""")
add_compiledglsl = ''
def write_compiledglsl(defs):
wrd = bpy.data.worlds['Arm']
rpdat = arm.utils.get_rp()
@ -583,6 +585,8 @@ const float voxelgiOffsetRefract = """ + str(round(wrd.arm_voxelgi_offset_refrac
"""const int skinMaxBones = """ + str(wrd.arm_skin_max_bones) + """;
""")
f.write(add_compiledglsl + '\n') # External defined constants
f.write("""#endif // _COMPILED_GLSL_
""")