Help A simpler shader

Everything related to 3D programming
User avatar
Johny8
User
User
Posts: 10
Joined: Sun Jan 25, 2015 1:40 am
Location: Bogotá -Colombia-
Contact:

Help A simpler shader

Post by Johny8 »

Hi I'm trying to learn writing shaders, but I think I'm doing something wrong since continued seeing a white cube.

// Material Box
vertex_program PlainTexture_VS cg
{

source GameObjStandard.cg
entry_point main_plain_texture_vp
profiles vs_1_1


default_params
{

param_name_auto worldViewProj worldViewproj_matrix


}


}


fragment_program PlainTexture_PS cg
{

source GameObjStandard.cg
entry_point_ main_plain_texture_fp
profiles ps_1_1



}







material Caja/Madera
{

technique
{


pass
{



vertex_program_ref PlainTexture_VS
{
}

fragment_program_ref PlainTexture_PS
{

}


texture_unit
{

texture Caja.jpg


}


}


}



}
// File CG

void main_plain_texture_vp(
// Vertex Inputs
float4 position : POSITION, // Vertex position in model space
float2 texCoord0 : TEXCOORD0, // Texture UV set 0

// Outputs
out float4 oPosition : POSITION, // Transformed vertex position
out float2 uv0 : TEXCOORD0, // UV0

// Model Level Inputs
uniform float4x4 worldViewProj)
{
// Calculate output position
oPosition = mul(worldViewProj, position);

// Simply copy the input vertex UV to the output
uv0 = texCoord0;
}

void main_plain_texture_fp(
// Pixel Inputs
float2 uv0 : TEXCOORD0, // UV interpolated for current pixel

// Outputs
out float4 color : COLOR, // Output color we want to write

// Model Level Inputs
uniform sampler2D texture) // Texture we're going to use
{
// Just sample texture using supplied UV
color = tex2D(texture, uv0);
}

I'm trying to learn, I am following the official documentation of Ogre
http://www.ogre3d.org/tikiwiki/tiki-ind ... +Materials
Iris3D -Games Studios- http://www.iris3dgames.com
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Help A simpler shader

Post by Samuel »

Usually when an object is white that means it failed to load the script or shader.
The easiest way to debug the problem is look at your Ogre log. Which is created at your applications root directory when you use InitEngine3D() with the #PB_Engine3D_DebugLog flag.

As to why your shader failed I'm guessing it's because your missing Nividia's CG toolkit.
CG shaders require the cg.dll that comes with the toolkit in order to run properly. This is one of the reasons I prefer HLSL and GLSL shaders (both are independent of dlls) over CG shaders.

You also need to use the #PB_Engine3D_EnableCG flag with InitEngine3D() in order to use any cg shaders in Purebasic.

Here's the sample code from your link with all the required files. I also included the cg.dll which means you shouldn't need to download the toolkit to run this specific code.

Let me know if you have trouble running this or if you have any questions.
Simple CG Shader.zip
User avatar
Johny8
User
User
Posts: 10
Joined: Sun Jan 25, 2015 1:40 am
Location: Bogotá -Colombia-
Contact:

Re: Help A simpler shader

Post by Johny8 »

Samuel wrote:Usually when an object is white that means it failed to load the script or shader.
The easiest way to debug the problem is look at your Ogre log. Which is created at your applications root directory when you use InitEngine3D() with the #PB_Engine3D_DebugLog flag.

As to why your shader failed I'm guessing it's because your missing Nividia's CG toolkit.
CG shaders require the cg.dll that comes with the toolkit in order to run properly. This is one of the reasons I prefer HLSL and GLSL shaders (both are independent of dlls) over CG shaders.

You also need to use the #PB_Engine3D_EnableCG flag with InitEngine3D() in order to use any cg shaders in Purebasic.

Here's the sample code from your link with all the required files. I also included the cg.dll which means you shouldn't need to download the toolkit to run this specific code.

Let me know if you have trouble running this or if you have any questions.
Simple CG Shader.zip

Hi, thanks for the example.

I'm trying to learn the language CG, but I'm really confused.

You know of any editor to write CG?

Where I can find the reference documentation CG?

I need very basic tutorials to understand this.

Greetings.
Iris3D -Games Studios- http://www.iris3dgames.com
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Help A simpler shader

Post by Samuel »

Johny8 wrote: I'm trying to learn the language CG, but I'm really confused.
Don't worry that's normal when it comes to shaders. :wink:
Johny8 wrote: You know of any editor to write CG?
There's Nvidia's FX Composer which covers CG shaders and a few other areas. I wasn't too fond of it, but it's the only CG editor I know of and who knows maybe you'll like it. The created shaders will require some editing in order for them to work in Purebasic/Ogre. So, maybe this isn't a good place to start, but that's up to you to decide.
https://developer.nvidia.com/fx-composer
Johny8 wrote: Where I can find the reference documentation CG?
Maybe this will help you?
http://http.developer.nvidia.com/Cg/index.html
Johny8 wrote: I need very basic tutorials to understand this.
Unfortunately, I've never found any great tutorials for any shader language. A lot of this I think has to do with the complexity of shaders and the constant changing hardware.
I started learning by just trying to get Ogre's sample shaders to run in Purebasic. Probably not the best or quickest way to learn, but I somehow managed.

Also you may want to look for HLSL tutorials. DirectX 9 HLSL shaders are identical to CG shaders except the program definition which is one small line that needs to be changed.
ymerdy
User
User
Posts: 10
Joined: Thu Jan 18, 2018 11:54 pm

Re: Help A simpler shader

Post by ymerdy »

Hello,

I'm trying to compile and run the examples, but I get an error from Ogre saying:
CG dll can't be loaded in CgPlugin::install at OgreCgPlugin.cpp

Where shall I copy the cg.dll?
It is in the same folder as the pb source, but it doesn't work.
Is there an option to set in purebsic compilation preferences?

thanks
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Help A simpler shader

Post by Samuel »

It has been a while since I've seen this post. 4 years goes by in a hurry. :)

Did you have any luck running the example Simple CG Shader from my first post? If that one fails you might have a hardware issue.
If that's the case could you post your Ogre.log file from my example.
ymerdy wrote:It is in the same folder as the pb source, but it doesn't work.
If you haven't installed the Nvidia toolkit onto your computer then the cg.dll needs to be included with your pb source.
ymerdy wrote:Is there an option to set in purebsic compilation preferences?
Have you tried switching between DirectX and Opengl in purebasic's compiler options?
ymerdy
User
User
Posts: 10
Joined: Thu Jan 18, 2018 11:54 pm

Re: Help A simpler shader

Post by ymerdy »

Hello,

wow, thanks for your answer.
So, using "directx11" as subsystem, I have an error "failed to initialize the 3D engine",
with subsystem set to "opengl", the program starts, but I have no texture displayed (I see a gray circle on a grey background)
with subsystem left empty, I have a rotating textured sphere !

So I went back to the first example I tried, the brightness compositor.

I can compile/launch the program, but the F5/F6 keys have no effect on the brightness (I m using PB5.70), so I keep on searching.

Thank you!
Post Reply