Re: Lights and Alpha
- From: "Saulo Machado" <SauloMachado@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Sep 2005 13:44:01 -0700
You're unlocking your vertexBuffer without even locking it? Try changing your
code for the vertexBuffer creation this way:
////////////////////////// CREATE THE VERTEXT BUFFER
vertexBuffer = new
VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, dev,
Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default);
(...) - Vertex creation code
vb.SetData(verts,0,LockFlags.None);
/////////////////////////////////////////////////////////////////
And, before setting up lights, turn it on:
mDevice.RenderState.Lighting = true;
To see if your normal is working, set this RenderState:
mDevice.RenderState.CullMode = Cull.None;
Then you can try the Normal coordinates. I suggest you should set the
normals coordinates to point at z+ direction - (0,0,1).
"Iain" wrote:
> On Mon, 19 Sep 2005 15:22:01 -0700, Saulo Machado wrote:
>
> > Assuming you created your quad without using lights you must not have created
> > ?Vertices with "Normals". It's impossible to have lighting in DirectX without
> > normals in your vertices. If you want lights... go there where you created
> > yur vertices and vertexBuffer and add normals.
> >
> Thanks.
>
> I've done that and it has made no difference.
>
> ////////////////////////// CREATE THE VERTEXT BUFFER
> vertexBuffer =new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, dev,
Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format,
Pool.Default);
>
> CustomVertex.PositionNormalTextured[] verts =
> (CustomVertex.PositionNormalTextured[])vertexBuffer.Lock(0, 0);
> verts[0].Position = new Vector3(-1, -1, 0);
> verts[1].Position = new Vector3(-1, 1, 0);
> verts[2].Position = new Vector3(1, -1, 0);
> verts[3].Position = new Vector3(1, 1, 0);
>
> verts[0].Normal = new Vector3(0, 0, -1);
> verts[1].Normal = new Vector3(0, 0, -1);
> verts[2].Normal = new Vector3(0, 0, -1);
> verts[3].Normal = new Vector3(0, 0, -1);
>
> verts[0].Tu = 0; verts[0].Tv = 1;
> verts[1].Tu = 0; verts[1].Tv = 0;
> verts[2].Tu = 1; verts[2].Tv = 1;
> verts[3].Tu = 1; verts[3].Tv = 0;
> vertexBuffer.Unlock();
>
> /////////////////////////////// SET UP LIGHTS
> mDevice.Lights[0].Type = LightType.Directional;
> mDevice.Lights[0].Diffuse = Color.White;
> mDevice.Lights[0].Direction = new Vector3(0, 1, 1);
> mDevice.Lights[0].Enabled = true;
>
>
> ////////////////////////////////// DRAW
> mDevice.RenderState.Lighting = true;
> mDevice.RenderState.AlphaBlendEnable = true;
> mDevice.RenderState.Ambient = Color.White;
> mDevice.RenderState.SourceBlend = Blend.SourceAlpha;
> mDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;
> mDevice.RenderState.CullMode = Cull.None;
> mDevice.SetTexture(0, texture);
> mDevice.RenderState.ZBufferEnable = true;
> mDevice.SetStreamSource(0, vertexBuffer, 0);
> mDevice.VertexFormat = CustomVertex.PositionNormalTextured.Format;
> mDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
>
>
> (I have tried various orientations of the normals and lighting direction in
> case my cartesian head is on backwards - still no display when lighting is
> turned on!)
>
> Any suggestions gratefully received!
>
>
>
> Iain
> --
> Iain Downs (DirectShow MVP)
> Commercial Software Therapist
> www.idcl.co.uk
>
.
- Follow-Ups:
- Re: Lights and Alpha
- From: zxeltor
- Re: Lights and Alpha
- References:
- Lights and Alpha
- From: Iain
- Re: Lights and Alpha
- From: Iain
- Lights and Alpha
- Prev by Date: Full Screen and not
- Next by Date: Re: Lights and Alpha
- Previous by thread: Re: Lights and Alpha
- Next by thread: Re: Lights and Alpha
- Index(es):
Relevant Pages
|