Implement translation rotation zoom using uniform buffers, improvement?
This commit is contained in:
+18
-2
@@ -10,10 +10,26 @@ uniform float zoom;
|
|||||||
uniform vec2 translation;
|
uniform vec2 translation;
|
||||||
uniform float rotation;
|
uniform float rotation;
|
||||||
|
|
||||||
|
vec2 tran(vec2 v)
|
||||||
|
{
|
||||||
|
return (v - translation);
|
||||||
|
}
|
||||||
|
vec2 rot(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( v.x * cos(-rotation) - v.y * sin(-rotation)
|
||||||
|
, v.x * sin(-rotation) + v.y * cos(-rotation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
vec2 scal(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( 2 * v.x * zoom / winSize.x
|
||||||
|
, 2 * v.y * zoom / winSize.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(position,1);
|
gl_Position = vec4(scal(rot(tran(position.xy))),position.z,1);
|
||||||
//gl_Position = vec4(0,0,0,1);
|
|
||||||
vColor = color;
|
vColor = color;
|
||||||
vparams = saEaRadWdth;
|
vparams = saEaRadWdth;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ in vec2 vWinSize [];
|
|||||||
out vec2 gTexPos;
|
out vec2 gTexPos;
|
||||||
|
|
||||||
uniform vec2 translation;
|
uniform vec2 translation;
|
||||||
|
uniform float zoom;
|
||||||
|
uniform float rotation;
|
||||||
|
|
||||||
vec2 rotBy( float rot, vec2 v)
|
vec2 rotBy( float rot, vec2 v)
|
||||||
{
|
{
|
||||||
@@ -18,8 +20,8 @@ vec2 rotBy( float rot, vec2 v)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 cPos = vec2(translation.x / 250 , translation.y /250 );
|
vec2 cPos = vec2(translation.x / 250 , translation.y /250 );
|
||||||
float zoom = vParams[0].w;
|
// float zoom = vParams[0].w;
|
||||||
float rot = 0 - vParams[0].z;
|
float rot = 0 - rotation;
|
||||||
|
|
||||||
float x = vWinSize[0].x / (500*zoom) ;
|
float x = vWinSize[0].x / (500*zoom) ;
|
||||||
float y = vWinSize[0].y / (500*zoom) ;
|
float y = vWinSize[0].y / (500*zoom) ;
|
||||||
|
|||||||
+18
-1
@@ -8,8 +8,25 @@ uniform float zoom;
|
|||||||
uniform float rotation;
|
uniform float rotation;
|
||||||
uniform vec2 translation;
|
uniform vec2 translation;
|
||||||
|
|
||||||
|
vec2 tran(vec2 v)
|
||||||
|
{
|
||||||
|
return (v - translation);
|
||||||
|
}
|
||||||
|
vec2 rot(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( v.x * cos(-rotation) - v.y * sin(-rotation)
|
||||||
|
, v.x * sin(-rotation) + v.y * cos(-rotation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
vec2 scal(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( 2 * v.x * zoom / winSize.x
|
||||||
|
, 2 * v.y * zoom / winSize.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(position,1);
|
gl_Position = vec4(scal(rot(tran(position.xy))),position.z,1);
|
||||||
vColor = color;
|
vColor = color;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-2
@@ -10,10 +10,25 @@ uniform float zoom;
|
|||||||
uniform vec2 translation;
|
uniform vec2 translation;
|
||||||
uniform float rotation;
|
uniform float rotation;
|
||||||
|
|
||||||
|
vec2 tran(vec2 v)
|
||||||
|
{
|
||||||
|
return (v - translation);
|
||||||
|
}
|
||||||
|
vec2 rot(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( v.x * cos(-rotation) - v.y * sin(-rotation)
|
||||||
|
, v.x * sin(-rotation) + v.y * cos(-rotation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
vec2 scal(vec2 v)
|
||||||
|
{
|
||||||
|
return vec2 ( 2 * v.x * zoom / winSize.x
|
||||||
|
, 2 * v.y * zoom / winSize.y
|
||||||
|
);
|
||||||
|
}
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(position,1);
|
gl_Position = vec4(scal(rot(tran(position.xy))),position.z,1);
|
||||||
//gl_Position = vec4(0,0,0,1);
|
|
||||||
vColor = color;
|
vColor = color;
|
||||||
vRad = rad;
|
vRad = rad;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ worldPictures w
|
|||||||
, smokeShadows
|
, smokeShadows
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
screenShift = scale zoomx zoomy . rotate (0 - (_cameraRot w) )
|
screenShift = id--scale zoomx zoomy . rotate (0 - (_cameraRot w) )
|
||||||
. uncurry translate ((0,0) -.- _cameraPos w)
|
-- . uncurry translate ((0,0) -.- _cameraPos w)
|
||||||
zoomx = 2 * _cameraZoom w / _windowX w
|
zoomx = 2 * _cameraZoom w / _windowX w
|
||||||
zoomy = 2 * _cameraZoom w / _windowY w
|
zoomy = 2 * _cameraZoom w / _windowY w
|
||||||
scaler = scale (2 / _windowX w) (2 / _windowY w)
|
scaler = scale (2 / _windowX w) (2 / _windowY w)
|
||||||
|
|||||||
+17
-3
@@ -358,13 +358,27 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p
|
|||||||
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
||||||
clear [DepthBuffer]
|
clear [DepthBuffer]
|
||||||
-- draw layer 0
|
-- draw layer 0
|
||||||
renderTree pdata rot zoom (tranx,trany) (winx,winy) (picToList 0 pic)
|
renderTree pdata rot zoom (tranx,trany) (winx,winy) (picToFTree 0 pic)
|
||||||
-- reset blend so that light map doesn't apply
|
-- reset blend so that light map doesn't apply
|
||||||
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
||||||
renderTree pdata rot zoom (tranx,trany) (winx,winy) $ picToList 1 pic
|
renderTree pdata rot zoom (tranx,trany) (winx,winy) $ picToFTree 1 pic
|
||||||
-- set drawing for on top
|
-- set drawing for on top
|
||||||
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
||||||
renderTree pdata rot zoom (tranx,trany) (winx,winy) $ picToList 2 pic
|
renderTree pdata rot zoom (tranx,trany) (winx,winy) $ picToFTree 2 pic
|
||||||
|
-- reset uniforms (hacky for now)
|
||||||
|
forM_ [_basicShader pdata
|
||||||
|
,_textShader pdata
|
||||||
|
,_circShader pdata
|
||||||
|
,_arcShader pdata
|
||||||
|
,_fadeCircleShader pdata
|
||||||
|
,_backShader pdata
|
||||||
|
,_wallShadowShader pdata
|
||||||
|
] $ \shad -> do
|
||||||
|
currentProgram $= Just (fst shad)
|
||||||
|
uniform (snd shad !! 0) $= Vector2 (2::Float) 2
|
||||||
|
uniform (snd shad !! 1) $= (1::Float)
|
||||||
|
uniform (snd shad !! 2) $= (0::Float)
|
||||||
|
uniform (snd shad !! 3) $= Vector2 (0::Float) 0
|
||||||
|
|
||||||
|
|
||||||
bufferOffset :: Integral a => a -> Ptr b
|
bufferOffset :: Integral a => a -> Ptr b
|
||||||
|
|||||||
Reference in New Issue
Block a user