About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Custom Shader Learning Project
Author Message
georgatos7 Offline
Member

Post: #16
RE: Custom Shader Learning Project
Awesome update, thanks.
(This post was last modified: 11-26-2014 02:39 AM by georgatos7.)
11-26-2014 02:23 AM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #17
RE: Custom Shader Learning Project
[Image: CrateDemo.jpg]

CrateDemo_executable

This demo takes the procedural box from 'GeometryGenerator' and uses the custom shader 'Basic.cpp' to apply a crate texture ('WoodCrate01.dds') to it.
The 'Basic.cpp' custom shader currently supports transformations, lighting, and texturing. It will act as the basic template for the still-to-come shaders.

However, it also demonstrates how to apply different Techniques to the shader from within the C++ code. By supplying different parameters to the function 'TechniqueCustomShaderName()', the shader can be compiled so that it will behave according to how those parameters are used in the shader code.
Esenthel has made this possible by means of a 'CUSTOM TECHNIQUE' macro replacing the usual 'TECHNIQUE(Main, VS(), PS())' which I've been using until now.

Observe that 'Basic.cpp' has techniques with texturing and without, by using the uniform parameter 'gUseTex'. In this way, if I need to render something that does not need texturing, I select the technique without it, and therefore, do not have to pay the cost of texturing . Likewise, I select the technique with the number of lights I use, so that I do not pay the cost of additional lighting calculations that I do not need.

My first post has been updated with the latest project files.
11-27-2014 03:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #18
RE: Custom Shader Learning Project
Spreading the word about the work you are doing here:
https://plus.google.com/u/0/communities/...1451923737
11-27-2014 03:48 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #19
RE: Custom Shader Learning Project
Yet again, many thanks for the continued examples.

Got my copy of the book today too smile
11-28-2014 08:07 PM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #20
RE: Custom Shader Learning Project
@pixelperfect
Quote:Got my copy of the book today too
That's great! You can only gain by going through it. Although specifically applied to DirectX 11, it does not matter too much as all the DirectX 11 stuff is already encapsulated in Esenthel.

Just an added note on the 'CrateDemo' I posted yesterday:
I had left the 'myTexTransform' matrix just as an identity matrix, but there is nothing stopping folks putting this matrix to use:
For tiling the texture, just add some scaling by adding in the 'Init' section:
PHP Code:
// 4x4 tiling
   
myTexTransform.scale(Vec(440)); 

For animated scrolling of the texture, add in the 'Update' section:
PHP Code:
// transform the texture
   
Flt TexOffset_x=0.0
   
Flt TexOffset_y=0.0;
   
Flt Speed_x=0.0;
   
Flt Speed_y=0.5;
   
TexOffset_x+=Speed_x*Time.d(); 
   
TexOffset_y+=Speed_y*Time.d(); 
   
myTexTransform.move(TexOffset_xTexOffset_y0.0); 

For animated rotation of the texture, add in the 'Update' section:
PHP Code:
// rotate the texture
   
static Flt RotOffset_z=0.0;
   
Flt Speed_z=0.01;
   
RotOffset_z+=Speed_z;
   if(
RotOffset_z>2*PI )
      
RotOffset_z=0.0;
   
myTexTransform.setRotateZ(RotOffset_z); 
11-29-2014 10:48 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Silver Supporter

Post: #21
RE: Custom Shader Learning Project
if built in 64bit the program becomes unresponsive for me, can anyone else verify?
32bit build works fine.

The problem seems to be occuring at "myWater.parts(0).render.vtxUnlock(); // NB unlock after all read/write is completed"

due to a EE::Free call inside VtxBuf unlock.
(This post was last modified: 11-30-2014 05:41 PM by Zervox.)
11-30-2014 05:41 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #22
RE: Custom Shader Learning Project
I think he only intended it 'as it is' to be for 32 bit build as mentioned in his opening post:

(11-21-2014 10:20 AM)3DRaddict Wrote:  Just a few notes on the project requirements:
1) Only Windows 32bit
2) Only DirectX 10+
3) For the shaders to compile you must duplicate my particular setup (or change to suit your own)

I have had an issue with running this which resulted in a run time error indicating the AO buffer already existed by with a different size. Removing the Ambient Occlusion shader header cured this so I guess I might have an out of date copy of the shader headers.
11-30-2014 06:18 PM
Find all posts by this user Quote this message in a reply
Zervox Offline
Silver Supporter

Post: #23
RE: Custom Shader Learning Project
yes I know of the notes, however the behavior of the program shouldn't differ like that unless there is something I am missing. This obviously is only on Lightning tutorial due to that exact call, and it is the only problem I've encountered.

the AO issue certainly is because of outdated shader headers. you can fix that by removing the // before CompileShaders in the lightning tutorial. if that doesn't help, you might as well update to latest shader headers as there is nothing to gain keeping the old ones. : )

The place where you are doing something wrong regarding elongated droplets is in

Code:
Byte *data=myWater.parts(0).render.vtxLock(LOCK_READ_WRITE);
   Int pos_ofs=myWater.parts(0).render.vtxOfs(VTX_POS);
   Int nrm_ofs=myWater.parts(0).render.vtxOfs(VTX_NRM);
   Int tan_ofs=myWater.parts(0).render.vtxOfs(VTX_TAN);
   Int bin_ofs=myWater.parts(0).render.vtxOfs(VTX_BIN);
   Int tex0_ofs=myWater.parts(0).render.vtxOfs(VTX_TEX0);
  
   Vec pos;
   for(uint i = 0; i < myWaves.VertexCount(); i++)
   {
      pos=*(Vec*)(data+pos_ofs+i*vtx_size);
      *((Vec*)(data + pos_ofs + i*vtx_size)) = Vec(pos.x, myWaves.getCurrSolution(i).y, pos.z);
      *((VecB4*)(data + nrm_ofs + i*vtx_size))=NrmToSBYTE4N(Vec(myWaves.getNormals(i).x,myWaves.getNormals(i).y, myWaves.getNormals(i).z ));
      *((VecB4*)(data + tan_ofs + i*vtx_size))=NrmToSBYTE4N(Vec(myWaves.getTangents(i).x,myWaves.getTangents(i).y,​ myWaves.getTangents(i).z ));
      Vec B=Cross(myWaves.getNormals(i),myWaves.getTangents(i) );
      *((VecB4*)(data + bin_ofs + i*vtx_size))=NrmToSBYTE4N(Vec(B.x, B.y, B.z ));
   }


found it by doing the way slower approach of
Code:
Vec pos;
   FREP(myWaves.VertexCount())
   {
      
      pos=myWater.parts(0).base.vtx.pos(i);
      myWater.parts(0).base.vtx.pos(i) = Vec(pos.x, myWaves.getCurrSolution(i).y, pos.z);
      myWater.parts(0).base.vtx.nrm(i)=Vec(myWaves.getNormals(i).x,myWaves.getNor​mals(i).y, myWaves.getNormals(i).z );
      myWater.parts(0).base.vtx.tan(i)=Vec(myWaves.getTangents(i).x,myWaves.getTa​ngents(i).y, myWaves.getTangents(i).z );
      myWater.parts(0).base.vtx.bin(i)=Cross(myWaves.getNormals(i),myWaves.getTan​gents(i) );
   }
   myWater.setRender();

my guess is possibly the NrmTobyte or the offsets are wrong.
(This post was last modified: 11-30-2014 07:27 PM by Zervox.)
11-30-2014 06:33 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #24
RE: Custom Shader Learning Project
(11-30-2014 06:33 PM)Zervox Wrote:  ...
the AO issue certainly is because of outdated shader headers. you can fix that by removing the // before CompileShaders in the lightning tutorial. if that doesn't help, you might as well update to latest shader headers as there is nothing to gain keeping the old ones. : )

Yeah, I'll update the shader headers ... thanks.


(11-30-2014 06:33 PM)Zervox Wrote:  yes I know of the notes, however the behavior of the program shouldn't differ like that unless there is something I am missing. This obviously is only on Lightning tutorial due to that exact call, and it is the only problem I've encountered.
...

Thinking about it the restriction to 32 bit in the notes may only have been due to the initial Windows dependencies, there may have been a 32 bit lib referenced. I don't remember what was referenced since those dependencies were removed.
12-01-2014 09:43 AM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #25
RE: Custom Shader Learning Project
@Zervox
Quote:The place where you are doing something wrong regarding elongated droplets is in
Thanks for pinpointing this... I substituted your bit of code and, lo and behold, I have nice circular ripples!grin

I'll have to investigate my dynamic vertex buffer code to see where it is going wrong.

As for the 64-bit story... it really boils down to my "old habits, die hard" theory.
Even though I have 'Windows 7 Home Premium' installed, I've grown too used to installing all apps and my own code projects in 'Program Files (X86)' folder as 32-bit.
Just never bothered with changing over to 64-bit.

I, just now, tried compiling all these shader examples as 64-bit, and you are quite correct, Zervox, they all compile and run ok, except 'Lighting'. I've no idea why.

Anyway, as I mentioned in my preamble to this project, I was undertaking it purely on a personal training basis, and just providing my code for others to view as they please. As long as it works on my particular system, I'm happy.smile
12-01-2014 01:23 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Zervox Offline
Silver Supporter

Post: #26
RE: Custom Shader Learning Project
Debug directs toward the unlock operation done at the end, something in the unlock is calling free, and that code is the code which is doing something it maybe isn't supposed to. Maybe EE could have a look at it when he gets time, I could possibly check it myself but I also got other things on my plate at the same time. smile

Yes and thank you anyways, because even if that exact sample doesn't work, I don't expect you to cover every grounds of platforms 32bit and 64bit compatibility. It still does give some ideas to try out. smile whatever I find not working on 64bit I might try writing code myself that works for both. it is good exercise in and by itself. ^^
12-01-2014 04:39 PM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #27
RE: Custom Shader Learning Project
My ripple problem has been solved!

http://www.esenthel.com/community/showth...8#pid49718
12-06-2014 06:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #28
RE: Custom Shader Learning Project
Looking awesome.
12-06-2014 10:27 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Silver Supporter

Post: #29
RE: Custom Shader Learning Project
Just wanted to note the fix for the ripples fixes the crash for 64bit.
12-06-2014 06:12 PM
Find all posts by this user Quote this message in a reply
3DRaddict Offline
Member

Post: #30
RE: Custom Shader Learning Project
Just added a little bit of life in the form of a tiled 'grass' texture and a tiled scrolling 'water' texture. The water now has circular ripples. Two custom shaders 'basic_land.cpp' and 'basic_water.cpp' take care of transformations, lighting and texturing of the land and water, respectively.
[Image: TexturedHillsWavesDemo.jpg]

TexturedHillsWavesDemo_executable
12-07-2014 10:28 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply