mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-23 14:19:37 +08:00
big tryout
This commit is contained in:
parent
57cec4ec59
commit
3d9bccb7c7
@ -130,6 +130,8 @@ class ProcessSlicedLayersJob(Job):
|
|||||||
|
|
||||||
normals = this_poly.getNormals()
|
normals = this_poly.getNormals()
|
||||||
all_normals.append(normals)
|
all_normals.append(normals)
|
||||||
|
# insert last element twice - fake converting line normals to vertex normals
|
||||||
|
#all_normals.append(normals[-1:])
|
||||||
|
|
||||||
this_layer.polygons.append(this_poly)
|
this_layer.polygons.append(this_poly)
|
||||||
|
|
||||||
@ -149,8 +151,24 @@ class ProcessSlicedLayersJob(Job):
|
|||||||
|
|
||||||
# layer_data.calculateNormals()
|
# layer_data.calculateNormals()
|
||||||
# We are done processing all the layers we got from the engine, now create a mesh out of the data
|
# We are done processing all the layers we got from the engine, now create a mesh out of the data
|
||||||
layer_data._normals = numpy.concatenate(all_normals)
|
# layer_data._normals = numpy.concatenate(all_normals)
|
||||||
layer_mesh = layer_data.build()
|
layer_mesh = layer_data.build()
|
||||||
|
# normals = []
|
||||||
|
# # quick and dirty normals calculation for 2d lines
|
||||||
|
# for line_idx in range(len(layer_mesh._indices) // 2 - 1):
|
||||||
|
# idx0 = layer_mesh._indices[line_idx]
|
||||||
|
# idx1 = layer_mesh._indices[line_idx + 1]
|
||||||
|
# x0 = layer_mesh._vertices[idx0][0]
|
||||||
|
# y0 = layer_mesh._vertices[idx0][2]
|
||||||
|
# x1 = layer_mesh._vertices[idx1][0]
|
||||||
|
# y1 = layer_mesh._vertices[idx1][2]
|
||||||
|
# dx = x1 - x0;
|
||||||
|
# dy = y1 - y0;
|
||||||
|
# normals.append([dy, 0, -dx])
|
||||||
|
# normals.append([dy, 0, -dx])
|
||||||
|
# layer_mesh._normals = numpy.array(normals)
|
||||||
|
#from UM.Mesh.MeshData import calculateNormalsFromIndexedVertices
|
||||||
|
#layer_mesh._normals = calculateNormalsFromIndexedVertices(layer_mesh._vertices, layer_mesh._indices, layer_mesh._face_count)
|
||||||
|
|
||||||
if self._abort_requested:
|
if self._abort_requested:
|
||||||
if self._progress:
|
if self._progress:
|
||||||
|
@ -16,6 +16,8 @@ vertex =
|
|||||||
varying highp vec3 v_vertex;
|
varying highp vec3 v_vertex;
|
||||||
varying highp vec3 v_normal;
|
varying highp vec3 v_normal;
|
||||||
|
|
||||||
|
varying highp vec3 v_orig_vertex;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 world_space_vert = u_modelMatrix * a_vertex;
|
vec4 world_space_vert = u_modelMatrix * a_vertex;
|
||||||
@ -27,6 +29,8 @@ vertex =
|
|||||||
|
|
||||||
v_vertex = world_space_vert.xyz;
|
v_vertex = world_space_vert.xyz;
|
||||||
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
|
v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
|
||||||
|
|
||||||
|
v_orig_vertex = a_vertex.xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry =
|
geometry =
|
||||||
@ -38,6 +42,7 @@ geometry =
|
|||||||
in vec4 v_color[];
|
in vec4 v_color[];
|
||||||
in vec3 v_vertex[];
|
in vec3 v_vertex[];
|
||||||
in vec3 v_normal[];
|
in vec3 v_normal[];
|
||||||
|
in vec3 v_orig_vertex[];
|
||||||
|
|
||||||
out vec4 f_color;
|
out vec4 f_color;
|
||||||
out vec3 f_normal;
|
out vec3 f_normal;
|
||||||
@ -50,6 +55,12 @@ geometry =
|
|||||||
vec3 g_normal;
|
vec3 g_normal;
|
||||||
vec3 g_offset;
|
vec3 g_offset;
|
||||||
|
|
||||||
|
vec3 g_vertex_delta;
|
||||||
|
vec3 g_vertex_normal;
|
||||||
|
|
||||||
|
float size = 3;
|
||||||
|
|
||||||
|
/*
|
||||||
delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0);
|
delta = vec4(gl_in[1].gl_Position.xy, 0.0, 0.0) - vec4(gl_in[0].gl_Position.xy, 0.0, 0.0);
|
||||||
|
|
||||||
if (length(delta) > 0.1) {
|
if (length(delta) > 0.1) {
|
||||||
@ -59,49 +70,71 @@ geometry =
|
|||||||
g_normal = vec3(delta.y, -delta.x, delta.z);
|
g_normal = vec3(delta.y, -delta.x, delta.z);
|
||||||
g_offset = vec3(0.0, 0.0, 0.0);
|
g_offset = vec3(0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
//g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0);
|
g_offset = vec3(3.5, 3.5, 0.0); //5.0 * g_normal; // vec3(3.5, 3.5, 0.0);
|
||||||
|
*/
|
||||||
//g_normal = normalize(vec3(delta.y, -delta.x, delta.z));
|
//g_normal = normalize(vec3(delta.y, -delta.x, delta.z));
|
||||||
|
|
||||||
f_vertex = v_vertex[0];
|
g_vertex_delta = v_orig_vertex[1] - v_orig_vertex[0];
|
||||||
f_normal = v_normal[0];
|
g_vertex_normal = vec3(g_vertex_delta.z, 0.0, -g_vertex_delta.x);
|
||||||
f_color = v_color[0];
|
if (length(g_vertex_normal) < 0.1) {
|
||||||
gl_Position = gl_in[0].gl_Position + g_offset;
|
g_vertex_normal = vec3(1.0, 0.0, 0.0);
|
||||||
EmitVertex();
|
} else {
|
||||||
|
g_vertex_normal = normalize(g_vertex_normal);
|
||||||
|
}
|
||||||
|
|
||||||
f_vertex = v_vertex[0];
|
f_vertex = v_vertex[0];
|
||||||
f_normal = -v_normal[0];
|
|
||||||
f_color = v_color[0];
|
f_color = v_color[0];
|
||||||
gl_Position = gl_in[0].gl_Position - g_offset;
|
|
||||||
|
f_normal = g_vertex_normal;
|
||||||
|
gl_Position = gl_in[0].gl_Position + vec4(0.0, size, 0.0, 0.0);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
f_vertex = v_vertex[1];
|
f_normal = g_vertex_normal;
|
||||||
f_normal = v_normal[1];
|
gl_Position = gl_in[1].gl_Position + vec4(0.0, size, 0.0, 0.0);
|
||||||
f_color = v_color[1];
|
EmitVertex();
|
||||||
gl_Position = gl_in[1].gl_Position + g_offset;
|
|
||||||
|
f_normal = vec3(0.0);
|
||||||
|
gl_Position = gl_in[0].gl_Position + vec4(-size, 0.0, 0.0, 0.0);
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
//f_vertex = v_vertex[1];
|
||||||
|
//f_color = v_color[1];
|
||||||
|
|
||||||
|
|
||||||
|
f_normal = vec3(0.0);
|
||||||
|
gl_Position = gl_in[1].gl_Position + vec4(size, 0.0, 0.0, 0.0);
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
f_normal = -g_vertex_normal;
|
||||||
|
gl_Position = gl_in[0].gl_Position + vec4(0, -size, 0.0, 0.0);
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
f_normal = -g_vertex_normal;
|
||||||
|
gl_Position = gl_in[1].gl_Position + vec4(0.0, -size, 0.0, 0.0);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
|
||||||
|
/*
|
||||||
f_vertex = v_vertex[0];
|
f_vertex = v_vertex[0];
|
||||||
f_normal = -v_normal[0];
|
f_normal = -g_vertex_normal;
|
||||||
f_color = v_color[0];
|
f_color = v_color[0];
|
||||||
gl_Position = gl_in[0].gl_Position - g_offset;
|
gl_Position = gl_in[0].gl_Position - g_offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
f_vertex = v_vertex[1];
|
f_vertex = v_vertex[1];
|
||||||
f_normal = v_normal[0];
|
f_normal = g_vertex_normal;
|
||||||
f_color = v_color[1];
|
f_color = v_color[1];
|
||||||
gl_Position = gl_in[1].gl_Position + g_offset;
|
gl_Position = gl_in[1].gl_Position + g_offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
f_vertex = v_vertex[1];
|
f_vertex = v_vertex[1];
|
||||||
f_normal = -v_normal[0];
|
f_normal = -g_vertex_normal;
|
||||||
f_color = v_color[1];
|
f_color = v_color[1];
|
||||||
gl_Position = gl_in[1].gl_Position - g_offset;
|
gl_Position = gl_in[1].gl_Position - g_offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
*/
|
||||||
|
|
||||||
EndPrimitive();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,21 +143,38 @@ fragment =
|
|||||||
varying lowp vec3 f_normal;
|
varying lowp vec3 f_normal;
|
||||||
varying lowp vec3 f_vertex;
|
varying lowp vec3 f_vertex;
|
||||||
|
|
||||||
|
uniform mediump vec4 u_ambientColor;
|
||||||
uniform mediump vec4 u_diffuseColor;
|
uniform mediump vec4 u_diffuseColor;
|
||||||
uniform highp vec3 u_lightPosition;
|
uniform highp vec3 u_lightPosition;
|
||||||
|
|
||||||
|
void Impostor(in float sphereRadius, in vec3 cameraSpherePos, in vec2 mapping, out vec3 cameraPos, out vec3 cameraNormal)
|
||||||
|
{
|
||||||
|
float lensqr = dot(mapping, mapping);
|
||||||
|
if(lensqr > 1.0)
|
||||||
|
discard;
|
||||||
|
|
||||||
|
cameraNormal = vec3(mapping, sqrt(1.0 - lensqr));
|
||||||
|
cameraPos = (cameraNormal * sphereRadius) + cameraSpherePos;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
vec3 cameraPos;
|
||||||
|
vec3 cameraNormal;
|
||||||
|
|
||||||
|
Impostor(0.2, vec3(0.0, 0.0, 0.0), vec2(0.1, 0.0), cameraPos, cameraNormal);
|
||||||
|
|
||||||
mediump vec4 finalColor = vec4(0.0);
|
mediump vec4 finalColor = vec4(0.0);
|
||||||
|
|
||||||
finalColor += f_color;
|
finalColor += u_ambientColor;
|
||||||
|
|
||||||
highp vec3 normal = normalize(f_normal);
|
//highp vec3 normal = normalize(f_normal);
|
||||||
|
highp vec3 normal = normalize(cameraNormal);
|
||||||
highp vec3 lightDir = normalize(u_lightPosition - f_vertex);
|
highp vec3 lightDir = normalize(u_lightPosition - f_vertex);
|
||||||
|
|
||||||
// Diffuse Component
|
// Diffuse Component
|
||||||
highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0);
|
highp float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0);
|
||||||
finalColor += (NdotL * u_diffuseColor);
|
finalColor += (NdotL * f_color);
|
||||||
|
|
||||||
finalColor.a = 1.0;
|
finalColor.a = 1.0;
|
||||||
gl_FragColor = finalColor;
|
gl_FragColor = finalColor;
|
||||||
@ -136,6 +186,7 @@ fragment =
|
|||||||
[defaults]
|
[defaults]
|
||||||
u_active_extruder = 0.0
|
u_active_extruder = 0.0
|
||||||
u_shade_factor = 0.60
|
u_shade_factor = 0.60
|
||||||
|
u_ambientColor = [0.3, 0.3, 0.3, 0.3]
|
||||||
u_diffuseColor = [1.0, 0.79, 0.14, 1.0]
|
u_diffuseColor = [1.0, 0.79, 0.14, 1.0]
|
||||||
|
|
||||||
[bindings]
|
[bindings]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user