Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

code:

var fragmentProgramCode:String =
                AGALUtils.build()
                .mov("ft0","v0")
                .div("ft1","ft0.xy","fc3.xy")
                .mul("ft2","fc6.x","ft1")
                .sub("ft3","ft2","fc5.x")//vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
                .mul("ft1","ft3.x","ft3.x")
                .mul("ft2","ft3.y","ft3.y")
                .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 );
                .pow("ft5","ft2","fc6.z")
                .add("ft1","ft4","ft5")
                .pow("ft4","ft1","fc6.w")
                .mov("ft5","fc5")//uv
                .sub("ft1","fc7.x","ft4")
                .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")
                .tex("ft0","ft5","fs0","repeat","linear","nomip")//tex
                .mul("ft1","ft4","ft4")
                .mul("ft2","ft1","ft4")//r*r*r
                .mul("ft1","ft0.xyz","ft2")
                .mov("ft0.w","fc5.x")
                .mov("oc","ft1").toString()

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;
#endif

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(p1.xyz, o)+p1.w)/dot(p1.xyz,rd);
 if(t>0.0&&t<tm){
   co =vec3(.2);//down
   tm=t;
 }
 t=- (dot(p2.xyz, o)+p2.w)/dot(p2.xyz,rd);
 if (t>0.0&&t<tm){
   co =vec3(.3);//top
   tm = t;
 }
 t=- (dot(p3.xyz, o)+p3.w)/dot(p3.xyz,rd);
 if (t>0.0&&t<tm){
    co =vec3(.4);//left
    tm = t;
 }
 t=- (dot(p4.xyz, o)+p4.w)/dot(p4.xyz,rd);
 if (t>0.0&&t<tm){
    co =vec3(.5);//right

    tm = t;
 }
 t=- (dot(p5.xyz, o)+p5.w)/dot(p5.xyz,rd);
 if (t>0.0&&t<tm){
     co =vec3(.6); //center
     tm=t;
 }
 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

1 Answer 1

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;
#endif

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 : http://www.iquilezles.org/apps/shadertoy/presets/tex0.jpg
unit 1 : http://www.iquilezles.org/apps/shadertoy/presets/tex1.jpg
unit 2 : http://www.iquilezles.org/apps/shadertoy/presets/tex2.jpg
unit 3 : http://www.iquilezles.org/apps/shadertoy/presets/tex3.jpg
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

 
discard

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.