Sorry to resurrect this, but I'm getting tantalizingly close to solving this now, but just cant figure out how to proceed.
So, what I've done:
Used calunetree to generate tree meshes
replaced the billboard leaves with my own mesh generation code and a billboard shader that renders the leaves as billboards, but as part of the mesh instead.
added an empty pass 0 into the leaf material, so that the billboard vertex program is loaded into the second pass, which theoretically should allow pagedGeometry to load its shader into the first pass without affecting things.
results:
imposters render correctly, nice billboarded leaves.
Unfortunately when you get close to a tree, the leaves fade out.
Heres my material file, and the billboard shader in case anyone can help!
billboardleaves.material:
vertex_program billBoardLeaves_vp cg
{
source leafboards.cg
entry_point billVertShader
profiles vs_2_0 arbvp1
default_params
{
param_named_auto wvp worldviewproj_matrix
param_named_auto viewUp view_up_vector
param_named_auto viewSide view_side_vector
param_named_auto lightPosition light_position_object_space 0
param_named_auto lightDiffuse light_diffuse_colour 0
param_named BillboardHeight float 3.0
param_named BillboardWidth float 3.0
}
}
fragment_program billBoardLeaves_fp cg
{
source leafboards.cg
entry_point billPixShader
profiles ps_2_0 arbfp1
}
material leavesBillBoards
{
technique
{
pass
{
cull_hardware none
cull_software none
scene_blend alpha_blend
}
pass
{
cull_hardware none
cull_software none
scene_blend alpha_blend
alpha_rejection greater 128
vertex_program_ref billBoardLeaves_vp
{
}
fragment_program_ref billBoardLeaves_fp
{
}
texture_unit leaf
{
texture tree_bush.png
}
}
}
}
leafboards.cg:
void billVertShader(
float3 Position : POSITION0,
float3 Normal : NORMAL0,
float2 TexCoord : TEXCOORD0,
uniform float4x4 wvp,
uniform float3 viewUp,
uniform float3 viewSide,
uniform float4 lightPosition,
uniform float4 lightDiffuse,
uniform float BillboardHeight,
uniform float BillboardWidth,
out float4 oPos : POSITION,
out float2 oTexCoord : TEXCOORD0,
out float4 oColor : COLOR0)
{
float width = BillboardWidth;
float height = BillboardHeight;
float3 position = Position;
position += viewSide * (TexCoord.x - 0.5) * BillboardWidth;
position += viewUp * (1 - TexCoord.y) * BillboardHeight;
float4 vPos = float4(position, 1);
oPos = mul(wvp, vPos);
oTexCoord = TexCoord;
float diffuseLight = max(-dot(Normal, lightPosition), 0);
oColor.rgb = diffuseLight * lightDiffuse + 0.5;
oColor.a = 1;
}
void billPixShader(float2 texCoord : TEXCOORD0,
float4 color : COLOR0,
uniform sampler2D TextureSampler,
out float4 oCol: COLOR)
{
float4 col = tex2D(TextureSampler, texCoord);
oCol = col * color;
}
so, as you can see the first pass is empty, ready to be modified by pagedGeometry, but sadly this still doesn't work.
If theres no way to work around this, can I humbly make a feature request for a future version
?
With a view to aiding that feature request - heres the code I use to create the leaf geometry (its in python, but is almost identical to what you'd do in c++ i think. The manObj passed into this function is the result of the calunetree trunk generation) -
def createLeaves(self, manObj=None):
nl = 0
lVerts = []
lNormals = []
lUVs = []
lTriangles = []
if not manObj:
leafObj = self.sceneManager.createManualObject("leaves_mesh")
else:
leafObj = manObj
leafObj.begin("leavesBillBoards")
centre = ogre.Vector3(0.0, 1.0, 1.0)
uvs = [ [0.0, 0.0], [1.0, 1.0], [0.0, 1.0], [1.0, 0.0] ]
leafRadius = 4.0
for i in range(46):
x = random.uniform(-leafRadius, leafRadius)
y = random.uniform(-leafRadius, leafRadius)
z = random.uniform(-leafRadius, leafRadius)
vPos = [x, y+6, z]
triA = [nl, nl+2, nl+3]
triB = [nl+1, nl+2, nl+3]
norm = centre - ogre.Vector3(vPos)
norm.normalise()
for i in range(4):
leafObj.position( vPos )
leafObj.normal( norm )
leafObj.textureCoord( uvs[i] )
leafObj.triangle( *triA )
leafObj.triangle( *triB )
nl += 4
leafObj.end()
return leafObj
thanks and sorry for the biblical sized post,