Terrain Texturing using Position, Color, Normal, and TEXTURE???

Started by
13 comments, last by vagos21 16 years, 9 months ago
Quote:Original post by ET3D
You wouldn't normally use both colour and normal attributes. When a normal is used, the lighting (either fixed function or shader based) calculates a colour based on the light colour and object colour. This results in a diffuse (and potentially specular) colour, which is a direct replacement to specifying the colour in the vertex.


If you do want to use the per-vertex colour as the object colour, you'd have to write a shader that calculates the resulting colour from that.

The fixed function pipeline can replace material colors with vertex colors too. You are right that this is not the default configuration and I had should remember this.

@AtomicWedgie: If your colors are all the same you should set the Device.Material property. If this is not the case you have to set RenderStateManager.DiffuseMaterialSource to ColorSource.Color1.


Advertisement
The terrain vertex colors can vary depending on height. I tried the following, but all that I am seeing is the texture - still no color.

I am curious if anyone has had any luck with the fixed function pipeline with a custom vertex declaration? It seems like support is extremely limited? I guess that is the reason for HLSL?

this.Game.DisplayDevice.RenderState.ColorVertex = true;this.Game.DisplayDevice.RenderState.DiffuseMaterialSource = ColorSource.Color1;   
Does lighting work for you without a per-vertex colour? If you haven't tried that, I think that'd be an easier place to start.

If lighting does work for you, and only lighting with per-vertex colour doesn't, you might want to try reordering the vertex components in a way compatible with FVFs: position, normal, colour, texture coords.
Lighting works as expected with a texture and without a per-vertex color. I have tried tweaking the ordering of the vertex declaration and have not had much luck.

I found a good tutorial on Terrain texturing using HLSL here. I am going to give a try.

Hello there,

i'm new to this forum but i hope i can help you with what u're asking. I'm working with managed direct X and just managed to do this a week ago. I'm using VB.net but i guess u can easily interpret it to C#.

1. First i declare a structure:


Public Structure PositionNormalTexVertex
Public Position As Vector3
Public Normal As Vector3
Public Diffuse As Integer
Public Tu0, Tv0 As Single
Public Shared ReadOnly FVF As VertexFormats = VertexFormats.Position Or VertexFormats.Normal Or VertexFormats.Diffuse Or VertexFormats.Texture1
End Structure


you can play with the FVF to set the combination of vertex format you wish.


2. then i make another structure called primitive, which holds the vertex and index buffer of the geometry i want to build:

Public Structure PRIMITIVE
Dim numVerts As Integer
Dim numInds As Integer
Dim VertexBuffer As VertexBuffer
Dim IndexBuffer As IndexBuffer
End Structure


3. Declaring an instance of a primitive...:


Public PRIMITIVE(0) As PRIMITIVE


4. and set the vertex buffer of the instance as the FVF structure format

PRIMITIVE(0).VertexBuffer = New VertexBuffer(GetType(PositionNormalTexVertex), PRIMITIVE(0).numVerts, d3deng.device, 0, VertexFormats.Position, Pool.Managed)

5. after filling the vertex buffer with the data u wish, u can render it (my texture here uses alpha channel for transparency too):


device.SetTexture(0, TEXTURE)
device.RenderState.SourceBlend = Blend.SourceAlpha
device.RenderState.DestinationBlend = Blend.InvSourceAlpha

device.SetStreamSource(0, main.PRIMITIVE(0).VertexBuffer, 0)
device.Indices = main.PRIMITIVE(0).IndexBuffer
device.VertexFormat = PositionNormalTexVertex.FVF
device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, main.PRIMITIVE(0).numVerts, 0, main.PRIMITIVE(0).numInds - 2)



i hope this helps!!!

vangelis

This topic is closed to new replies.

Advertisement