- Create
a new partially transparent Effect
- In
other words, an Entity with a Material using this Effect should be
visible, but you should be able to also see objects behind it. (Something
like a window or a glass ball, for example.)
- BLENDOP
is ADD
- SRCBLEND
is SRCALPHA
- DESTBLEND
is INVSRCALPHA
- How transparent the object is should be determined by a uniform float parameter between 1 (fully opaque) and 0 (completely transparent). This way different materials can be more or less transparent and still use the same Effect.
- Create
a new Effect that uses binary alpha
- In
other words, every fragment that the Effect outputs should either be
completely opaque or completely transparent.
- Choose
a threshold value between 0 and 1
- You
can use the HLSL clip() function to discard the fragment if it is less
than the threshold value:
- clip(
alpha - threshold );
- (clip(x)
will discard the fragment if x is less than 0)
- After
calling clip() you should probably set the alpha value to 1
- Create
a new Effect that is additive
- Whatever
color the fragment shader outputs should be added to what is already
stored in the image's corresponding pixel
- BLENDOP
is ADD
- SRCBLEND
is ONE
- DESTBLEND
is ONE
- Your
scene must have at least one Entity that uses a binary alpha Material
- For
this to be effective it must get its alpha from a texture
- Your
scene must have at least one Entity that uses an additive Material
- Your
scene must have at least three Entities that use a
partially transparent Material, and those Entities must have
some overlap on screen to prove that they are sorted correctly
back-to-front
- In
other words, when I start your program there should be one partially
transparent object closest to the camera, and then I must be able to see
another partially transparent object through the closest one, and then I
should be able to see another partially transparent
object through both of them
- I
should be able to change the order that these partially transparent
Entities are declared in your Scene file and the sorting should still
work correctly
- You
must separate the Entities that get drawn into two different
"buckets":
- Opaque
- This
should contain every Entity that is drawn with materials that have
either no alpha or binary alpha
- (In
other words, the result of any fragments drawn in this bucket only depend
on the current fragment shader; whatever value the pixel had before
will have no influence on the current value)
- This
bucket must use the same sorting algorithm you created for Assignment
05/06 (Effect->Material->Entity)
- Alpha
blending must not be enabled while this bucket is
drawing
- Translucent
- This
should contain every Entity that is drawn with materials where ALPHABLENDENABLE
is true
- (In
other words, the result of each fragment drawn in this bucket depends
not only on the current fragment shader, but also on whatever previous
value the pixel had)
- The
Entities in this bucket must be sorted back-to-front
based on the distance from the camera
- The
sorting should be done on a per-Entity basis
- You
can use the squared distance from the Entity to the camera to sort,
since it is cheaper than computing the actual distance: x^2 + y^2 +
z^2
- You
don't need to do any secondary sorting besides distance (the chances of
two objects being the same distance from the camera are pretty small)
- The
Opaque bucket must be drawn first, and the Translucent
bucket is drawn next
- You
must create new PIX events for each bucket
- All
of your events from Assignment 05/06 should now be under
"Opaque"
- All
of the new alpha blend Entities should be under "Translucent".
Since the Translucent draw calls are sorted by distance you won't need
any sub-events other than "Entity"
- Your
writeup must include two screenshots from PIX:
- One
where all I see are the collapsed buckets. So, it should look something
like this:
- Frame
- Clear
- BeginScene
- Opaque
- Translucent
- EndScene
- Present
- One
where the buckets are expanded
Details
Enabling Alpha
- You
will need to change Direct3D render states
- Look
up the documentation for IDirect3DDevice9::SetRenderState()
- Enable
alpha blending by setting ALPHABLENDENABLE to true
- Set
the other relevant render states (the source, destination, and operation)
based on what the current Effect specifies
- All
of the render states to set should be data-driven, and must come from your
Effect file.
- There
are two potential strategies for storing render states in a file
- You
may choose to actually store key/values that match the Direct3D states
exactly. Then when you switch to a new Effect you can just iterate
through them and set them as is
- If
you do this you need to make sure you have a good strategy to ensure
that you are always in a known state. You would probably need to store
an ALPHABLENDENABLE for every Effect, for example, and
have it set to either true or false, or else as soon as you set it to
true it would never get turned off again
- You
may choose to store the render states in your file in more of a
high-level representation, and make your renderer code smart enough to
know what to do
- For
example, you might just have a single "alpha" state, which
could be either "none", "blend", or "additive".
Then, the C++ renderer code would be responsible for knowing what states
to set for each of those.
- Note
that alpha blending should not be enabled for binary
alpha Effects, since we are handling it as part of the shader
Additive Materials
- Generally
you want a texture with a black background (since adding zero to anything
doesn't affect it), and then some sort of special effect that will be
added to the scene. I found this link with some free textures
that might give you some ideas (be sure to read and respect the license if
you use one)
Binary Alpha Textures
- Something
like a leaf works well for binary alpha. I found this link with some free textures
(be sure to read and respect the license if you use one)
No comments:
Post a Comment