This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/intern/opensubdiv/shader/gpu_shader_opensubdiv_geometry.glsl
Sergey Sharybin d920382046 OpenSubdiv: Re-work C-API integration
Main goal is to make API simpler to follow (at least ion terms what
is defined/declared where, as opposite of handful big headers which
includes all the declarations), and also avoid a big set of long and
obscure functions.

Now C-API files are split into smaller ones, following OpenSubdiv
behavior more closely, and also function pointers in structures
used a lot more, which shortens functions names,

UV integration part in GL Mesh is mainly stripped away, it needs
to be done differently. On a related topic, UV coordinates API in
converter needs to be removed as well, we do not need coordinates,
only island connectivity information there.

Additional changes:

- Varying interpolation in evaluator API are temporarily disabled,
  need to extend API somewhere (probably, evaluator's API) to inform
  layout information of vertex data (whether it contains varying
  data, width, stride and such).

- Evaluator now can interpolate face-varying data.
  Only works for adaptive refiner, since some issues in OpenSubdiv
  itself.

Planned changes:

- Remove uv coordinates from TopologyConverter.
- Support evaluation of patches (as opposite to individual coordinates
  as it happens currently).
- Support more flexible layout of varying and face-varying data.
  It is stupid to assume varying is 3 floats and face-varying 2 floats.
- Support of second order derivatives.
- Everything else what i'm missing in this list.
2018-07-16 09:52:37 +02:00

155 lines
3.6 KiB
GLSL

/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2014 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/
struct VertexData {
vec4 position;
vec3 normal;
vec2 uv;
};
layout(lines_adjacency) in;
#ifdef WIREFRAME
layout(line_strip, max_vertices = 8) out;
#else
layout(triangle_strip, max_vertices = 4) out;
#endif
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform int PrimitiveIdBase;
uniform int osd_fvar_count;
uniform int osd_active_uv_offset;
in block {
VertexData v;
} inpt[];
#define INTERP_FACE_VARYING_2(result, fvarOffset, tessCoord) \
{ \
vec2 v[4]; \
int primOffset = (gl_PrimitiveID + PrimitiveIdBase) * 4; \
for (int i = 0; i < 4; ++i) { \
int index = (primOffset + i) * osd_fvar_count + fvarOffset; \
v[i] = vec2(texelFetch(FVarDataBuffer, index).s, \
texelFetch(FVarDataBuffer, index + 1).s); \
} \
result = mix(mix(v[0], v[1], tessCoord.s), \
mix(v[3], v[2], tessCoord.s), \
tessCoord.t); \
}
uniform samplerBuffer FVarDataBuffer;
uniform isamplerBuffer FVarDataOffsetBuffer;
out block {
VertexData v;
} outpt;
#ifdef FLAT_SHADING
void emit(int index, vec3 normal)
{
outpt.v.position = inpt[index].v.position;
outpt.v.normal = normal;
/* TODO(sergey): Only uniform subdivisions atm. */
vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
vec2 st = quadst[index];
INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
gl_Position = projectionMatrix * inpt[index].v.position;
EmitVertex();
}
# ifdef WIREFRAME
void emit_edge(int v0, int v1, vec3 normal)
{
emit(v0, normal);
emit(v1, normal);
}
# endif
#else
void emit(int index)
{
outpt.v.position = inpt[index].v.position;
outpt.v.normal = inpt[index].v.normal;
/* TODO(sergey): Only uniform subdivisions atm. */
vec2 quadst[4] = vec2[](vec2(0, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1));
vec2 st = quadst[index];
INTERP_FACE_VARYING_2(outpt.v.uv, osd_active_uv_offset, st);
gl_Position = projectionMatrix * inpt[index].v.position;
EmitVertex();
}
# ifdef WIREFRAME
void emit_edge(int v0, int v1)
{
emit(v0);
emit(v1);
}
# endif
#endif
void main()
{
gl_PrimitiveID = gl_PrimitiveIDIn;
#ifdef FLAT_SHADING
vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
vec3 flat_normal = normalize(cross(B, A));
# ifndef WIREFRAME
emit(0, flat_normal);
emit(1, flat_normal);
emit(3, flat_normal);
emit(2, flat_normal);
# else
emit_edge(0, 1, flat_normal);
emit_edge(1, 2, flat_normal);
emit_edge(2, 3, flat_normal);
emit_edge(3, 0, flat_normal);
# endif
#else
# ifndef WIREFRAME
emit(0);
emit(1);
emit(3);
emit(2);
# else
emit_edge(0, 1);
emit_edge(1, 2);
emit_edge(2, 3);
emit_edge(3, 0);
# endif
#endif
EndPrimitive();
}