Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 09 December 2010 - 10:02 PM
Posted 10 December 2010 - 03:49 AM
Posted 10 December 2010 - 03:18 PM
Quote:
Original post by Pragma
If you know the forward transformation, then there are two ways to proceed:
1. Get out a pen and paper, and calculate the inverse transformation. This doesn't look like it will be too difficult, since it's just made up of rotation, scaling, log and exp which are all easily invertible. Then you can do the whole effect in a pixel shader.
Hope that is helpful. Looks like a cool effect, now I'm tempted to try it ...
vec2 complexExp(in vec2 z){
return vec2(exp(z.x)*cos(z.y),exp(z.x)*sin(z.y));
}
vec2 complexLog(in vec2 z){
return vec2(log(length(z)), atan(z.y, z.x));
}
vec2 complexMult(in vec2 a,in vec2 b){
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
}
vec4 droste(in vec2 co){
vec2 z = (co-0.5)*2.0;
z = complexExp(z);
z = complexMult(z,vec2(1.0,1.0));
z = complexLog(z);
z = z*0.5+0.5;
vec4 final = texture2D(Texture0,fract(z));
return final;
}
Posted 11 December 2010 - 02:10 AM
Posted 11 December 2010 - 04:02 PM
Posted 12 December 2010 - 01:21 AM
const float TWO_PI = 3.141592*2.0;
//ADJUSTABLE PARAMETERS:
const float branches = 1.0;
const float scale = 0.25;
const float speed = 2.0;
//Complex Math:
vec2 complexExp(in vec2 z){
return vec2(exp(z.x)*cos(z.y),exp(z.x)*sin(z.y));
}
vec2 complexLog(in vec2 z){
return vec2(log(length(z)), atan(z.y, z.x));
}
vec2 complexMult(in vec2 a,in vec2 b){
return vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
}
float complexMag(in vec2 z){
return float(pow(length(z), 2.0));
}
vec2 complexReciprocal(in vec2 z){
return vec2(z.x / complexMag(z), -z.y / complexMag(z));
}
vec2 complexDiv(in vec2 a,in vec2 b){
return complexMult(a, complexReciprocal(b));
}
vec2 complexPower(in vec2 a, in vec2 b){
return complexExp( complexMult(b,complexLog(a)) );
}
//Misc Functions:
float nearestPower(in float a, in float base){
return pow(base, ceil( log(abs(a))/log(base) )-1.0 );
}
float map(float value, float istart, float istop, float ostart, float ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
vec4 droste(in vec2 co){
//SHIFT AND SCALE COORDINATES TO <-1,1>
vec2 z = (co-0.5)*2.0;
//ESCHER GRID TRANSFORM:
float factor = pow(1.0/scale,branches);
z = complexPower(z, complexDiv(vec2( log(factor) ,TWO_PI), vec2(0.0,TWO_PI) ) );
//RECTANGULAR DROSTE EFFECT:
z *= 1.0+fract(time*speed)*(scale-1.0);
float npower = max(nearestPower(z.x,scale),nearestPower(z.y,scale));
z.x = map(z.x,-npower,npower,-1.0,1.0);
z.y = map(z.y,-npower,npower,-1.0,1.0);
//UNDO SHIFT AND SCALE:
z = z*0.5+0.5;
return texture2D(Texture0,z);
}
Posted 08 November 2011 - 12:05 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.