Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Normalize Vertices in VertexShader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 montify   Members   -  Reputation: 395

Like
0Likes
Like

Posted 12 April 2014 - 04:21 AM

Hello

 

 

With my old VertexShader i normalize and Scale each Vertex in VertexShader like:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

	
	float3 worldPosition = mul(input.Position, World).xyz;


		float3 normalized = normalize(worldPosition);
		float4 scaled = float4(normalized * SeaLevel, 1);

		output.Position = mul(mul(scaled, View), Projection);

		output.UV = input.UV;

    return output;
}

So, to Multiply the World, View, Projection Matrix on CPU in have a new VertexShader:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

	
	output.Position = mul(input.Position, worldViewProj);

    return output;
}

My question is, how can i normalize each Vertex in the new Shader? 

 

 

This is for my Planet, so i have a Cube, and the center of the Cube is Origin(0,0,0). 

 

 



Sponsor:

#2 cozzie   Members   -  Reputation: 3264

Like
0Likes
Like

Posted 12 April 2014 - 07:36 AM

Hi.

I'm not sure if I understand correct. The 2nd vertex shader only transforms the modelspace vertex into viewspace (and all transformations in between).

If you still want to scale the source vertex, you need to keep some of the old vertex shader.

 

For example:

(I've assumed SeaLevel is an extern constant)

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
	VertexShaderOutput output;

	float3 worldPosition = normalize(mul(input.Position, World).xyz);
	float4 scaled = float4(worldPosition * SeaLevel, 1);

	output.Position = mul(scaled, worldViewProj);
	output.UV = input.UV;

	return output;
}

Not sure though why you have to normalize the worldposition, before scaling.

The result might be that all vertices are now 'quite close together'. Maybe you can save the nonscaled position, determine scale, then scale the position (and multiply by worldViewProj).


Crealysm game & engine development: http://www.crealysm.com
My games: http://www.crealysm.com/games

Looking for a passionate, disciplined and structured producer? PM me

#3 Jason Z   Crossbones+   -  Reputation: 6108

Like
0Likes
Like

Posted 12 April 2014 - 08:10 AM

If you need multiple copies of your position, just make an extra copy and multiply it accordingly.  Unfortunately I can't really follow what you are trying to do - can you describe it with a little more detail what you are trying to do?  Most likely if you describe how this geometry appears in a scene then it could be helpful.



#4 montify   Members   -  Reputation: 395

Like
0Likes
Like

Posted 12 April 2014 - 08:49 AM

Thank you for replay...

 

So i have a QuadTree ( Chunked LOD)  like here:

 

http://www.gamedev.net/topic/621554-imprecision-problem-on-planet/

 

 

I scale and normalize each Vertex in the VertexShader, the advantage is, i can work with a cube on cpu side.

1 VertexBuffer for each Child/Patch.

every Patch has a own worldmatrix, i can calculate each Position of the Patch.

 

So to create a Sphere i use "Cube2Sphere" mapping, that mean the center of the "cube" should 0,0,0 (in WorldSpace)  to normalize each Vertex to get a Sphere. 

 

But when you open the Link you see my problem -> float Precision.

 

 

I read, i should calculate the World,View, Projection Matrix on CPU side with doubles.

 

 

The result is i have one Matrix ( worldViewProjection ) and here my Question start.

 

 

I found to render "Relative to the GPU" 

 

http://www.amazon.de/3D-Engine-Design-Virtual-Globes/dp/1568817118/ref=sr_1_1?ie=UTF8&qid=1397314306&sr=8-1&keywords=openglobe

https://github.com/virtualglobebook/OpenGlobe/tree/master/Source/Examples/Chapter05/Jitter/GPURelativeToEyeDSFUN90

 

 

It's in OpenGL, and he also use WordlViewProj Matrix instead of 3 single Matrix.


Edited by montify, 12 April 2014 - 09:34 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS