Permalink
Browse files

pattern support for Q3 materials

  • Loading branch information...
csabahruska committed Jun 27, 2012
1 parent 385f8f4 commit e0000ae01e0a4f0d4190af7d4d78f45f7900f3b0
Showing with 25 additions and 8 deletions.
  1. +4 −1 hStunts/GameGraphics.hs
  2. +1 −0 lambdacube-core/LC_U_DeBruijn.hs
  3. +14 −3 q3demo/Graphics.hs
  4. +3 −3 q3demo/Main.hs
  5. +1 −0 q3demo/Material.hs
  6. +1 −0 q3demo/Render.hs
  7. +1 −1 q3demo/ShaderParser.hs
View
@@ -154,7 +154,10 @@ stuntsGFX = {-blurVH $ PrjFrameBuffer "blur" tix0 $ -}Accumulate fragCtx (Filter
shadowMap = Texture (Texture2D (Float RGBA) n1) (V2 512 512) NoMip [PrjFrameBuffer "shadowMap" tix0 moments]
shadowMapEnvelope :: Texture GP DIM2 SingleTex (Regular Float) RGBA
- shadowMapEnvelope = Texture (Texture2D (Float RGBA) n1) (V2 512 512) NoMip [PrjFrameBuffer "shadowMap" tix0 $ {- blurVH $ PrjFrameBuffer "blur" tix0 $ -} shadowEnvelope $ PrjFrameBuffer "envelope" tix0 moments]
+ shadowMapEnvelope = Texture (Texture2D (Float RGBA) n1) (V2 512 512) NoMip [PrjFrameBuffer "shadowMap" tix0 $ shadowEnvelope $ PrjFrameBuffer "envelope" tix0 moments]
+
+ shadowMapEnvelopeBlur :: Texture GP DIM2 SingleTex (Regular Float) RGBA
+ shadowMapEnvelopeBlur = Texture (Texture2D (Float RGBA) n1) (V2 512 512) NoMip [PrjFrameBuffer "shadowMap" tix0 $ blurVH $ PrjFrameBuffer "blur" tix0 $ shadowEnvelope $ PrjFrameBuffer "envelope" tix0 moments]
shadowMapBlur :: Texture GP DIM2 SingleTex (Regular Float) RGBA
shadowMapBlur = Texture (Texture2D (Float RGBA) n1) (V2 512 512) NoMip [PrjFrameBuffer "shadowMap" tix0 $ blurVH $ PrjFrameBuffer "blur" tix0 moments]
@@ -122,6 +122,7 @@ class ExpC exp where
lam :: exp -> exp
body :: exp -> exp
let_ :: Ty -> exp -> exp -> exp
+ --let_ :: Ty -> exp -> (exp -> exp) -> exp
var :: Ty -> Int -> TypeRep -> exp -- type, index, layout counter (this needed for proper sharing)
apply :: Ty -> exp -> exp -> exp
const_ :: Ty -> Value -> exp
View
@@ -11,6 +11,7 @@ import LC_API
import Material hiding (Blending)
+import Debug.Trace
-- specialized snoc
v3v4 :: Exp s V3F -> Exp s V4F
@@ -280,17 +281,27 @@ mkFragmentShader sa uvrgba = FragmentOutRastDepth $ color :. ZT
ST_AnimMap {} -> rgba @* texColor Wrap stageTexN
texColor em name = texture' sampler uv (Const 0)
where
- rgbaTex = texture' sampler uv (Const 0)
sampler = Sampler LinearFilter em $ TextureSlot name (Texture2D (Float RGBA) n1)
mkFilterFunction :: StageAttrs -> FragmentFilter (V2F,V4F)
mkFilterFunction sa = case saAlphaFunc sa of
Nothing -> PassAll
Just f -> Filter $ \uvrgba ->
let
+ V4 _ _ _ a = unpack' color
(uv,rgba) = untup2 uvrgba
- V4 _ _ _ a = unpack' rgba
- in case f of
+ stageTex = saTexture sa
+ stageTexN = SB.pack $ "Tex_" ++ show (crc32 $ SB.pack $ show stageTex)
+ color = case stageTex of
+ ST_WhiteImage -> rgba
+ ST_Lightmap -> rgba @* texColor Clamp "LightMap"
+ ST_Map {} -> rgba @* texColor Wrap stageTexN
+ ST_ClampMap {} -> rgba @* texColor Clamp stageTexN
+ ST_AnimMap {} -> rgba @* texColor Wrap stageTexN
+ texColor em name = texture' sampler uv (Const 0)
+ where
+ sampler = Sampler LinearFilter em $ TextureSlot name (Texture2D (Float RGBA) n1)
+ in case trace ("aplha filter: " ++ show f) f of
A_Gt0 -> a @> floatF 0
A_Lt128 -> a @< floatF 0.5
A_Ge128 -> a @>= floatF 0.5
View
@@ -74,19 +74,19 @@ main :: IO ()
main = do
ar <- loadArchive
- let imageShader txName = defaultCommonAttrs {caStages = sa:saLM:[]}
+ let imageShader txName = defaultCommonAttrs {caStages = saLM:sa:[]}
where
sa = defaultStageAttrs
{ saTexture = ST_Map txName
--, saBlend = Just (SrcColor,Zero)
- --, saBlend = Just (SrcColor,DstColor)
+ , saBlend = Just (B_SrcColor,B_One)
, saDepthWrite = True
}
saLM = defaultStageAttrs
{ saTexture = ST_Lightmap
, saTCGen = TG_Lightmap
--, saBlend = Just (SrcColor,One)
- , saBlend = Just (B_SrcColor,B_DstColor)
+ --, saBlend = Just (B_SrcColor,B_DstColor)
}
args <- getArgs
View
@@ -126,6 +126,7 @@ data AlphaFunction
= A_Gt0
| A_Lt128
| A_Ge128
+ deriving (Show, Eq, Ord)
data DepthFunction
= D_Equal
View
@@ -69,6 +69,7 @@ addObject' rndr name prim idx attrs unis = addObject rndr name' prim idx attrs'
Just (_,x) -> x
_ -> error $ "material not found: " ++ show name'
+addBSP :: Renderer -> BSPLevel -> IO (V.Vector Object)
addBSP renderer bsp = do
let alig = Just 4
View
@@ -291,7 +291,7 @@ tcMod = (\_ v sa -> sa {saTCMod = v:saTCMod sa}) <$> kw "tcmod" <*> (
depthFunc = (\_ v sa -> sa {saDepthFunc = v}) <$> kw "depthfunc" <*> (val D_Lequal "lequal" <|> val D_Equal "equal")
depthWrite = (\_ sa -> sa {saDepthWrite = True}) <$> kw "depthwrite"
detail = pass <$> kw "detail"
-alphaFunc = pass <$> kw "alphafunc" <* (kw "gt0" <|> kw "lt128" <|> kw "ge128")
+alphaFunc = (\_ v sa -> sa {saAlphaFunc = Just v}) <$> kw "alphafunc" <*> (val A_Gt0 "gt0" <|> val A_Lt128 "lt128" <|> val A_Ge128 "ge128")
--
-- Q3MAP Specific Shader Keywords

0 comments on commit e0000ae

Please sign in to comment.