Project

General

Profile

« Previous | Next » 

Revision 0f10a0b6

Added by Leszek Koltunski about 4 years ago

A lot of changes.

1) main vertex shader: remove support for degree_object. This functionality will hopefully come back when we introduce other than circular regions.
2) MeshBase: remove the need to set a Bounding box (this is the point of the whole thing - we wanted to get rid of this so that the advances in MeshJoined will be easier)
3) Set ground for removing the MeshBase.setStretch / getStretch (another thing needed to advance MeshJoined )
4) since we removed the Bounding box, we need to change the DEFORN effect to have 1 additional parameter, the 'radius' which takes over the function of the bounding box in the vertex shader.
5) since the'res no bounding box, simplify the postprocessing Halo (remove EffectQueueMatrix.magnify() )
6) adjust applications.

After this we will hopefully be ready to introduce MeshBase.preApply(VertexEffect), i.e. bending several simple Meshes with any VertexEffect - including the freshly-introduced PseudoMatrix-Vertex effects like VertexEffectScale - and then combining them into one MeshJoined.

View differences:

src/main/res/raw/main_vertex_shader.glsl
31 31
out vec3 v_Normal;                   //
32 32
out vec2 v_TexCoordinate;            //
33 33

  
34
uniform vec3 u_Bounding;             // MeshBase.mBounding{X,Y,Z}
35 34
uniform vec3 u_Stretch;              // MeshBase.mStretch{X,Y,Z}
36 35
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
37 36
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
......
46 45

  
47 46
//////////////////////////////////////////////////////////////////////////////////////////////
48 47
// HELPER FUNCTIONS
49
//////////////////////////////////////////////////////////////////////////////////////////////
50
// The trick below is the if-less version of the
51
//
52
// t = dx<0.0 ? (u_Bounding.x-v.x) / (u_Bounding.x-ux) : (u_Bounding.x+v.x) / (u_Bounding.x+ux);
53
// h = dy<0.0 ? (u_Bounding.y-v.y) / (u_Bounding.y-uy) : (u_Bounding.y+v.y) / (u_Bounding.y+uy);
54
// d = min(t,h);
55
//
56
// float d = min(-ps.x/(sign(ps.x)*u_Bounding.x+p.x),-ps.y/(sign(ps.y)*u_Bounding.y+p.y))+1.0;
57
//
58
// We still have to avoid division by 0 when p.x = +- u_Bounding.x or p.y = +- u_Bounding.y (i.e
59
// on the edge of the Object).
60
// We do that by first multiplying the above 'float d' with sign(denominator1*denominator2)^2.
61
//
62
// 2019-01-09: make this 3D. The trick: we want only the EDGES of the cuboid to stay constant.
63
// the interiors of the Faces move! Thus, we want the MIDDLE of the PS/(sign(PS)*u_Bounding+S) !
64
//////////////////////////////////////////////////////////////////////////////////////////////
65
// return degree of the point as defined by the cuboid (u_Bounding.x X u_Bounding.y X u_Bounding.z)
66

  
67
float degree_object(in vec3 S, in vec3 PS)
68
  {
69
  vec3 ONE = vec3(1.0,1.0,1.0);
70
  vec3 A = sign(PS)*u_Bounding + S;
71

  
72
  vec3 signA = sign(A);                      //
73
  vec3 signA_SQ = signA*signA;               // div = PS/A if A!=0, 0 otherwise.
74
  vec3 div = signA_SQ*PS/(A-(ONE-signA_SQ)); //
75
  vec3 ret = sign(u_Bounding)-div;
76

  
77
  float d1= ret.x-ret.y;
78
  float d2= ret.y-ret.z;
79
  float d3= ret.x-ret.z;
80

  
81
  if( d1*d2>0.0 ) return ret.y;             //
82
  if( d1*d3>0.0 ) return ret.z;             // return 1-middle(div.x,div.y,div.z)
83
  return ret.x;                             // (unless size of object is 0 then 0-middle)
84
  }
85

  
86 48
//////////////////////////////////////////////////////////////////////////////////////////////
87 49
// Return degree of the point as defined by the Region. Currently only supports spherical regions.
88 50
//
......
103 65
// where a = PS*PO/|PS| but we are really looking for d = |PX|/(|PX|+|PS|) = 1/(1+ (|PS|/|PX|) ) and
104 66
// |PX|/|PS| = -b + sqrt(b^2 + (OX^2-PO^2)/PS^2) where b=PS*PO/|PS|^2 which can be computed with only one sqrt.
105 67

  
106
float degree_region(in vec4 region, in vec3 PS)
68
float degree(in vec4 region, in vec3 PS)
107 69
  {
108 70
  vec3 PO  = PS + region.xyz;
109 71
  float D = region.w*region.w-dot(PO,PO);      // D = |OX|^2 - |PO|^2
......
125 87
  return 1.0 / (1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT));
126 88
  }
127 89

  
128
//////////////////////////////////////////////////////////////////////////////////////////////
129
// return min(degree_object,degree_region). Just like degree_region, currently only supports spheres.
130

  
131
float degree(in vec4 region, in vec3 S, in vec3 PS)
132
  {
133
  vec3 PO  = PS + region.xyz;
134
  float D = region.w*region.w-dot(PO,PO);     // D = |OX|^2 - |PO|^2
135

  
136
  if( D<=0.0 ) return 0.0;
137

  
138
  vec3 A = sign(PS)*u_Bounding + S;
139
  vec3 signA = sign(A);
140
  vec3 signA_SQ = signA*signA;
141
  vec3 div = signA_SQ*PS/(A-(vec3(1.0,1.0,1.0)-signA_SQ));
142
  vec3 ret = sign(u_Bounding)-div;            // if object is flat, make ret.z 0
143

  
144
  float d1= ret.x-ret.y;
145
  float d2= ret.y-ret.z;
146
  float d3= ret.x-ret.z;
147
  float degree_object;
148

  
149
       if( d1*d2>0.0 ) degree_object= ret.y;  //
150
  else if( d1*d3>0.0 ) degree_object= ret.z;  // middle of the ret.{x,y,z} triple
151
  else                 degree_object= ret.x;  //
152

  
153
  float ps_sq = dot(PS,PS);
154
  float one_over_ps_sq = 1.0/(ps_sq-(sign(ps_sq)-1.0));  // return 1.0 if ps_sq = 0.0
155
  float DOT  = dot(PS,PO)*one_over_ps_sq;
156
  float degree_region = 1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT));
157

  
158
  return min(degree_region,degree_object);
159
  }
160

  
161 90
#endif  // NUM_VERTEX>0
162 91

  
163 92
//////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff