About Store Forum Documentation Contact



Post Reply 
SPSet and Multiparameter shader problem.
Author Message
georgatos7 Offline
Member

Post: #1
SPSet and Multiparameter shader problem.
Hi, i got 2 problems with the shaders coding and even though i have searched the forums and the tutorials, i can't find the solution.

First problem.

In the "Shader with Parameter.cpp" example there is this part of code where a constant buffer is set in order to send a Vec2 variable from the C++ to the shader.

Code:
// PARAMETERS
/******************************************************************************/
BUFFER(ShaderWithParameterBuffer) // store parameters in custom Constant Buffer
   Vec2 TextureOffset; // declare a global Vec2 parameter
BUFFER_END
/******************************************************************************/

Now the shader code compiles successfully but when i run the "02 - Shader Parameters.cpp" in Esenthel i get the error...

Code:
1>------ Build started: Project: Application 1, Configuration: Debug Win32 ------
1>Compiling...
1>Example.cpp
1>c:\esenthel\projects\_build_\application 1\source\example.cpp(102) : error C2665: 'EE::SPSet' : none of the 18 overloads could convert all the argument types
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(107): could be 'void EE::SPSet<EE::Vec2>(CChar8 *,const TYPE &)'
1>        with
1>        [
1>            TYPE=EE::Vec2
1>        ]
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(91): or       'void EE::SPSet(CChar8 *,Bool)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(92): or       'void EE::SPSet(CChar8 *,Int)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(93): or       'void EE::SPSet(CChar8 *,Flt)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(94): or       'void EE::SPSet(CChar8 *,const EE::Vec2 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(95): or       'void EE::SPSet(CChar8 *,const EE::Vec &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(96): or       'void EE::SPSet(CChar8 *,const EE::Vec4 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(97): or       'void EE::SPSet(CChar8 *,const EE::VecI2 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(98): or       'void EE::SPSet(CChar8 *,const EE::VecI &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(99): or       'void EE::SPSet(CChar8 *,const EE::VecI4 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(100): or       'void EE::SPSet(CChar8 *,const EE::Matrix3 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(101): or       'void EE::SPSet(CChar8 *,const EE::Matrix &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(102): or       'void EE::SPSet(CChar8 *,const EE::Matrix4 &)'
1>        c:\esenthel\bin\esenthelengine\graphics\shader.h(108): or       'void EE::SPSet(CChar8 *,const EE::Color &)'
1>        while trying to match the argument list '(const wchar_t [14], EE::Vec2)'
1>Build log was saved at "file://c:\ESENTHEL\Projects\_Build_\Application 1\Debug\BuildLog.htm"
1>Application 1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

...pointing at the "SPSet" line below.

Code:
Bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 1000, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   // set shader's custom parameter value
   SPSet(   "TextureOffset", Vec2(Time.time(), 0)   );

   return true;
}

Now SPSet seems to need a pointer to a char instead of the string "TextureOffset", so when i replace the SPSet with a char pointer it seems to work but this leads to my second problem.



Second problem.

I use single chars to transfer the values to the shader like this.

Shader Code.
Code:
// PARAMETERS
/******************************************************************************/
BUFFER(ShaderWithParameterBuffer) // store parameters in custom Constant Buffer
   Vec2 t; // declare a global Vec2 parameter
BUFFER_END
/******************************************************************************/

C++ code.
Code:
cchar8 shaderData01='t';
Bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 1000, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   // set shader's custom parameter value
   SPSet(   &shaderData01, Vec2(Time.time(), 0)   );

   return true;
}


Now this works and i see the texture scrolling but when i try to add a second cchar8 variable to the C++ code so that i can pass a second parameter later in the shader it seems to stop using my first parameter.

So the example below stops working.

C++ code.
Code:
cchar8 shaderData01='t';
cchar8 shaderData02='o';
Bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 1000, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));

   // set shader's custom parameter value
   SPSet(   &shaderData01, Vec2(Time.time(), 0)   );

   return true;
}



So is there something i'm missing and i can't use string variable names like "TextureOffset" to pass variables to the shader and if the cchar8 is the solution, what should i do to pass a second parameter?

Thanks for your time.
(This post was last modified: 04-15-2014 12:58 PM by georgatos7.)
04-14-2014 04:27 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #2
RE: SPSet and Multiparameter shader problem.
--TLDR--

Anyone knows why

PHP Code:
SPSet("TexOffset"Vec2(0Time.time())); 

returns an error and how to pass variables in the shaders?
I'm asking because this is the default Esenthel tutorial and it's not working, so there is no other reference.

Thanks.
(This post was last modified: 04-23-2014 03:07 PM by georgatos7.)
04-23-2014 03:06 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #3
RE: SPSet and Multiparameter shader problem.
Ok it seems i found a bug.

The problem is shown in the simple shader code that follows.

Code:
/******************************************************************************/
#include "Main.h"
/******************************************************************************/
// PARAMETERS
/******************************************************************************/
/*
BUFFER(FlowBuffer) // store parameters in custom Constant Buffer
Vec2    j,
        o;
BUFFER_END
*/


Vec2    j,
        o;

/******************************************************************************/
// PIXEL SHADER
/******************************************************************************/
Vec4 PixelShader_PS
(
   IF_IS_PIXEL

   Vec2 inTex:TEXCOORD
):COLOR
{
   Flt z=Tex(Pos, inTex+(j+o)/10.0).x; // Get Depth Buffer Position
   return Vec4(z/10, 0, 0, 0.5f);
}
/******************************************************************************/
// TECHNIQUE
/******************************************************************************/
TECHNIQUE(CustomTechnique, Draw_VS(), PixelShader_PS());
/******************************************************************************/

Code:
/******************************************************************************/
#include "stdafx.h"
#include "c:/Projects/material_user_shader.enum.h"
/******************************************************************************/
Mesh box,
     ball;                                                                  

//Shader *myShader;// create a shader handle to manually change its parameters

MaterialPtr brick;
/******************************************************************************/
void CompileShaders()
{
   if(D.shaderModel()==SM_GL)
   {
      ShaderCompile("C:/Projects/Shader HLSL/TestVar.cpp", S+DataPath()+"Shader/GL/User/Custom Shader", SM_GL);
   }else
   if(D.shaderModel()>=SM_4)
   {
      ShaderCompile("C:/Projects/Shader HLSL/TestVar.cpp", S+DataPath()+"Shader/4/User/Custom Shader", SM_4);
   }else
   {
      ShaderCompile("C:/Projects/Shader HLSL/TestVar.cpp", S+DataPath()+"Shader/2/User/Custom Shader", SM_2);
      ShaderCompile("C:/Projects/Shader HLSL/TestVar.cpp", S+DataPath()+"Shader/3/User/Custom Shader", SM_3);
   }
}
/******************************************************************************/
void InitPre()
{
   App.name("2D Shader");
   App.flag=APP_FULL_TOGGLE|APP_MS_EXCLUSIVE;  
   DataPath("C:/Esenthel/Projects/!m4iis3x0vo570!345ai7c1d/Game/");  
   Paks.add("C:/Esenthel/Bin/engine.pak");
   D.mode(900, 900, false);
   D.ambientPower(0.1f);
}
Bool Init()
{
   Cam.dist=2;

   // compile shader
   CompileShaders();

   // set meshes
   brick.require(UID(2404297727, 1221101651, 2104406697, 3519969918));
   box  .parts.New().base.create( Box(5), VTX_TEX0|VTX_NRM|VTX_TAN).reverse();
   ball .parts.New().base.create(Ball(1), VTX_TEX0|VTX_NRM|VTX_TAN)          ;

   box .setMaterial(brick).setRender().setBox();
   ball.setMaterial(brick).setRender().setBox();
  
   //myShader = Shaders("User/Custom Shader");
  
   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   CamHandle(0.1f, 1000, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT));
  
   // BUG HERE <--- (Sometimes only the 'o' works)
   if(Kb.bp(KB_Q))
   {  
   cchar8 name = 'j';
   SPSet(&name, Vec2(0, 3));  
   cchar8 name2 = 'o';
   SPSet(&name2, Vec2(0, 3));
   }
  
   // Always works
   if(Kb.bp(KB_W))
   {
   cchar8 name = 'j';
   SPSet(&name, Vec2(0, 3));  
   }
  
   // Always works
   if(Kb.bp(KB_E))
   {
   cchar8 name2 = 'o';
   SPSet(&name2, Vec2(0, 3));
   }
  
   return true;
}
/******************************************************************************/
void Render()
{
   switch(Renderer())
   {
      case RM_PREPARE:
      {
         ball.draw(MatrixIdentity);
         box .draw(MatrixIdentity);

         LightPoint(20, Vec(0,3,-3)).add();
      }break;
   }
}
void Draw()
{
   Renderer(Render);

   // perform a 2D shader effect on left half of the screen
   Shaders("User/Custom Shader")->getTech("CustomTechnique")->draw(NULL, &Rect(-D.w(), -D.h(), 0, D.h()));
}
/******************************************************************************/


When you press W or E the outcome is always as expected.
If you try pressing Q when the program starts (many restarts) you'll get the different results shown below.

[Image: Shader.jpg]

I have made a nice Bloom and Eye Adaptation effect and i can't utilize it because SPSet acts weirdly and it's driving me crazy.

Anyone else tried the shaders in Esenthel?
It seems strange that i'm the only one with that problem.
(This post was last modified: 04-24-2014 01:10 AM by georgatos7.)
04-24-2014 01:07 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: SPSet and Multiparameter shader problem.
http://www.esenthel.com/?id=doc#Language_Differences

SPSet(8"TexOffset", Vec2(0, Time.time()));
04-24-2014 03:12 AM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #5
RE: SPSet and Multiparameter shader problem.
(04-24-2014 03:12 AM)Esenthel Wrote:  http://www.esenthel.com/?id=doc#Language_Differences

SPSet(8"TexOffset", Vec2(0, Time.time()));

Works perfectly.
Thanks a lot!
04-24-2014 05:56 AM
Find all posts by this user Quote this message in a reply
Post Reply