Skip to content

Commit 0969665

Browse files
committed
cleanup
1 parent 929f808 commit 0969665

File tree

1 file changed

+31
-49
lines changed

1 file changed

+31
-49
lines changed

GPipe-Test/src/Main.hs

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Graphics.Implicit.Primitives
1717
import Graphics.Implicit.Export
1818
import Graphics.Implicit.Export.DiscreteAproxable
1919
--import Graphics.Implicit.Export.Utils
20+
-- XXX: ^^ cleanupTris
2021

2122
import Data.VectorSpace (normalized, (^-^))
2223
import Data.Cross (cross3)
@@ -29,19 +30,16 @@ trim :: NormedTriangleMesh
2930
trim = cleanupTris . discreteAprox 1.5 $ obj
3031

3132
obj = autocenter $ union $ [
32-
rect3R 0 (0,0,0) (20,20,20) -- rect3R 10 15 12
33+
rect3R 0 (0,0,0) (20,20,20)
3334
, translate (20,20,20) (sphere 15)
3435
, translate (0,0,25) (rect3R 2 (0,0,0) (10,10,10))
35-
--, translate (0, 0, -30) heart
36+
--, translate (0, 0, -30) fun
3637
] ++
3738
[]
3839
--map (\x -> translate (0,0,20 + (10 - x) * 11) (rect3R 0 (0,0,0) (10 - x, 10 - x, 10 - x))) [0..9]
3940

40-
heart:: SymbolicObj3
41-
heart = implicit (\(x,y,z) -> x^4 + y^4 + z^4 - 15000) ((-20,-20,-20),(20,20,20))
42-
43-
-- , translate (0,0,35) (rect3R 2 (0,0,0) (2,2,2))
44-
-- cleanupTris $
41+
fun:: SymbolicObj3
42+
fun = implicit (\(x,y,z) -> x^4 + y^4 + z^4 - 15000) ((-20,-20,-20),(20,20,20))
4543

4644
ptri (NormedTriangleMesh ts) = mapM_ (\(NormedTriangle (a, b, c)) -> print (a, b, c) ) ts
4745

@@ -117,8 +115,10 @@ main = do
117115
(bbx, _, _) = bb
118116
-- ratio perserving scaling
119117
s = let m = bmax (bb - ba) in pack (m, m, m) -- ^* 1.0
118+
-- scale by x
120119
--s = V3 (bbx - bax) (bbx - bax) (bbx - bax)
121-
--s = pack $ ba - bb
120+
-- non-preserving scaling
121+
--s = pack $ bb - ba
122122

123123
print (ba, bb, s)
124124
--print $ rmp s trim
@@ -166,7 +166,6 @@ main = do
166166

167167
-- Create the shader
168168
shader <- compileShader $ do
169-
sides <- fmap makeSide <$> toPrimitiveStream primitives
170169
--tries <- toPrimitiveStream mytris
171170

172171
primitiveStream <- toPrimitiveStream mytris
@@ -177,10 +176,11 @@ main = do
177176

178177
let filterMode = SamplerFilter Linear Linear Linear (Just 4)
179178
edgeMode = (pure ClampToEdge, undefined)
180-
--projectedSides = proj modelViewProj normMat <$> sides
179+
181180
samp <- newSampler2D (const (tex, filterMode, edgeMode))
182181

183182
fragmentStream <- rasterize (const (FrontAndBack, ViewPort (V2 0 0) (V2 (1920 `div` 1) 1080), DepthRange 0 1)) projected -- primitiveStream
183+
-- colorful normals
184184
--drawWindowColor (const (win, ContextColorOption NoBlending (V3 True True True))) fragmentStream
185185

186186
let fragNormals = fragmentStream
@@ -192,30 +192,9 @@ main = do
192192
depthOption = DepthOption Less True
193193

194194
drawWindowColorDepth (const (win, colorOption, depthOption)) litFragsWithDepth
195-
--drawWindowColorDepth (const (win, colorOption, depthOption)) litFragsWithDepth
196195

197-
{--
198-
--}
199196
return ()
200197

201-
202-
{--
203-
(modelViewProj, normMat) <- getUniform (const (uniform, 0))
204-
let filterMode = SamplerFilter Linear Linear Linear (Just 4)
205-
edgeMode = (pure ClampToEdge, undefined)
206-
projectedSides = proj modelViewProj normMat <$> sides
207-
samp <- newSampler2D (const (tex, filterMode, edgeMode))
208-
209-
fragNormalsUV <- rasterize rasterOptions projectedSides
210-
let litFrags = light samp <$> fragNormalsUV
211-
litFragsWithDepth = withRasterizedInfo
212-
(\a x -> (a, getZ $ rasterizedFragCoord x)) litFrags
213-
colorOption = ContextColorOption NoBlending (pure True)
214-
depthOption = DepthOption Less True
215-
216-
drawWindowColorDepth (const (win, colorOption, depthOption)) litFragsWithDepth
217-
--}
218-
219198
-- Run the loop
220199
loop win shader makePrimitives tris uniform 0
221200

@@ -248,6 +227,7 @@ loop win shader makePrimitives tris uniform angleRot = do
248227
clearWindowColor win 0 -- Black
249228
clearWindowDepth win 1 -- Far plane
250229
prims <- makePrimitives
230+
251231
--vertexArray <- newVertexArray vertexBuffer
252232
--let primitiveArray = toPrimitiveArray TriangleList vertexArray
253233
vertexArray <- newVertexArray tris
@@ -270,38 +250,40 @@ getZ (V4 _ _ z _) = z -- Some day I'll learn to use lenses instead...
270250

271251
data ShaderEnvironment = ShaderEnvironment
272252
{ primitives :: PrimitiveArray Triangles (B2 Float, (B3 Float, B3 Float))
273-
-- , mytris :: PrimitiveArray Triangles (B3 Float) -- , B3 Float)
274253
, mytris :: PrimitiveArray Triangles (B3 Float, B3 Float)
275254
, rasterOptions :: (Side, ViewPort, DepthRange)
276255
}
277256

278-
-- Project the sides coordinates using the instance's normal and tangent
279-
makeSide (p@(V2 x y), (normal, tangent)) =
280-
(V3 x y 1 *! V3 tangent bitangent normal, normal, uv)
281-
where bitangent = cross normal tangent
282-
uv = (p + 1) / 2
283-
284-
-- Project the cube's positions and normals with ModelViewProjection matrix
285-
proj' modelViewProj normMat (V3 px py pz, normal, uv) =
286-
(modelViewProj !* V4 px py pz 1, (fmap Flat $ normMat !* normal, uv))
257+
proj modelViewProj normMat (V3 px py pz, normal) =
258+
(modelViewProj !* V4 px py pz 1, fmap Flat $ normMat !* normal)
287259

260+
light color normal =
261+
(V3 0 0.5 0) ^* (clamp (normal `dot` V3 0 1 1) 0 1)
262+
-- ^^ light color
288263

289-
proj modelViewProj normMat (V3 px py pz, normal) = -- V3 cx cy cz) = -- normal, uv) =
290-
(modelViewProj !* V4 px py pz 1, fmap Flat $ normMat !* normal) -- V3 cx cy cz) -- (fmap Flat $ normMat !* normal, uv))
264+
-- global ilum hack
265+
go color = color ^+^ 0.2 -- 0.1 ^+^ color ^+^ V3 0.2 0 0
291266

267+
-- eof
268+
--
269+
-- OLDstuff
270+
--
292271
-- Set color from sampler and apply directional light
293272
light'' samp normal =
294273
--sample2D samp SampleAuto Nothing Nothing $ pure (normal `dot` V3 0 0 1)
295274
pure (normal `dot` V3 0 0 1)
296275

297-
light color normal =
298-
(V3 0 0.5 0) ^* (clamp (normal `dot` V3 0 1 1) 0 1)
299-
-- ^^ light color
276+
-- Project the cube's positions and normals with ModelViewProjection matrix
277+
proj' modelViewProj normMat (V3 px py pz, normal, uv) =
278+
(modelViewProj !* V4 px py pz 1, (fmap Flat $ normMat !* normal, uv))
300279

301-
-- global hack
302-
go color = color ^+^ 0.2 -- 0.1 ^+^ color ^+^ V3 0.2 0 0
280+
-- Project the sides coordinates using the instance's normal and tangent
281+
makeSide (p@(V2 x y), (normal, tangent)) =
282+
(V3 x y 1 *! V3 tangent bitangent normal, normal, uv)
283+
where bitangent = cross normal tangent
284+
uv = (p + 1) / 2
303285

304286
light' samp (normal, uv) =
305287
sample2D samp SampleAuto Nothing Nothing uv * pure (normal `dot` V3 0 0 1)
306288

307-
-- eof
289+

0 commit comments

Comments
 (0)