Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make an infinite cave in my 3d game using flash stage3d. But I got no idea about how to build that cave. Can anyone can give me some solution or hint?
update: I've tried agal fragment shader like squeae tunnel in shadertoy


var fragmentProgramCode:String =
                .sub("ft3","ft2","fc5.x")//vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
                .pow("ft4","ft1","fc6.z")//float r = pow( pow(p.x*p.x,16.0) + pow(p.y*p.y,16.0), 1.0/32.0 );
                .add("ft5.x","fc7.x","ft1")//uv.x = .5*time + 0.5/r;
                .mov("ft6","fc0")//for atan
                .atan2("ft5.y","ft3.y","ft3.x",new <String>["fc7.y","fc5.x","fc7.z","fc7.w","fc8.x","fc8.y","fc8.z","fc8.w","fc9.x","fc9.y"],"ft6")

it can only apply one material,but my project requires different types of material (like floor,ceilling). so ,I create a 3d model cave Is there anyway to make that 3d model render like "infinity cave"? use agal to make each side of cave's texture move? thanks for your help

update again:

I tried glsl to make a cube,when using color It looks good,but when I don't know how to apply texture's transform. It's really hard for me to accomplish this,haven't 3d experience before,thanks for your time !     

#ifdef GL_ES
precision highp float;

uniform vec2 resolution;
uniform float time;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;

vec4 p1 = vec4(0.0, 1.0, 0.0, 1.3);//down
vec4 p2 = vec4(0.0, - 1.0, 0.0, 1.3);//up
vec4 p3 = vec4(1.0, 0.0, 0.0, 1.3);//left
vec4 p4 = vec4(-1.0, 0.0, 0.0, 1.3);//right
vec4 p5 = vec4(0.0, 0.0, 1.0, 1.3);//center

void main(){
 vec2 uv = -1.0 + 2.0*gl_FragCoord.xy/resolution.xy;
 uv.x *= resolution.x/resolution.y;
 vec3 o = vec3(0.0, 0.0, 2.3);
 vec3 rd = normalize(vec3(uv, -1.0));
 vec3 lp = vec3(sin(time), sin(time), cos(time));
 float li = 2.0;
 vec3 co;   

 float tm = 10000.0;
 float t=- (dot(, o)+p1.w)/dot(,rd);
   co =vec3(.2);//down
 t=- (dot(, o)+p2.w)/dot(,rd);
 if (t>0.0&&t<tm){
   co =vec3(.3);//top
   tm = t;
 t=- (dot(, o)+p3.w)/dot(,rd);
 if (t>0.0&&t<tm){
    co =vec3(.4);//left
    tm = t;
 t=- (dot(, o)+p4.w)/dot(,rd);
 if (t>0.0&&t<tm){
    co =vec3(.5);//right

    tm = t;
 t=- (dot(, o)+p5.w)/dot(,rd);
 if (t>0.0&&t<tm){
     co =vec3(.6); //center
 gl_FragColor = vec4(co, 1.0);

texture not apply transform

share|improve this question
This question really lacks detail. What have you tried so far? "Cave" isn't specific enough... what kind of cave? Does it have turns/splits? What look are you trying to achieve? Do you import assets from a 3D modelling program? – bummzack Nov 4 '12 at 8:42
thank you @bummzack ,I'll update my question – ifree Nov 4 '12 at 9:38
You posted a lot of text but you're not giving us details that help clarify the question. You say "I want to make an infinite cave"; what is an "infinite cave"? – jhocking Nov 5 '12 at 4:34
@jhocking "infinite cave" means the cave's depth is infinite,you can not reach it's end, in my game ,play go strait and never reach the end of that cave thanks for your response :) – ifree Nov 5 '12 at 5:17
up vote 1 down vote accepted

altering the code you've pasted in Shader Toy I've reached something acceptable:

#ifdef GL_ES
precision highp float;

uniform vec2 resolution;
uniform float time;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;

void main(void)
    vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
    vec2 uv;

    float r = pow( pow(p.x*p.x,32.0) + pow(p.y*p.y,32.0), 1.0/.0 );
    uv.x = .5*time + 0.5/r;
    uv.y = 2.0*atan(p.y,p.x)/3.1416+2.5;    
    vec3 col0 = texture2D(tex0,uv).xyz;
    vec3 col1 = texture2D(tex1,uv).xyz;
    vec3 col2 = texture2D(tex2,uv).xyz;
    vec3 col3 = texture2D(tex3,uv).xyz;
    vec3 col  = vec3(0);
    col += (step (4.0,uv.y) + step(uv.y,1.0)) * col0; 
    col += step (1.0,uv.y) * step(uv.y,2.0) * col1;
    col += step (2.0,uv.y) * step(uv.y,3.0) * col2;
    col += step (3.0,uv.y) * step(uv.y,4.0) * col3;
    gl_FragColor = vec4(col*r*r*r,1.0);

this code uses all 4 texture slots so if you want to see the results in shader toy you need to fill all 4 texture units there, here are the textures I used:

unit 0 :
unit 1 :
unit 2 :
unit 3 :
share|improve this answer
,another question ,can you tell me how to adjust each side's length depth etc ? thanks :) – ifree Nov 5 '12 at 12:04
thank you Gajoo :) – ifree Nov 5 '12 at 12:23
@ifree find that on your own, a little bit hint, you mus modify last line! – Ali.S Nov 5 '12 at 13:22
I've figured it out,but don't know why should modify last line ? performance issue or what? I've never write glsl before can you tell me – ifree Nov 5 '12 at 15:59
@ifree actually this was the 8th fragment shader I've written so far! the thing is you need to understand what each line is doing, and I'm not going to explain it line by line. try reading some GLSL documentation or start playing with variables and other thing to see what effect you can create! I've started writing that code with this method. and as you see I've succeeded creating something! – Ali.S Nov 5 '12 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.