Improving the demo render quality and performance

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 11:05 am

Now that we have skin, the demos are dominated by teh fact that the skinning is done in cpu and for a model with 12000 point is quite notizable if I try to render say 20 or 30.

It is no the skinning it is the fat that using user buffer that make slow sine it has to copy the same buffer over an over to teh GPU and make about a hundred time slower.

to fix that I am re enbling the shader, I al;ready have the basi scene rendering using shader, but I found a problem that at first I thous I was doing some wrong, but after testion I conclude that some does no seems right whn use a shader and the scene overall look darker.

I simply the shade to just draw the solid color lower that 1.0 and set it to 0.5
and is very dark wit the shder buy is brighte wi teh fix pipe. hwoever is I use 1.0 then teh scene is equally bright, it is as if the shader fragment by pass the Gamma correction.

I committed the test, in case anyone want to test.

what is commite render teh scen using teh shader. but if you go to file
...\demosSandbox\sdkDemos\DemoMesh.cpp and comment the first line that set the shader program
then is will use the fix pipe line.

Code: Select all
void DemoSubMesh::OptimizeForRender(const DemoMesh* const mesh) const
{
//   glUseProgram(m_shader);
//   glUniform1i(glGetUniformLocation(m_shader, "texture"), 0);


you will see the scen is far brighter, this befoem a real problem because and amine of 0.5 is too hight when using realitic values the scene is almos black with few highlight.
some is wrong but I cant find what it is.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sat Feb 02, 2019 12:23 pm

Hi Julio.
The problem seen to come from the ambient in the shader.
Maybe you can test this shader.
https://sites.google.com/site/oxnewton/ ... Diffuse.ps

Edited:
If you need the transparent for the car window.
You can maybe use something like this.

vec3 color = texColor.xyz * directionaLight;
gl_FragColor = vec4 (color, texColor.a);

This file is setup the same it as in the old file but with transparent actived.
https://sites.google.com/site/oxnewton/ ... ffuse_2.ps
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 3:53 pm

I believe I have good now, I found what the bug was and now seem equally bright.
Since the phong shading is per pixel, the model looks much better now with highlights
and is not doll like before.
can you please check it out and tell what you think?

now I am moving to the gpu skin vertex shader thats where we are going to get the performance back.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sat Feb 02, 2019 4:25 pm

The light look good and transparency too.
I get a black effect here i'm not sure from where but something get zeroed value somewhere in the shader.
https://www.youtube.com/watch?v=Z1Sm0JZr6oA
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 4:31 pm

unfortunately the fix pileline seem faster, when I run teh box stack I am getting about 75 fps top and if I comment out the shader programe
Code: Select all
void DemoSubMesh::OptimizeForRender(const DemoMesh* const mesh) const
{
//   glUseProgram(m_shader);
//   glUniform1i(glGetUniformLocation(m_shader, "texture"), 0);


I get about 250 top, that a factor of 3 to 1 or higher.


I remember long time ago, I was wondering if teh fix pipe is just using some optimize shader in teh driver and some one sad no, that is use dedicate hardware.
I am now confused because if it is hardware it seem way faster, but if is just special secret shaders (which is what I tend to beleive). then those shader are high optimized.

this is my normal light shader 1 directional light and one diffuse flash light at the eyepoint.
maybe some one can see some inefficiency.

Code: Select all
#version 120
// standard normal directional light one texture pixel shader

uniform sampler2D texture;

varying vec3 normal;
varying vec3 position;

vec3 PhongDirectionalShading()
{
   vec3 norm = normalize (normal);
   vec3 lighDir = normalize (gl_LightSource[0].position.xyz);
   vec3 specularDir = normalize (-position);
   vec3 refectionDir = -reflect (lighDir, normal);

   vec3 ambientCoeff = vec3(gl_LightSource[0].ambient * gl_FrontMaterial.ambient);
   vec3 diffuseCoeff = vec3(gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse);
   vec3 specularCoeff = vec3(gl_LightSource[0].specular * gl_FrontMaterial.specular);

   vec3 ambientColor = ambientCoeff + vec3(gl_FrontMaterial.emission);
   vec3 diffuseColor = diffuseCoeff * max (dot(norm, lighDir), 0.0);
   vec3 specularColor = specularCoeff * pow (max (dot (refectionDir, specularDir), 0.0), gl_FrontMaterial.shininess);

   //return vec3 (specularColor);
   return vec3 (ambientColor + diffuseColor + specularColor);
}

vec3 GouraudPointLightShading(int index)
{
   vec3 norm = normalize (normal);
   vec3 lighDir = normalize (gl_LightSource[index].position.xyz - position);

   vec3 diffuseCoeff = vec3(gl_LightSource[index].diffuse * gl_FrontMaterial.diffuse);
   vec3 diffuseColor = diffuseCoeff * max (dot(norm, lighDir), 0.0);
   return diffuseColor;
}

void main()
{
   // get texture color
   vec3 texColor = vec3 (texture2D(texture, gl_TexCoord[0].st));

   //vec3 lightIntensity = PhongDirectionalShading();
   vec3 lightIntensity = PhongDirectionalShading() + GouraudPointLightShading(1);
   
   vec3 color = texColor * lightIntensity;

   float opacity = gl_FrontMaterial.diffuse.w;
   gl_FragColor = vec4 (color, opacity);
}

Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sat Feb 02, 2019 4:33 pm

You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 4:40 pm

I just commited a tweak, can you check again before I see what that is.
I changed the like to this.

Code: Select all
vec3 specularColor = specularCoeff * pow (max (dot (refectionDir, specularDir), 0.1), gl_FrontMaterial.shininess);


please try again.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 4:45 pm

I nee to add the light attenuation, the brightness is too strong without it, but I can do after get the skin shader
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sat Feb 02, 2019 4:46 pm

I get the same problem with the change.
Remember you too, You use old opengl #version 120
I think with newer opengl like 330 or over you need to change the old rendering method and use buffers.
Maybe newers shader version can have better features for bones and Geometry Shader and more rendering features.

Edited:
Code: Select all
vec3 specularColor = specularCoeff * pow (max (dot (refectionDir, specularDir), 0.1), gl_FrontMaterial.shininess);


With this change it work ok it don't work only when value is zero.
Sorry I have get a bug when I have post my message.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sat Feb 02, 2019 5:00 pm

Dave Gravel wrote:With this change it work ok it don't work only when value is zero.
Sorry I have get a bug when I have post my message.

To make it clear, are you sayon that is fine now.

Yes I read about that about vertex buffers been deprecated, that why I use version 120
so that I do no have to rewrite all the vertices stuff.
as along as it works and will go on, them some day I update to a new version.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sat Feb 02, 2019 5:02 pm

Yes it is fine now.
It give a nice rendering :) the light is good.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sun Feb 03, 2019 2:12 pm

Dave I wrote the vertex weight shader. I t has a bug that I can't fine.
I am not sure is the matrices are loaded of the have to ne transpose, of the dgVertex attribute are passed in little indian or something like that.
but is runs and the performance is abput 10 time in debug and about 40 time in release.
basically ther is not difference between rendering a sking of a solid mesh
I is so hard to determine when some is wrong on a shade because there is no debugger.

If you sync you can check it out, I is set to CPU skinning to enable teh GPU skinning in file
...\applications\demosSandbox\sdkDemos\DemoMesh.cpp line 1233 set the if def to 1
Code: Select all
void DemoSkinMesh::Render (DemoEntityManager* const scene)
{
#if 1 


maybe you can see what mistake I made in the shader.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sun Feb 03, 2019 2:29 pm

I debug a lithe and I thing is the matrix pallet that is no bee loaded, because even what I set to zero, teh result is teh same. this is how I loaded it

Code: Select all
   int count = CalculateMatrixPalette(bindMatrix);
   GLfloat* const glMatrixPallete = dAlloca (GLfloat, 16 * count);
   for (int i = 0; i < count; i ++) {
      const dMatrix& src = bindMatrix[i];
      GLfloat* dst = &glMatrixPallete[i * 16];
      for (int j = 0; j < 4; j ++) {
         for (int k = 0; k < 4; k ++) {
            dst[j * 4 + k] = src[j][k];
            dst[j * 4 + k] = 0.0;
         }
      }
   }

//   glUniformMatrix4fv(matrixPalette, count, TRUE, glMatrixPallete);
   glUniformMatrix4fv(matrixPalette, count, FALSE, glMatrixPallete);


as you can see the matrix is set to zero, therefore the mesh sould disappear by is look exactly teh same as when the matrix is what is suppose to be.
no sure how to load an array of matrices to a uniform array.
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Improving the demo render quality and performance

Postby Dave Gravel » Sun Feb 03, 2019 2:56 pm

I'm not so sure I have test with mode 0 in debug and I get only 90 fps.
With the mode 1 I get around 1500 in debug and around 4000 in release.
I have look the matrix parts and shader I see nothing for now.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 712
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Improving the demo render quality and performance

Postby Julio Jerez » Sun Feb 03, 2019 3:04 pm

from 90 to 1500 is good, your machine is faster than mine.
I still can't see what is wrong, I cant believe there is not a glsl debugger available or a lest I have no fond any.
do you use glsl for your shaders?
Julio Jerez
Moderator
Moderator
 
Posts: 10989
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 10 guests