6 Replies Latest reply on Dec 29, 2008 6:48 AM by johnAq

    Amateur needs help with film grain effect

    deancolt45
      Hey all,
      Doing a third year project designing a level of a game that is aiming to mirror a 1940's film noir movie (basically). I was wondering could anyone give me an idea on how I would apply a film grain effect overlay to the camera, to give the impression of noise or its old age (if that makes sense). Quite stuck with this and any help or idea's would be amazing. Thanks. The film grain obviously can't be a static transparency over the top. Cheers.
        • 1. Re: Amateur needs help with film grain effect
          Level 7
          The only way is swapping a 32-bit ovelay textures (with alpha) but in
          case of large frostrum it may be pretty slow...
          • 2. Re: Amateur needs help with film grain effect
            deancolt45 Level 1
            Cheers for the advice Ziggi, yeh that def does seem to be the only way to achieve what I need, i am not brilliant at lingo, so does anyone know how to alternate the images so that they create the illusion of noise, I have the following code in my setup camera as an overlay, how would i get them to come up randomly changing every second or so, I have just have two alpha images at the moment to test it, the images are named as "noise". Thanks any help would be brilliant!
            Existing Code

            on setup_camera


            G_world.camera(1).transform.position = G_PC.transform.position + vector(0,-0,60)

            G_world.camera(1).transform.rotation = vector(80,0,0)


            G_PC.addChild(member(1).camera(1))

            -----------------------------------------------------
            CODE FOR THE IMAGES--- Need to know how to alternate them in milliseconds


            t1 = member("librarymockupBW").newTexture("Rough", #fromCastMember,member("noise"))
            sprite(1).camera.addOverlay(t1, point(100,100), 0)

            t1 = member("librarymockupBW").newTexture("Rough2", #fromCastMember,member("noise2"))
            sprite(1).camera.addOverlay(t1, point(100,100), 0)


            end
            ------------------------------------------------

            • 3. Re: Amateur needs help with film grain effect
              Level 7
              Hi Man,

              Sorry - no time for writting code, though it will be easy.
              Just an advice - if you need performance it's better to swap overlay's
              texture than to swap overlay texture image.

              I mean - the bottleneck is sending data from main memory (accessible to
              CPU) to graphics card memory (available to GPU). While texture resides
              in graphics card memory, it's image resides in main memory, so:

              3D_member.texture("the_texture").image

              is slow, while:

              3D_member.camera("the_camera").overlay[the_index].source

              is fast

              Consequently - it is better to prepare dozen of textures in advance and
              swap overlay source than prepare dozen of images and swap the texture image.

              Good luck!,
              Ziggi
              • 4. Re: Amateur needs help with film grain effect
                James Newton, ACP Level 3
                Here's how I made an effect that looks a little like what you might be looking for:

                1) I created a new movie
                2) I added a 3D member and placed it on the stage (320 x 240)
                3) In Photoshop, I created an image with a noisy alpha channel (256 x 256)
                4) I imported this image into Director, and called it "Noise"
                5) I attached the following behavior to the 3D sprite

                • 5. Re: Amateur needs help with film grain effect
                  deancolt45 Level 1
                  Cheers for all the help guys, much appreciated and a very Merry Christmas to you all!!!! Still having a few issues, haven't been using lingo long and my syntax seems different in how I have learnt it, so I am unsure as to what handlers go where etc. would anyone be able to point me in the right direction of where to put the previous code from openspark. I just don't fully understand it all well enough and after trying for a couple of hours i realised i still need help. Here is an initial part of the script dealing with the basics, minus lighting, collision etc etc. Where would I put it within here and do i need to change existing handlers or add new ones? Sorry to be a nuisance with this....... THanks for your patience.

                  Global G_World, G_PC
                  Global G_move_rate, G_Rot_rate
                  Global G_ray_height



                  ----------------------------------------------------------------
                  ----------------- Initial Setup
                  ----------------------------------------------------------------


                  on startmovie

                  _movie.go(1) -- move the playback head to frame 1

                  -- reset the 3D world in cast member 1
                  member(1).resetworld()


                  Setup_World -- set the initial parameters
                  G_Shader = 0

                  end

                  on exitframe

                  _movie.go(_movie.frame) -- loop around the current frame

                  if keyPressed(123) then Rot_left
                  if keyPressed(124) then Rot_right
                  if keyPressed(126) then Move_Forward
                  if keyPressed(125) then Move_Back

                  check_ground
                  PC_Collision_Check



                  end


                  on Setup_world

                  --set the globals for the world an PC

                  G_World = Member(1)
                  G_PC = G_world.model("dean")


                  -- set the initial movement rates

                  G_move_rate = 20 -- walk rate
                  G_Rot_rate = 2 -- turn angle


                  G_ray_height = 90 -- the height for casting collision rays

                  setup_camera
                  ---Setup_lights

                  on setup_camera

                  --move the camera to the PC and offset it
                  G_world.camera(1).transform.position = G_PC.transform.position + vector(0,-0,60)

                  --adjust the viewing angle
                  G_world.camera(1).transform.rotation = vector(80,0,0)




                  -- attach the camera to the PC by making it a child object
                  G_PC.addChild(member(1).camera(1))




                  ---system milliseconds (look for example of davids last year)
                  --Grain overlay---------
                  -- t1 = member("Scene").newTexture("Rough", #fromCastMember,member("noise"))
                  -- sprite(1).camera.addOverlay(t1, point(100,100), 0) ------overlay noise
                  -------member("librarymockupBW").camera[1].addOverlay(t1, point(20, 20), 45)
                  -- t1 = member("Scene").newTexture("Rough2", #fromCastMember,member("noise2"))
                  -- sprite(1).camera.addOverlay(t1, point(100,100), 0)
                  ----note textures wrong size

                  end

                  on reset_PC

                  G_PC.transform.position = vector(-1000,100,100)

                  end


                  on move_Forward

                  G_PC.translate(0,G_move_rate,0)

                  end

                  on move_Back

                  G_PC.translate(0,-G_move_rate,0)

                  end


                  ---- Rotate-----

                  on Rot_Left

                  G_PC.rotate(0,0,G_Rot_rate)

                  end


                  on Rot_right

                  G_PC.rotate(0,0,-G_Rot_rate)

                  end

                  • 6. Re: Amateur needs help with film grain effect
                    johnAq Level 1
                    The code that James has written is a self-contained behavior script intended to do its thing independently of other scripts. Here is more info on his list of instructions

                    1) I created a new movie
                    >>Use your own movie

                    2) I added a 3D member and placed it on the stage (320 x 240)
                    >>Use your own 3d member

                    3) In Photoshop, I created an image with a noisy alpha channel (256 x 256)
                    >>This is a transparent image that will overlay over your 3D. It must have an alpha for transparency. Create it in Photoshop and save as NOISE.PNG.

                    4) I imported this image into Director, and called it "Noise"
                    >>The name of the imported member is important as the only thing the script relies on is finding in your cast a bitmap called 'Noise' (no quotes)

                    5) I attached the following behavior to the 3D sprite.
                    >>Create a new script member, paste in James' code. Under the 'Script' tab in the Property Inspector, make sure the Type is set to 'Behavior'. Close the script window and drag the script member from the cast window onto the 3D member in the score window. Play the movie

                    hth

                    johnAq