Revision 0f10a0b6
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/effect/VertexEffectWave.java | ||
---|---|---|
129 | 129 |
{ |
130 | 130 |
addEffect(EffectName.WAVE, |
131 | 131 |
|
132 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
|
133 |
+ "float amplitude = vUniforms[effect ].x; \n" |
|
134 |
+ "float length = vUniforms[effect ].y; \n" |
|
132 |
"vec3 center = vUniforms[effect+1].yzw; \n"
|
|
133 |
+ "float amplitude = vUniforms[effect ].x; \n"
|
|
134 |
+ "float length = vUniforms[effect ].y; \n"
|
|
135 | 135 |
|
136 |
+ "vec3 ps = center - v; \n" |
|
137 |
+ "float deg = amplitude*degree_region(vUniforms[effect+2],ps); \n"
|
|
136 |
+ "vec3 ps = center - v; \n"
|
|
137 |
+ "float deg = amplitude*degree(vUniforms[effect+2],ps); \n"
|
|
138 | 138 |
|
139 |
+ "if( deg != 0.0 && length != 0.0 ) \n" |
|
140 |
+ "{ \n" |
|
141 |
+ "float phase = vUniforms[effect ].z; \n" |
|
142 |
+ "float alpha = vUniforms[effect ].w; \n" |
|
143 |
+ "float beta = vUniforms[effect+1].x; \n" |
|
139 |
+ "if( deg != 0.0 && length != 0.0 ) \n"
|
|
140 |
+ "{ \n"
|
|
141 |
+ "float phase = vUniforms[effect ].z; \n"
|
|
142 |
+ "float alpha = vUniforms[effect ].w; \n"
|
|
143 |
+ "float beta = vUniforms[effect+1].x; \n"
|
|
144 | 144 |
|
145 |
+ "float sinA = sin(alpha); \n" |
|
146 |
+ "float cosA = cos(alpha); \n" |
|
147 |
+ "float sinB = sin(beta); \n" |
|
148 |
+ "float cosB = cos(beta); \n" |
|
145 |
+ "float sinA = sin(alpha); \n"
|
|
146 |
+ "float cosA = cos(alpha); \n"
|
|
147 |
+ "float sinB = sin(beta); \n"
|
|
148 |
+ "float cosB = cos(beta); \n"
|
|
149 | 149 |
|
150 | 150 |
+ "float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length + phase; \n" |
151 |
+ "vec3 dir= vec3(sinB*cosA,cosB*cosA,sinA); \n" |
|
152 |
+ "v += sin(angle)*deg*dir; \n" |
|
153 |
|
|
154 |
+ "if( n.z != 0.0 ) \n" |
|
155 |
+ "{ \n" |
|
156 |
+ "float sqrtX = sqrt(dir.y*dir.y + dir.z*dir.z); \n" |
|
157 |
+ "float sqrtY = sqrt(dir.x*dir.x + dir.z*dir.z); \n" |
|
158 |
|
|
159 |
+ "float sinX = ( sqrtY==0.0 ? 0.0 : dir.z / sqrtY); \n" |
|
160 |
+ "float cosX = ( sqrtY==0.0 ? 1.0 : dir.x / sqrtY); \n" |
|
161 |
+ "float sinY = ( sqrtX==0.0 ? 0.0 : dir.z / sqrtX); \n" |
|
162 |
+ "float cosY = ( sqrtX==0.0 ? 1.0 : dir.y / sqrtX); \n" |
|
163 |
|
|
164 |
+ "float abs_z = dir.z <0.0 ? -(sinX*sinY) : (sinX*sinY); \n" |
|
165 |
+ "float tmp = 1.578*cos(angle)*deg/length; \n" |
|
166 |
|
|
167 |
+ "float fx =-cosB*tmp; \n" |
|
168 |
+ "float fy = sinB*tmp; \n" |
|
169 |
|
|
170 |
+ "vec3 sx = vec3 (1.0+cosX*fx,cosY*sinX*fx,abs_z*fx); \n" |
|
171 |
+ "vec3 sy = vec3 (cosX*sinY*fy,1.0+cosY*fy,abs_z*fy); \n" |
|
172 |
|
|
173 |
+ "vec3 normal = cross(sx,sy); \n" |
|
174 |
|
|
175 |
+ "if( normal.z<=0.0 ) \n" // Why this bizarre thing rather than the straightforward
|
|
176 |
+ "{ \n" //
|
|
177 |
+ "normal.x= 0.0; \n" // if( normal.z>0.0 )
|
|
178 |
+ "normal.y= 0.0; \n" // {
|
|
179 |
+ "normal.z= 1.0; \n" // n.x = (n.x*normal.z + n.z*normal.x);
|
|
180 |
+ "} \n" // n.y = (n.y*normal.z + n.z*normal.y);
|
|
181 |
// n.z = (n.z*normal.z); |
|
182 |
// } |
|
183 |
+ "n.x = (n.x*normal.z + n.z*normal.x); \n" //
|
|
184 |
+ "n.y = (n.y*normal.z + n.z*normal.y); \n" // ? Because if we do the above, my Nexus4 crashes
|
|
185 |
+ "n.z = (n.z*normal.z); \n" // during shader compilation!
|
|
186 |
+ "} \n" |
|
151 |
+ "vec3 dir= vec3(sinB*cosA,cosB*cosA,sinA); \n"
|
|
152 |
+ "v += sin(angle)*deg*dir; \n"
|
|
153 |
|
|
154 |
+ "if( n.z != 0.0 ) \n"
|
|
155 |
+ "{ \n"
|
|
156 |
+ "float sqrtX = sqrt(dir.y*dir.y + dir.z*dir.z); \n"
|
|
157 |
+ "float sqrtY = sqrt(dir.x*dir.x + dir.z*dir.z); \n"
|
|
158 |
|
|
159 |
+ "float sinX = ( sqrtY==0.0 ? 0.0 : dir.z / sqrtY); \n"
|
|
160 |
+ "float cosX = ( sqrtY==0.0 ? 1.0 : dir.x / sqrtY); \n"
|
|
161 |
+ "float sinY = ( sqrtX==0.0 ? 0.0 : dir.z / sqrtX); \n"
|
|
162 |
+ "float cosY = ( sqrtX==0.0 ? 1.0 : dir.y / sqrtX); \n"
|
|
163 |
|
|
164 |
+ "float abs_z = dir.z <0.0 ? -(sinX*sinY) : (sinX*sinY); \n"
|
|
165 |
+ "float tmp = 1.578*cos(angle)*deg/length; \n"
|
|
166 |
|
|
167 |
+ "float fx =-cosB*tmp; \n"
|
|
168 |
+ "float fy = sinB*tmp; \n"
|
|
169 |
|
|
170 |
+ "vec3 sx = vec3 (1.0+cosX*fx,cosY*sinX*fx,abs_z*fx); \n"
|
|
171 |
+ "vec3 sy = vec3 (cosX*sinY*fy,1.0+cosY*fy,abs_z*fy); \n"
|
|
172 |
|
|
173 |
+ "vec3 normal = cross(sx,sy); \n"
|
|
174 |
|
|
175 |
+ "if( normal.z<=0.0 ) \n" // Why this bizarre thing rather than the straightforward
|
|
176 |
+ "{ \n" //
|
|
177 |
+ "normal.x= 0.0; \n" // if( normal.z>0.0 )
|
|
178 |
+ "normal.y= 0.0; \n" // {
|
|
179 |
+ "normal.z= 1.0; \n" // n.x = (n.x*normal.z + n.z*normal.x);
|
|
180 |
+ "} \n" // n.y = (n.y*normal.z + n.z*normal.y);
|
|
181 |
// n.z = (n.z*normal.z);
|
|
182 |
// }
|
|
183 |
+ "n.x = (n.x*normal.z + n.z*normal.x); \n" //
|
|
184 |
+ "n.y = (n.y*normal.z + n.z*normal.y); \n" // ? Because if we do the above, my Nexus4 crashes
|
|
185 |
+ "n.z = (n.z*normal.z); \n" // during shader compilation!
|
|
186 |
+ "} \n"
|
|
187 | 187 |
+ "}" |
188 | 188 |
); |
189 | 189 |
} |
Also available in: Unified diff
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.