Project

General

Profile

« Previous | Next » 

Revision 23b733db

Added by Leszek Koltunski about 4 years ago

Further corrections.

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_objD;                 // half of object width x half of object height X half the depth;
35
                                     // point (0,0,0) is the center of the object
36

  
34
uniform vec3 u_Bounding;             // MeshBase.mBounding{X,Y,Z}
35
uniform vec3 u_Stretch;              // MeshBase.mStretch{X,Y,Z}
37 36
uniform mat4 u_MVPMatrix;            // the combined model/view/projection matrix.
38 37
uniform mat4 u_MVMatrix;             // the combined model/view matrix.
39 38
uniform float u_Inflate;             // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
......
50 49
//////////////////////////////////////////////////////////////////////////////////////////////
51 50
// The trick below is the if-less version of the
52 51
//
53
// t = dx<0.0 ? (u_objD.x-v.x) / (u_objD.x-ux) : (u_objD.x+v.x) / (u_objD.x+ux);
54
// h = dy<0.0 ? (u_objD.y-v.y) / (u_objD.y-uy) : (u_objD.y+v.y) / (u_objD.y+uy);
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);
55 54
// d = min(t,h);
56 55
//
57
// float d = min(-ps.x/(sign(ps.x)*u_objD.x+p.x),-ps.y/(sign(ps.y)*u_objD.y+p.y))+1.0;
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;
58 57
//
59
// We still have to avoid division by 0 when p.x = +- u_objD.x or p.y = +- u_objD.y (i.e on the edge of the Object)
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 60
// We do that by first multiplying the above 'float d' with sign(denominator1*denominator2)^2.
61 61
//
62 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_objD+S) !
63
// the interiors of the Faces move! Thus, we want the MIDDLE of the PS/(sign(PS)*u_Bounding+S) !
64 64
//////////////////////////////////////////////////////////////////////////////////////////////
65
// return degree of the point as defined by the object cuboid (u_objD.x X u_objD.y X u_objD.z)
65
// return degree of the point as defined by the cuboid (u_Bounding.x X u_Bounding.y X u_Bounding.z)
66 66

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

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

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

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

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

  
144 144
  float d1= ret.x-ret.y;
145 145
  float d2= ret.y-ret.z;
......
164 164

  
165 165
void main()
166 166
  {
167
  vec3 v = 2.0*u_objD*a_Position;
167
  vec3 v = u_Stretch*a_Position;
168 168
  vec3 n = a_Normal;
169 169

  
170
  v += (u_objD.x+u_objD.y)*u_Inflate*a_Inflate;
170
  v += u_Inflate*u_Stretch*a_Inflate;
171 171

  
172 172
#if NUM_VERTEX>0
173 173
  int effect=0;
......
181 181
#endif
182 182
   
183 183
  v_Position      = v;
184
  v_endPosition   = v + (0.3*u_objD.x)*n;
184
  v_endPosition   = v + 0.3*u_Stretch*n;
185 185
  v_TexCoordinate = a_TexCoordinate;
186 186
  v_Normal        = normalize(vec3(u_MVMatrix*vec4(n,0.0)));
187 187
  gl_Position     = u_MVPMatrix*vec4(v,1.0);

Also available in: Unified diff