tessellation-factor is now adaptive
- tessellation gets reduced in distance - tess-factor is now adaptive
This commit is contained in:
parent
f7cc34b3a0
commit
376375008c
@ -10,6 +10,9 @@ out vec4 tcColor[];
|
|||||||
out vec3 tcNormal[];
|
out vec3 tcNormal[];
|
||||||
uniform float TessLevelInner = 1.0; // controlled by keyboard buttons
|
uniform float TessLevelInner = 1.0; // controlled by keyboard buttons
|
||||||
uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons
|
uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons
|
||||||
|
uniform mat4 ProjectionMatrix;
|
||||||
|
uniform mat4 ViewMatrix;
|
||||||
|
uniform mat3 NormalMatrix;
|
||||||
|
|
||||||
#define ID gl_InvocationID
|
#define ID gl_InvocationID
|
||||||
|
|
||||||
@ -18,10 +21,28 @@ void main()
|
|||||||
tcPosition[ID] = vPosition[ID];
|
tcPosition[ID] = vPosition[ID];
|
||||||
tcColor[ID] = vColor[ID];
|
tcColor[ID] = vColor[ID];
|
||||||
tcNormal[ID] = vNormal[ID];
|
tcNormal[ID] = vNormal[ID];
|
||||||
|
float dist = (ProjectionMatrix * ViewMatrix * vec4(vPosition[ID], 1)).z;
|
||||||
if (ID == 0) {
|
if (ID == 0) {
|
||||||
gl_TessLevelInner[0] = TessLevelInner;
|
if (dist < 30) {
|
||||||
gl_TessLevelOuter[0] = TessLevelOuter;
|
gl_TessLevelInner[0] = TessLevelInner;
|
||||||
gl_TessLevelOuter[1] = TessLevelOuter;
|
gl_TessLevelOuter[0] = TessLevelOuter;
|
||||||
gl_TessLevelOuter[2] = TessLevelOuter;
|
gl_TessLevelOuter[1] = TessLevelOuter;
|
||||||
|
gl_TessLevelOuter[2] = TessLevelOuter;
|
||||||
|
} else if (dist < 50) {
|
||||||
|
gl_TessLevelInner[0] = max(TessLevelInner-1.0,1.0);
|
||||||
|
gl_TessLevelOuter[0] = max(TessLevelOuter-1.0,1.0);
|
||||||
|
gl_TessLevelOuter[1] = max(TessLevelOuter-1.0,1.0);
|
||||||
|
gl_TessLevelOuter[2] = max(TessLevelOuter-1.0,1.0);
|
||||||
|
} else if (dist < 100) {
|
||||||
|
gl_TessLevelInner[0] = max(TessLevelInner-2.0,1.0);
|
||||||
|
gl_TessLevelOuter[0] = max(TessLevelOuter-2.0,1.0);
|
||||||
|
gl_TessLevelOuter[1] = max(TessLevelOuter-2.0,1.0);
|
||||||
|
gl_TessLevelOuter[2] = max(TessLevelOuter-2.0,1.0);
|
||||||
|
} else {
|
||||||
|
gl_TessLevelInner[0] = 1.0;
|
||||||
|
gl_TessLevelOuter[0] = 1.0;
|
||||||
|
gl_TessLevelOuter[1] = 1.0;
|
||||||
|
gl_TessLevelOuter[2] = 1.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
12
src/Main.hs
12
src/Main.hs
@ -132,6 +132,7 @@ main =
|
|||||||
}
|
}
|
||||||
, _io = IOState
|
, _io = IOState
|
||||||
{ _clock = now
|
{ _clock = now
|
||||||
|
, _tessClockFactor = 0
|
||||||
}
|
}
|
||||||
, _mouse = MouseState
|
, _mouse = MouseState
|
||||||
{ _isDown = False
|
{ _isDown = False
|
||||||
@ -234,23 +235,24 @@ run = do
|
|||||||
targetFrametime = 1.0/targetFramerate
|
targetFrametime = 1.0/targetFramerate
|
||||||
targetFrametimeμs = targetFrametime * 1000000.0
|
targetFrametimeμs = targetFrametime * 1000000.0
|
||||||
now <- getCurrentTime
|
now <- getCurrentTime
|
||||||
diff <- return $ diffUTCTime now (state ^. io.clock) -- get time-diffs
|
let diff = diffUTCTime now (state ^. io.clock) -- get time-diffs
|
||||||
title <- return $ unwords ["Pioneers @ ",show ((round . double $ 1.0/diff)::Int),"fps"]
|
title = unwords ["Pioneers @ ",show ((round . double $ 1.0/diff)::Int),"fps"]
|
||||||
setWindowTitle (env ^. windowObject) title
|
setWindowTitle (env ^. windowObject) title
|
||||||
let sleepAmount = floor ((targetFrametime - double diff)*1000000) :: Int -- get time until next frame in microseconds
|
let sleepAmount = floor ((targetFrametime - double diff)*1000000) :: Int -- get time until next frame in microseconds
|
||||||
|
clockFactor = (state ^. io.tessClockFactor)
|
||||||
tessChange
|
tessChange
|
||||||
| (sleepAmount > (floor $0.1*targetFrametimeμs)) && (state ^. gl.glMap.stateTessellationFactor < 5) = ((+)1 :: Int -> Int)
|
| (clockFactor > (2*targetFrametimeμs)) && (state ^. gl.glMap.stateTessellationFactor < 5) = ((+)1 :: Int -> Int)
|
||||||
-- > factor < 5 & 10% of frame idle -> increase graphics
|
-- > factor < 5 & 10% of frame idle -> increase graphics
|
||||||
| sleepAmount < 0 && (state ^. gl.glMap.stateTessellationFactor > 1) = (flip (-) 1 :: Int -> Int)
|
| sleepAmount < 0 && (state ^. gl.glMap.stateTessellationFactor > 1) = (flip (-) 1 :: Int -> Int)
|
||||||
-- frame used up completely -> decrease
|
-- frame used up completely -> decrease
|
||||||
| otherwise = ((+)0 :: Int -> Int) -- 0ms > x > 10% -> keep settings
|
| otherwise = ((+)0 :: Int -> Int) -- 0ms > x > 10% -> keep settings
|
||||||
when (sleepAmount > 0) $ threadDelay sleepAmount
|
when (sleepAmount > 0) $ threadDelay sleepAmount
|
||||||
print targetFrametimeμs
|
|
||||||
return (now,tessChange,sleepAmount)
|
return (now,tessChange,sleepAmount)
|
||||||
-- set state with new clock-time
|
-- set state with new clock-time
|
||||||
modify $ (io.clock .~ mt)
|
modify $ (io.clock .~ mt)
|
||||||
. (gl.glMap.stateTessellationFactor %~ tc)
|
. (gl.glMap.stateTessellationFactor %~ tc)
|
||||||
liftIO $ putStrLn $ concat $ ["TessFactor at: ",show (state ^. gl.glMap.stateTessellationFactor), " - slept for ",show sleepAmount, "μs."]
|
. (io.tessClockFactor %~ (((+) (fromIntegral sleepAmount)).((*) 0.99)))
|
||||||
|
-- liftIO $ putStrLn $ concat $ ["TessFactor at: ",show (state ^. gl.glMap.stateTessellationFactor), " - slept for ",show sleepAmount, "μs."]
|
||||||
shouldClose' <- return $ state ^. window.shouldClose
|
shouldClose' <- return $ state ^. window.shouldClose
|
||||||
unless shouldClose' run
|
unless shouldClose' run
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ data CameraState = CameraState
|
|||||||
|
|
||||||
data IOState = IOState
|
data IOState = IOState
|
||||||
{ _clock :: !UTCTime
|
{ _clock :: !UTCTime
|
||||||
|
, _tessClockFactor :: !Double
|
||||||
}
|
}
|
||||||
|
|
||||||
data GameState = GameState
|
data GameState = GameState
|
||||||
|
Loading…
Reference in New Issue
Block a user