|
| 1 | +// This file consists of model/texture shader tests that don't result in anything useful, |
| 2 | +// it may contain unused uniforms and misplaced comments, I recommend using it for reference purposes only, but you are free to do whatever you want! |
| 3 | +
|
| 4 | +//defuniformparam "transform" [@(_getRayHit)] 0 // x y z rotate |
| 5 | +//defuniformparam "transform" [@(_getRayHit)] 0 // x y z rotate |
| 6 | +defuniformparam "pivot" 0 0 0 0 |
| 7 | +defuniformparam "debug" 0 |
| 8 | +defuniformparam "position" 0 0 0 0 |
| 9 | +defuniformparam "trigger" 0 0 0 0 |
| 10 | +defuniformparam "triggerradius" 0.7 0 0 0 |
| 11 | +
|
| 12 | +shader 0 [_conceptshaders_shadersdemo@getmillis] [ |
| 13 | + attribute vec4 vvertex; |
| 14 | + attribute vec3 vnormal; |
| 15 | + attribute vec2 vtexcoord0, vtexcoord1; |
| 16 | + uniform mat4 camprojmatrix; |
| 17 | + uniform vec2 texgenscroll; |
| 18 | + varying vec2 texcoord0, texcoord1; |
| 19 | + varying vec4 dbgvvertex; |
| 20 | + uniform vec3 camera; |
| 21 | + uniform vec3 center; |
| 22 | + uniform vec3 objectCenter; |
| 23 | + uniform float millis; |
| 24 | + varying vec3 objectCenterdbg; |
| 25 | + varying vec3 positionOffset; |
| 26 | + varying vec2 is_triggered; |
| 27 | + mat4 getRotationMatrix(float angle) { |
| 28 | + float c = cos(angle); |
| 29 | + float s = sin(angle); |
| 30 | + return mat4( |
| 31 | + vec4(c, -s, 0.0, 0.0), |
| 32 | + vec4(s, c, 0.0, 0.0), |
| 33 | + vec4(0.0, 0.0, 1.0, 0.0), |
| 34 | + vec4(0.0, 0.0, 0.0, 1.0) |
| 35 | + ); |
| 36 | + } |
| 37 | +
|
| 38 | + //:water |
| 39 | + void main(void) |
| 40 | + { |
| 41 | + // 1. Define the object's world-space center (a known value or calculated from bounding box). |
| 42 | + //vec3 objectCenter = vec3(2752+32, 2114+64, 2048); // Example: Midpoint of a 4096x4096x4096 world |
| 43 | + dbgvvertex = vvertex; |
| 44 | + //vec3 objectCenter = vec3(transform.xyz); |
| 45 | + // Step 2: Use nearestZ for the z-component of objectCenter |
| 46 | + vec3 objectCenter = vec3(pivot.w == 1 ? pivot.xyz : vvertex.xyz); |
| 47 | + |
| 48 | + // 2. Compute the rotation matrix using transform.w (rotation angle). |
| 49 | + mat4 rotationMatrix = getRotationMatrix(position.w == 0 ? sin(millis*2) : mod(millis, 2.0 * 3.14159)); |
| 50 | + |
| 51 | + is_triggered.x = float(abs(camera.x - trigger.x) <= triggerradius.x && |
| 52 | + abs(camera.y - trigger.y) <= triggerradius.y && |
| 53 | + abs(camera.z - trigger.z) <= triggerradius.z); |
| 54 | + |
| 55 | + |
| 56 | + if (is_triggered.x == 1) { |
| 57 | + if (trigger.w == 1) { |
| 58 | + positionOffset.z -= 1.8; |
| 59 | + } |
| 60 | + |
| 61 | + if (trigger.w == 2) { |
| 62 | + rotationMatrix = getRotationMatrix(mod(millis*5, 2.0 * 3.14159)); |
| 63 | + } |
| 64 | + |
| 65 | + if (trigger.w == 5) { |
| 66 | + positionOffset.x += 0.65; |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + if (trigger.w == 8) { |
| 74 | + positionOffset.z += distance(vvertex.xy, camera.xy)/2; |
| 75 | + } |
| 76 | + |
| 77 | + if (trigger.w == 9) { |
| 78 | + positionOffset.z += 20; |
| 79 | + positionOffset.xyz += sin(vvertex.z+millis); |
| 80 | + } |
| 81 | + |
| 82 | + if (trigger.w == 10) { |
| 83 | + positionOffset.z += 20; |
| 84 | + positionOffset.y += 2-cos(vvertex.x+millis)*2; |
| 85 | + } |
| 86 | + |
| 87 | + if (trigger.w == 11) { |
| 88 | + positionOffset.z += 10; |
| 89 | + positionOffset.z += 2-cos(vvertex.x+millis)*2; |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + // 3. Translate the vertex relative to the object's center (bring the object to the origin). |
| 94 | + vec4 translatedVertex = vec4(vvertex.xyz - objectCenter, 0.0); |
| 95 | +
|
| 96 | + // 4. Apply the rotation. |
| 97 | + vec4 rotatedVertex = rotationMatrix * translatedVertex; |
| 98 | +
|
| 99 | + // 5. Translate the rotated vertex back to the object's world position. |
| 100 | + vec4 finalVertex = rotatedVertex + vec4(objectCenter + position.xyz + positionOffset.xyz, 1.0); |
| 101 | + |
| 102 | + // 6. Apply camera projection. |
| 103 | + gl_Position = camprojmatrix * finalVertex; |
| 104 | + |
| 105 | + texcoord0 = vtexcoord0 + texgenscroll; |
| 106 | + texcoord1 = vtexcoord1 * @lmcoordscale; |
| 107 | + objectCenterdbg = objectCenter; |
| 108 | + //:shadowmap |
| 109 | + //:dynlight |
| 110 | + } |
| 111 | +] [ |
| 112 | + uniform vec4 colorparams; |
| 113 | + varying vec2 texcoord0, texcoord1; |
| 114 | + uniform sampler2D diffusemap, lightmap, tsky; |
| 115 | + varying vec4 dbgvvertex; // Vertex position in 3D space |
| 116 | + varying vec3 objectCenterdbg; // Center of the object |
| 117 | + uniform vec3 camera; // Camera position |
| 118 | + uniform float millis; |
| 119 | + uniform float alphatest; |
| 120 | + varying vec2 is_triggered; |
| 121 | + uniform vec4 ambient; |
| 122 | + uniform mat4 camprojmatrix; |
| 123 | + |
| 124 | + mat4 constructProjectionMatrix(float fovy, float aspect, float znear, float zfar) { |
| 125 | + float f = 1.0 / tan(fovy / 2.0); |
| 126 | + mat4 M = mat4(0.0); |
| 127 | + M[0][0] = f / aspect; |
| 128 | + M[1][1] = f; |
| 129 | + M[2][2] = (zfar + znear) / (znear - zfar); |
| 130 | + M[2][3] = -1.0; |
| 131 | + M[3][2] = (2.0 * zfar * znear) / (znear - zfar); |
| 132 | + return M; |
| 133 | + } |
| 134 | + |
| 135 | + vec2 extractYawPitch(mat4 cammatrix) { |
| 136 | + mat3 R = mat3(cammatrix); |
| 137 | + vec3 forward = -vec3(R[0][2], R[1][2], R[2][2]); |
| 138 | + float yaw = atan(forward.x, forward.y); |
| 139 | + float pitch = asin(forward.z); |
| 140 | + return vec2(yaw, pitch); |
| 141 | + } |
| 142 | + |
| 143 | + void main(void) |
| 144 | + { |
| 145 | + |
| 146 | + float A = camprojmatrix[2][2]; |
| 147 | + float B = camprojmatrix[2][3]; |
| 148 | + float nearPlane = B / (A - 1.0); |
| 149 | + float farPlane = B / (A + 1.0); |
| 150 | + float aspect = @scr_w / @scr_h; |
| 151 | + mat4 proj = constructProjectionMatrix(@fov, aspect, nearPlane, farPlane); |
| 152 | + mat4 invProj = inverse(proj); |
| 153 | + mat4 view = invProj * camprojmatrix; |
| 154 | + vec2 yawPitch = extractYawPitch(view); |
| 155 | + float yaw = -yawPitch.x; // Yaw in radians |
| 156 | + float pitch = yawPitch.y; // Pitch in radians |
| 157 | + |
| 158 | + vec4 lm = texture2D(lightmap, texcoord1); |
| 159 | + vec4 diffuse = texture2D(diffusemap, texcoord0); |
| 160 | + |
| 161 | + // Base color calculation with dynamic lighting |
| 162 | + //:shadowmap lm |
| 163 | + //:dynlight lm |
| 164 | + |
| 165 | + gl_FragColor = pivot.w == 0 ? (diffuse*lm) : |
| 166 | + (diffuse * lm) - vec4((round(dbgvvertex.x) == round(objectCenterdbg.x)) ? 1 : 0, |
| 167 | + (round(dbgvvertex.y) == round(objectCenterdbg.y)) ? 1 : 0, |
| 168 | + (round(dbgvvertex.z) == round(objectCenterdbg.z)) ? 1 : 0, |
| 169 | + 0.0); |
| 170 | + |
| 171 | + if (is_triggered.x == 1) { |
| 172 | + //gl_FragColor = mix(gl_FragColor, vec4(1.0, 0.0, 1.0, 1.0), 1.0); |
| 173 | + if (trigger.w == 1) { // pressure plate |
| 174 | + gl_FragColor = mix(gl_FragColor, vec4(0.5, 0.0, 0.5, 1.0), 1.0); |
| 175 | + } |
| 176 | + |
| 177 | + if (trigger.w == -1 || trigger.w == 2) { // pressure plate room & spinning object |
| 178 | + gl_FragColor = mix(gl_FragColor, vec4((round(dbgvvertex.x) == round(camera.x)) ? 1 : gl_FragColor.x, |
| 179 | + (round(dbgvvertex.y) == round(camera.y)) ? 1 : gl_FragColor.y, |
| 180 | + (round(dbgvvertex.z) == round(camera.z)) ? 1 : gl_FragColor.z, |
| 181 | + 0.0), 1.0); |
| 182 | + |
| 183 | + } |
| 184 | + if (trigger.w == 4 || trigger.w == 6) { // lantern cave |
| 185 | + vec2 center = vec2(@scr_w / 2, @scr_h / 2); // Center of the lantern effect |
| 186 | + float outerRadius = 512.0; // Radius of the outer glow |
| 187 | + float innerRadius = 128.0; // Radius of the bright center |
| 188 | + float dist = length(gl_FragCoord.xy - center); // Distance from the center |
| 189 | + |
| 190 | + if (trigger.w == 6) { // auggiedog |
| 191 | + diffuse = texture2D(tsky, texcoord0 + vec2( |
| 192 | + sin(texcoord0.y * 10.0 + millis * 2) * 0.02, |
| 193 | + cos(texcoord0.x * 10.0 + millis * 2) * 0.02 |
| 194 | + )); |
| 195 | + } |
| 196 | + |
| 197 | + if (dist < outerRadius) { // Inside the outer lantern radius |
| 198 | + float outerFalloff = 1.0 - (dist / outerRadius); // Fade from edge to center of outer radius |
| 199 | + vec3 outerColor = mix(vec3(0.0), diffuse.rgb, outerFalloff); // Black to diffuse.rgb |
| 200 | + |
| 201 | + if (dist < innerRadius) { // Inside the bright center radius |
| 202 | + float innerFalloff = 1.0 - (dist / innerRadius); // Stronger fade for center |
| 203 | + vec3 innerColor = mix(outerColor, diffuse.rgb * 1.5, innerFalloff); // Brighten diffuse.rgb in the center |
| 204 | + gl_FragColor = vec4(innerColor, 1.0); |
| 205 | + } else { |
| 206 | + gl_FragColor = vec4(outerColor, 1.0); |
| 207 | + } |
| 208 | + } else { |
| 209 | + // Outside the radius, set color to black |
| 210 | + gl_FragColor = vec4(diffuse.rgb-0.6, 1.0); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + if (trigger.w == 5) { // switch |
| 215 | + gl_FragColor = vec4(1.0, 1.0, 0.5, 0.0); |
| 216 | + } |
| 217 | + |
| 218 | + if (trigger.w == 3) { // house wall/ground (lights on) |
| 219 | + gl_FragColor = diffuse * vec4(lm.b, lm.b, lm.b, 1.0); |
| 220 | + } |
| 221 | + |
| 222 | + } else { |
| 223 | + if (trigger.w == 4 || trigger.w == 6) { // lantern cave |
| 224 | + gl_FragColor = vec4((diffuse.rgb*lm.rgb)-0.05, 1.0); |
| 225 | + //gl_FragColor = vec4(0.0); |
| 226 | + } |
| 227 | + if (trigger.w == 3) { // house wall/ground (lights off) |
| 228 | + gl_FragColor = (diffuse-0.1) * vec4(lm.r, lm.r, lm.r, 1.0); |
| 229 | + } |
| 230 | + } |
| 231 | + |
| 232 | + |
| 233 | + if (trigger.w == 7) { // room psicodelic |
| 234 | + |
| 235 | + } |
| 236 | + |
| 237 | + |
| 238 | + |
| 239 | + } |
| 240 | +] |
| 241 | + |
| 242 | + |
| 243 | +_SD_modeltrigger = [ |
| 244 | + local shadername position radius body |
| 245 | + shadername = $arg1 |
| 246 | + position = $arg2 |
| 247 | + radius = $arg3 |
| 248 | + body = $arg4 |
| 249 | + _SD_loadingmodelshader = $shadername |
| 250 | + shader 0 $shadername [ |
| 251 | + // Vertex Shader |
| 252 | + attribute vec4 vvertex, vcolor; |
| 253 | + attribute vec2 vtexcoord0; |
| 254 | + varying vec2 texcoord0; |
| 255 | + varying vec4 color; |
| 256 | + uniform mat4 modelmatrix; |
| 257 | + uniform vec3 camera; |
| 258 | + vec3 trigger = vec3(@(at $position 0), @(at $position 1), @(at $position 2)); |
| 259 | + vec3 triggerradius = vec3(@(at $radius 0), @(at $radius 1), @(at $radius 2)); |
| 260 | + varying vec2 is_triggered; |
| 261 | + |
| 262 | + void main(void) |
| 263 | + { |
| 264 | + gl_Position = modelmatrix * vvertex; |
| 265 | + texcoord0 = vtexcoord0; |
| 266 | + color = vcolor; |
| 267 | + |
| 268 | + is_triggered.x = float(abs(camera.x - trigger.x) <= triggerradius.x && |
| 269 | + abs(camera.y - trigger.y) <= triggerradius.y && |
| 270 | + abs(camera.z - trigger.z) <= triggerradius.z); |
| 271 | + } |
| 272 | + ] [ |
| 273 | + // Fragment Shader |
| 274 | + uniform sampler2D diffusemap; |
| 275 | + varying vec2 texcoord0; |
| 276 | + varying vec4 color; |
| 277 | + uniform vec3 camera; |
| 278 | + vec4 diffuse = texture2D(diffusemap, texcoord0); |
| 279 | + varying vec2 is_triggered; |
| 280 | + |
| 281 | + int is_active = int(round(is_triggered.x)); |
| 282 | + |
| 283 | + void main(void) |
| 284 | + { |
| 285 | + @body |
| 286 | + } |
| 287 | + ] |
| 288 | +] |
| 289 | + |
| 290 | +_SD_modeltrigger [_conceptshaders_lamp@getmillis] [1260 918 1040] [5 5 5] [ |
| 291 | + gl_FragColor = (is_active == 0) ? ((diffuse-0.1) - vec4(diffuse.r > 0.5, diffuse.g > 0.5, diffuse.b > 0.5, 0)) : diffuse; |
| 292 | +] |
| 293 | +mmodel "conceptshaders/bulb" |
| 294 | +clearmodel "conceptshaders/bulb" |
| 295 | + |
| 296 | +_SD_modeltrigger [_conceptshaders_furniture@getmillis] [1260 918 1040] [5 5 5] [ |
| 297 | + gl_FragColor = (is_active == 0) ? vec4(diffuse.rgb*0.05, 1)-0.01 : diffuse-0.05; |
| 298 | +] |
| 299 | + |
| 300 | +mmodel "conceptshaders/bed01" |
| 301 | +mmodel "conceptshaders/chair01" |
| 302 | +mmodel "conceptshaders/table01" |
| 303 | +clearmodel "conceptshaders/bed01" |
| 304 | +clearmodel "conceptshaders/chair01" |
| 305 | +clearmodel "conceptshaders/table01" |
| 306 | + |
| 307 | +setshader [_conceptshaders_shadersdemo@getmillis] |
| 308 | + |
| 309 | +texture 0 "textures/fatum/white.jpg" |
| 310 | +texture 0 "textures/philipk/pk02/floor09a_c.jpg" |
| 311 | +texture 0 "textures/yves_allaire/ex/cretebase_01_d.jpg" |
| 312 | +texture 0 "mitaman/mm-auggiedog.jpg" |
| 313 | +texture 0 "textures/nieb/rock02.jpg" |
| 314 | +texture 0 "dg/mad065.jpg" |
| 315 | +texture 0 "ik2k/ik_woodv256a.jpg" |
| 316 | +texture 0 "<mad:3>egyptsoc/wood17.jpg" |
| 317 | + |
| 318 | +_getRayHit = [ |
| 319 | + local PI X Y Z SZ YAW PITCH PLANE YAWRAD PITCHRAD DIRX DIRY DIRZ DISTANCE HITX HITY |
| 320 | + PI = 3.141592653589793 |
| 321 | + |
| 322 | + X = (at (getcampos) 0) |
| 323 | + Y = (at (getcampos) 1) |
| 324 | + Z = (at (getcampos) 2) |
| 325 | + SZ = (at (getselpos) 2) |
| 326 | + |
| 327 | + YAW = (getcamyaw) |
| 328 | + PITCH = (getcampitch) |
| 329 | + |
| 330 | + PLANE = (? (< $Z $SZ) $SZ (+ $SZ (div (<< 2 $gridpower) 2))) |
| 331 | + |
| 332 | + YAWRAD = (-f 90 $YAW) |
| 333 | + PITCHRAD = $PITCH |
| 334 | + |
| 335 | + |
| 336 | + DIRX = (*f (cos $PITCHRAD) (cos $YAWRAD)) |
| 337 | + DIRY = (*f (cos $PITCHRAD) (sin $YAWRAD)) |
| 338 | + DIRZ = (sin $PITCHRAD) |
| 339 | + |
| 340 | + DISTANCE = (divf (-f $PLANE $Z) $DIRZ) |
| 341 | + |
| 342 | + HITX = (-f $X (*f $DIRX $DISTANCE)) |
| 343 | + HITY = (+f $Y (*f $DIRY $DISTANCE)) |
| 344 | + |
| 345 | + concat $HITX $HITY $PLANE |
| 346 | +] |
| 347 | + |
| 348 | + |
| 349 | + |
0 commit comments