Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


relaxok

Member Since 31 Jan 2010
Offline Last Active Jul 10 2014 05:24 PM

Topics I've Started

HLSL - Billboarding a mesh

22 January 2014 - 12:49 AM

Guys:

 

I have a vertex shader that I use for all my non-terrain models.  My per-mesh structure has a flags uint where i can set things like billboard, unlit, etc.  Some models have single meshes that need to be billboarded, like a light halo that looks the same from any angle.  However, I can't figure out how to successfully billboard the mesh.

 

Below is my vertex shader.. in the billboard section I've tried various combinations of matrices as you can see.. based on MJP's response in this topic:  

 

http://www.gamedev.net/topic/507808-hlsl-billboard/


PixelInputType VS(VertexInputType input, uint InstanceID : SV_InstanceID )
{	
	PixelInputType output;
    
	// Fix w
        input.position.w = 1.0f;

	// Calculate animation matrices
	matrix bonematrix = ( float( input.boneweight0 ) / 255.0f ) *  BoneMatrices[ input.boneindex0 ];
	bonematrix += ( float( input.boneweight1 ) / 255.0f ) *  BoneMatrices[ input.boneindex1 ];
	bonematrix += ( float( input.boneweight2 ) / 255.0f ) *  BoneMatrices[ input.boneindex2 ];
	bonematrix += ( float( input.boneweight3 ) / 255.0f ) *  BoneMatrices[ input.boneindex3 ];

	// World matrix from instance buffer
	matrix worldMatrixInstance = InstanceLocations[ InstanceID ];

	// Transform via combined bones + world matrix
	output.position = mul(input.position, bonematrix);
	output.position = mul(output.position, worldMatrixInstance );
	
	// Animate normal the same way
	output.normal = mul(input.normal, bonematrix);
	output.normal = mul(output.normal, worldMatrixInstance );

	// Camera view
        output.position = mul(output.position, viewMatrix);
	float4 cameraPosition = output.position;

	// vertex color
	output.vertex_color = input.vertex_color;

	// billboard?
	if( flags & PER_MESH_FLAG_BILLBOARD )
	{
		matrix boneWorldMat = mul( bonematrix, worldMatrixInstance );
		matrix boneWorldViewMat = mul( boneWorldMat, viewMatrix );
		//output.position = input.position + float4( boneWorldMat._41, boneWorldMat._42, boneWorldMat._43, 1.0f );
		output.position = input.position + float4( boneWorldViewMat._41, boneWorldViewMat._42, boneWorldViewMat._43, 1.0f );
		//output.position = input.position + float4( viewMatrix._41, viewMatrix._42, viewMatrix._43, 1.0f );
	}
		
	output.position = mul(output.position, projectionMatrix);
	 
	output.tex = input.tex;

	// Fog calc
	output.fogFactor = saturate((fogEnd - cameraPosition.z) / (fogEnd - fogStart));

	output.instance = InstanceID;
    
        return output;
}

I am using a y-up system, if it matters.

 

Please note there are no issues with the shader outside of the billboarding so please no recommendations on other things I can do differently.  I just want to know how to billboard within the context of what you see here.

 

Thanks..


Multiple draw calls unable to use different OMSetBlendState?

02 April 2012 - 02:02 AM

Hi!

I have a situation that boggles my mind. If i have two meshes, and i use OMSetBlendState before drawing each one (with DrawIndexed), both of them seem to be using whatever the most recent blend state that was set. EIther that, or the map/unmap of the lighting properties buffer is only using the most recent settings. Using PIX seems unreliable here but if it's not bugging out, it would seem to be the latter.

Basically, the first mesh is drawn with an alpha blending blend state, the second mesh is drawn with blending disabled (opaque). If i draw only the first mesh, it's correctly rendered - a plant texture with alpha blending around the branches. If i draw the second mesh after the first mesh, which disables alpha blending (for the 2nd mesh draw only), the first mesh that was working fine is also drawing opaquely.

Can anybody give me any ideas of things to try? OMSetBlendState should only be per draw call right?

I'm out of ideas... I'm not sure what other info would be relevant but feel free to ask..

Thanks

Do subsequent cbuffer fills affect previous draw calls?!

30 March 2012 - 02:45 AM

Hello!

I have a situation where when I am debugging with PIX:

-- i am drawing 4 meshes, each with different cbuffer values that i'm mapping inbetween

-- when i only draw the first mesh, it looks correct and the values in the cbuffer in PIX look right

-- when i enable drawing all 4 meshes in the loop, and go to that FIRST mesh's draw call, the cbuffer values are wrong as if they are getting values from cbuffer fills that happen AFTER that first draw call in time

how is this possible? Do I have to do anything during rendering or initialization to keep this from happening?

Thanks

How is it possible for the output register in a pixel shader to differ from PS output?

26 February 2012 - 09:53 PM

Basically, the topic title is the question... any ideas?

here's the proof:

Posted Image

Any way to get which index is being computed in a vertex shader?

25 February 2012 - 08:17 PM

Note: I am in D3D11, >=4.0 shaders

I've been reading this page today:

http://msdn.microsof...8(v=vs.85).aspx

It all seems very useful, however it's not quite what I need.

SV_VertexID refers to the actual value of the index in the index buffer you're iterating through, with say, DrawIndexed.

However, there doesn't seem to be a way to get the plain old 'which index am i on?' So when you're for example debugging in PIX and see a DrawIndexed call of 192k indices, there's no way inside the vertex shader to know if you're computing index 0 or 192k or 5 or 99, etc.

Does anybody know any way this is possible in HLSL? I'm kind of stunned it doesn't exist. There are many patterns where the value of the index could help you calculate something that would otherwise waste vertex format space.

Just to be super clear, I'm talking about getting the value of VTX rather than IDX in the below scenario:

Posted Image

Thanks.

PARTNERS