Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualanindie

Posted 08 May 2012 - 03:01 AM

OK. I gave up bumpmaping. Cause I am trying to do all these calculation in real time, on a iphone. Posted Image Not going to happan. Thanks for all.  

I am writing bit of my shader code, for those who are interested. I hope its correct :?). It seems to working; but as I said before generated normalmap is not smooth.




    vec3 normal=  texture2D(heighttexture, gl_TexCoord[0].xy).xyz;
    
    normal.r=dFdx(normal.x)*50.0;
    normal.g=dFdy(normal.y)*50.0;
    normal.b=0.0;

    float z = abs(normal.r)+abs(normal.g);
    
    if( z > 1.0 )
    {
        normal.rg/=z;
    }

    float blue = 1.0-length(normal);

    normal=normal*0.5+0.5;

    normal.b= blue;




This is another code that I tried, generates smooth normals, it makes again expensive.



const float width=0.01;
const float strength=1.0;



vec3 nomralfrombump(sampler2D atex,vec2 textcoord)
{
        
    vec4 heretex = texture2D(atex, textcoord.xy);
    
    if(heretex.a == 0.0)
    return vec3(0.0,0.0,0.0);
    
    vec2 dus= vec2(textcoord.x+width, textcoord.y);

    vec2 dvs= vec2(textcoord.x, textcoord.y+width);
    vec4 du4 = heretex  - texture2D(atex,dus);
    vec4 dv4 = heretex - texture2D(atex,dvs);
    
    du4.x=du4.x*strength;
    dv4.x=dv4.x*strength;
    
    float z = abs(du4.x)+abs(dv4.x);
    
    if( z > 1.0 )
    {
        du4.r/=z;
        dv4.r/=z;
    }
    
    float dw = sqrt(1.0-du4.r*du4.r - dv4.r*dv4.r);
    
    vec3 normal=vec3(du4.x*0.5+0.5,dv4.x*0.5+0.5,dw);
    
    return normal;
    
}

#4anindie

Posted 08 May 2012 - 02:59 AM

Ok I gaveup bumpmaping. Cause I am trying to do all these calculation in real time, on a iphone. Posted Image Not going to happan. Thanks for all.  

I am writing bit of my shader code, for those who are interested. I hope its correct :?). It seems to working; but as I said before its not smooth.




    vec3 normal=  texture2D(heighttexture, gl_TexCoord[0].xy).xyz;
    
    normal.r=dFdx(normal.x)*50.0;
    normal.g=dFdy(normal.y)*50.0;
    normal.b=0.0;

    float z = abs(normal.r)+abs(normal.g);
    
    if( z > 1.0 )
    {
        normal.rg/=z;
    }

    float blue = 1.0-length(normal);

    normal=normal*0.5+0.5;

    normal.b= blue;




This is another code that I tried, generates smooth normals, it makes again expensive.



const float width=0.01;
const float strength=1.0;



vec3 nomralfrombump(sampler2D atex,vec2 textcoord)
{
        
    vec4 heretex = texture2D(atex, textcoord.xy);
    
    if(heretex.a == 0.0)
    return vec3(0.0,0.0,0.0);
    
    vec2 dus= vec2(textcoord.x+width, textcoord.y);

    vec2 dvs= vec2(textcoord.x, textcoord.y+width);
    vec4 du4 = heretex  - texture2D(atex,dus);
    vec4 dv4 = heretex - texture2D(atex,dvs);
    
    du4.x=du4.x*strength;
    dv4.x=dv4.x*strength;
    
    float z = abs(du4.x)+abs(dv4.x);
    
    if( z > 1.0 )
    {
        du4.r/=z;
        dv4.r/=z;
    }
    
    float dw = sqrt(1.0-du4.r*du4.r - dv4.r*dv4.r);
    
    vec3 normal=vec3(du4.x*0.5+0.5,dv4.x*0.5+0.5,dw);
    
    return normal;
    
}

#3anindie

Posted 08 May 2012 - 01:58 AM

Ok I give up bumpmaping. Cause I am trying to do all these calculation in real time, on a iphone. :) Not going to happan. 

I am writing bit of my shader code, for those who are interested. I hope its correct :?). It seems to working; but as I said before its not smooth.




    vec3 normal=  texture2D(heighttexture, gl_TexCoord[0].xy).xyz;
    
    normal.r=dFdx(normal.x)*50.0;
    normal.g=dFdy(normal.y)*50.0;
    normal.b=0.0;

    float z = abs(normal.r)+abs(normal.g);
    
    if( z > 1.0 )
    {
        normal.rg/=z;
    }

    float blue = 1.0-length(normal);

    normal=normal*0.5+0.5;

    normal.b= blue;




This is another code that I tried, generates smooth normals, it makes again expensive.



const float width=0.01;
const float strength=1.0;



vec3 nomralfrombump(sampler2D atex,vec2 textcoord)
{
        
    vec4 heretex = texture2D(atex, textcoord.xy);
    
    if(heretex.a == 0.0)
    return vec3(0.0,0.0,0.0);
    
    vec2 dus= vec2(textcoord.x+width, textcoord.y);

    vec2 dvs= vec2(textcoord.x, textcoord.y+width);
    vec4 du4 = heretex  - texture2D(atex,dus);
    vec4 dv4 = heretex - texture2D(atex,dvs);
    
    du4.x=du4.x*strength;
    dv4.x=dv4.x*strength;
    
    float z = abs(du4.x)+abs(dv4.x);
    
    if( z > 1.0 )
    {
        du4.r/=z;
        dv4.r/=z;
    }
    
    float dw = sqrt(1.0-du4.r*du4.r - dv4.r*dv4.r);
    
    vec3 normal=vec3(du4.x*0.5+0.5,dv4.x*0.5+0.5,dw);
    
    return normal;
    
}

#2anindie

Posted 08 May 2012 - 01:52 AM

Ok I give up bumpmaping. Cause I am trying to do all these calculation in real time on a iphone.  

I am writing more of my shader code those who are interested. I hope its correct(?). it seems to working but as I said before
its not smooth.




    vec3 normal=  texture2D(heighttexture, gl_TexCoord[0].xy).xyz;
    
    normal.r=dFdx(normal.x)*50.0;
    normal.g=dFdy(normal.y)*50.0;
    normal.b=0.0;

    float z = abs(normal.r)+abs(normal.g);
    
    if( z > 1.0 )
    {
        normal.rg/=z;
    }

    float blue = 1.0-length(normal);

    normal=normal*0.5+0.5;

    normal.b= blue;




Another code I tried generates smooth normal it makes agian expensive.



const float width=0.01;
const float strength=1.0;



vec3 nomralfrombump(sampler2D atex,vec2 textcoord)
{
        
    vec4 heretex = texture2D(atex, textcoord.xy);
    
    if(heretex.a == 0.0)
    return vec3(0.0,0.0,0.0);
    
    vec2 dus= vec2(textcoord.x+width, textcoord.y);

    vec2 dvs= vec2(textcoord.x, textcoord.y+width);
    vec4 du4 = heretex  - texture2D(atex,dus);
    vec4 dv4 = heretex - texture2D(atex,dvs);
    
    du4.x=du4.x*strength;
    dv4.x=dv4.x*strength;
    
    float z = abs(du4.x)+abs(dv4.x);
    
    if( z > 1.0 )
    {
        du4.r/=z;
        dv4.r/=z;
    }
    
    float dw = sqrt(1.0-du4.r*du4.r - dv4.r*dv4.r);
    
    vec3 normal=vec3(du4.x*0.5+0.5,dv4.x*0.5+0.5,dw);
    
    return normal;
    
}

#1anindie

Posted 08 May 2012 - 01:51 AM

Ok I give up bumpmaping. Cause I am trying to do all these calculation in real time on a iphone.

I am writing more of my shader code those who are interested. I hope its correct(?). it seems to working but as I said before
its not smooth.




vec3 normal= texture2D(heighttexture, gl_TexCoord[0].xy).xyz;

normal.r=dFdx(color.x)*50.0;
normal.g=dFdy(color.g)*50.0;
normal.b=0.0;

float z = abs(normal.r)+abs(normal.g);

if( z > 1.0 )
{
normal.rg/=z;
}

float blue = 1.0-length(normal);

normal=normal*0.5+0.5;

normal.b= blue;




Another code I tried generates smooth normal it makes agian expensive.



const float width=0.01;
const float strength=1.0;



vec3 nomralfrombump(sampler2D atex,vec2 textcoord)
{

vec4 heretex = texture2D(atex, textcoord.xy);

if(heretex.a == 0.0)
return vec3(0.0,0.0,0.0);

vec2 dus= vec2(textcoord.x+width, textcoord.y);

vec2 dvs= vec2(textcoord.x, textcoord.y+width);
vec4 du4 = heretex - texture2D(atex,dus);
vec4 dv4 = heretex - texture2D(atex,dvs);

du4.x=du4.x*strength;
dv4.x=dv4.x*strength;

float z = abs(du4.x)+abs(dv4.x);

if( z > 1.0 )
{
du4.r/=z;
dv4.r/=z;
}

float dw = sqrt(1.0-du4.r*du4.r - dv4.r*dv4.r);

vec3 normal=vec3(du4.x*0.5+0.5,dv4.x*0.5+0.5,dw);

return normal;

}

PARTNERS