Can You send to me Your example? I will check it (You shouldn't use sementics for matrices in shader file, because You probably not define them?). I will try repair Your example or irrCg, because maybe this is library bug.
@rootroot1
Thanks
![Smile :)](./images/smilies/icon_smile.gif)
Code: Select all
float4x4 WorldViewProj;
float3x3 WorldIT;
float3x4 World;
float3 LightVec;
float3 EyePos;
struct appdata {
float3 Position : POSITION;
float3 Normal : NORMAL;
};
struct vpconn {
float4 Hposition : POSITION;
float4 TexCoord0 : TEXCOORD0;
};
vpconn main(appdata IN)
{
vpconn OUT;
float3 worldNormal = normalize(mul(WorldIT, IN.Normal));
//build float4
float4 tempPos;
tempPos.xyz = IN.Position.xyz;
tempPos.w = 1.0;
//compute world space position
float3 worldSpacePos = mul(World, tempPos);
//vector from vertex to eye, normalized
float3 vertToEye = normalize(EyePos - worldSpacePos);
//h = normalize(l + e)
float3 halfAngle = normalize(vertToEye + LightVec);
OUT.TexCoord0.x = max(dot(LightVec,worldNormal),0.0);
OUT.TexCoord0.y = max(dot(halfAngle,worldNormal),0.0);
// transform into homogeneous-clip space
OUT.Hposition = mul(WorldViewProj, tempPos);
return OUT;
}
technique D3D9
{
pass P0
{
VertexProgram = compile vs_3_0 main();
}
}
Code: Select all
I set parameters, but nothing works
class ICGE_CGFX_CB : public ICgShaderConstantSetCallBack
{
public:
ICGE_CGFX_CB()
{
}
virtual void OnSetConstants(ICgServices* Services,const CGeffect& Effect,const CGpass& Pass,const CGprogram& Vertex,const CGprogram& Fragment,const SMaterial& Material)
{
// Vertex.
matrix4 Matrix;
pWVP = cgGetNamedEffectParameter(Effect, "WorldViewProj");
Matrix = Services->getDevice()->getVideoDriver()->getTransform(ETS_PROJECTION);
Matrix *= Services->getDevice()->getVideoDriver()->getTransform(ETS_VIEW);
Matrix *= Services->getDevice()->getVideoDriver()->getTransform(ETS_WORLD);
cgSetMatrixParameterfr(pWVP, Matrix.pointer());
matrix4 mWorld;
World = cgGetNamedEffectParameter(Effect, "World");
mWorld = Services->getDevice()->getVideoDriver()->getTransform(ETS_WORLD);
cgSetMatrixParameterfr(World, mWorld.pointer());
matrix4 mWorldInverseTranspose;
WorldIT = cgGetNamedEffectParameter(Effect, "WorldIT");
mWorld.getInverse(mWorldInverseTranspose);
mWorldInverseTranspose.getTransposed(mWorldInverseTranspose);
cgSetMatrixParameterfr(WorldIT, mWorldInverseTranspose.pointer());
if(Services->getDevice()->getSceneManager()->getActiveCamera() != NULL)
{
vector3df CameraPosition = Services->getDevice()->getSceneManager()->getActiveCamera()->getAbsolutePosition();
EyePosition = cgGetNamedParameter(Vertex, "EyePos");
Services->setParameter3f(EyePosition, CameraPosition.X, CameraPosition.Y, CameraPosition.Z);
}
LightVec = cgGetNamedParameter(Vertex, "LightVec");
Services->setParameter3f(LightVec,1.0,0,1.0);
}
private:
CGparameter pWVP;
CGparameter World;
CGparameter WorldIT;
CGparameter EyePosition;
CGparameter LightVec;
}
Code: Select all
float4 main(in float3 refractVec : TEXCOORD0,
in float3 reflectVec : TEXCOORD1,
in float3 fresnelTerm : COLOR0,
uniform samplerCUBE environmentMaps[2],
uniform float enableRefraction,
uniform float enableFresnel) : COLOR
{
float3 refractColor = texCUBE(environmentMaps[0],
refractVec).rgb;
float3 reflectColor = texCUBE(environmentMaps[1],
reflectVec).rgb;
float3 reflectRefract = lerp(refractColor, reflectColor,
fresnelTerm);
float3 finalColor = enableRefraction ?
(enableFresnel ? reflectRefract : refractColor) :
(enableFresnel ? reflectColor : fresnelTerm);
return float4(finalColor, 1.0);
}
Code: Select all
//vertex params
float4x4 WorldViewProj;
float4 LightVector; //in object space
float4 EyePosition; //in object space
//fragment params
sampler2D DiffuseMap;
sampler2D NormalMap;
sampler2D IlluminationMap;
float Ambient;
struct a2v {
float4 Position : POSITION; //in object space
float3 Normal : NORMAL; //in object space
float2 TexCoord : TEXCOORD0;
float3 T : TEXCOORD1; //in object space
float3 B : TEXCOORD2; //in object space
float3 N : TEXCOORD3; //in object space
};
struct v2f {
float4 Position : POSITION; //in projection space
float4 Normal : COLOR0; //in tangent space
float4 LightVectorUnsigned : COLOR1; //in tangent space
float3 TexCoord0 : TEXCOORD0;
float3 TexCoord1 : TEXCOORD1;
float4 LightVector : TEXCOORD2; //in tangent space
float4 HalfAngleVector : TEXCOORD3; //in tangent space
};
v2f main_v(a2v IN)
{
v2f OUT;
// pass texture coordinates for
// fetching the diffuse map
OUT.TexCoord0.xy = IN.TexCoord.xy;
// pass texture coordinates for
// fetching the normal map
OUT.TexCoord1.xy = IN.TexCoord.xy;
// compute the 3x3 transform from
// tangent space to object space
float3x3 objToTangentSpace;
objToTangentSpace[0] = IN.T;
objToTangentSpace[1] = IN.B;
objToTangentSpace[2] = IN.N;
// transform normal from
// object space to tangent space
OUT.Normal.xyz = 0.5 * mul(objToTangentSpace, IN.Normal) + 0.5;
// transform light vector from
// object space to tangent space
float3 lightVectorInTangentSpace =
mul(objToTangentSpace, LightVector.xyz);
OUT.LightVector.xyz = lightVectorInTangentSpace;
OUT.LightVectorUnsigned.xyz = 0.5 *
lightVectorInTangentSpace + 0.5;
// compute view vector
float3 viewVector =
normalize(EyePosition.xyz - IN.Position.xyz);
// compute half angle vector
float3 halfAngleVector =
normalize(LightVector.xyz + viewVector);
// transform half-angle vector from
// object space to tangent space
OUT.HalfAngleVector.xyz =
mul(objToTangentSpace, halfAngleVector);
// transform position to projection space
OUT.Position = mul(WorldViewProj, IN.Position);
return OUT;
}
struct v2f {
float4 Position : POSITION; //in projection space
float4 Normal : COLOR0; //in tangent space
float4 LightVectorUnsigned : COLOR1; //in tangent space
float3 TexCoord0 : TEXCOORD0;
float3 TexCoord1 : TEXCOORD1;
float4 LightVector : TEXCOORD2; //in tangent space
float4 HalfAngleVector : TEXCOORD3; //in tangent space
};
float4 main_f(v2f IN) : COLOR
{
// fetch base color
float4 color = tex2D(DiffuseMap, IN.TexCoord0.xy);
// fetch bump normal and expand it to [-1,1]
float4 bumpNormal = 2 *
(tex2D(NormalMap, IN.TexCoord1.xy) - 0.5);
// compute the dot product between
// the bump normal and the light vector,
// compute the dot product between
// the bump normal and the half angle vector,
// fetch the illumination map using
// the result of the two previous dot products
// as texture coordinates
// returns the diffuse color in the
// color components and the specular color in the
// alpha component
float2 illumCoord =
float2(dot(IN.LightVector.xyz, bumpNormal.xyz),
dot(IN.HalfAngleVector.xyz, bumpNormal.xyz));
float4 illumination = tex2D(IlluminationMap, illumCoord);
// expand iterated normal to [-1,1]
float4 normal = 2 * (IN.Normal - 0.5);
// compute self-shadowing term
float shadow = saturate(4 * dot(normal.xyz,
IN.LightVectorUnsigned.xyz));
// compute final color
return (Ambient * color + shadow)
* (illumination * color + illumination.wwww);
}
technique D3D9
{
pass P0
{
VertexProgram = compile vs_3_0 main_v();
FragmentProgram = compile ps_3_0 main_f();
}
}
Code: Select all
class IBumpCG : public ICgShaderConstantSetCallBack
{
public:
IBumpCG()
{
}
virtual void OnSetConstants(ICgServices* Services,const CGeffect& Effect,const CGpass& Pass,const CGprogram& Vertex,const CGprogram& Fragment,const SMaterial& Material)
{
// Vertex.
matrix4 Matrix;
pWVP = cgGetNamedEffectParameter(Effect, "WorldViewProj");
Matrix = Services->getDevice()->getVideoDriver()->getTransform(ETS_PROJECTION);
Matrix *= Services->getDevice()->getVideoDriver()->getTransform(ETS_VIEW);
Matrix *= Services->getDevice()->getVideoDriver()->getTransform(ETS_WORLD);
cgSetMatrixParameterfr(pWVP, Matrix.pointer());
/*matrix4 mWorld;
World = cgGetNamedEffectParameter(Effect, "World");
mWorld = Services->getDevice()->getVideoDriver()->getTransform(ETS_WORLD);
cgSetMatrixParameterfr(World, mWorld.pointer());
matrix4 mWorldInverseTranspose;
WorldIT = cgGetNamedEffectParameter(Effect, "WorldIT");
mWorld.getInverse(mWorldInverseTranspose);
mWorldInverseTranspose.getTransposed(mWorldInverseTranspose);
cgSetMatrixParameterfr(WorldIT, mWorldInverseTranspose.pointer());*/
if(Services->getDevice()->getSceneManager()->getActiveCamera() != NULL)
{
vector3df CameraPosition = Services->getDevice()->getSceneManager()->getActiveCamera()->getAbsolutePosition();
EyePosition = cgGetNamedParameter(Vertex, "EyePosition");
Services->setParameter4f(EyePosition, CameraPosition.X, CameraPosition.Y, CameraPosition.Z,0);
}
LightVec = cgGetNamedParameter(Vertex, "LightVector");
Services->setParameter4f(LightVec,1.0,0,1.0,0);
// Fragment.
DiffuseMap = cgGetNamedEffectParameter(Effect, "DiffuseMap");
Services->setTexture( DiffuseMap,Material.TextureLayer[0],0 ); // We can't use optimized EnableTexture function instead of setTexture in OpenGL mode, because next cgSetSamplerState need bind, active texture.
cgSetSamplerState(DiffuseMap); // Important for apply sampler states from CgFX.
NormalMap = cgGetNamedEffectParameter(Effect, "NormalMap");
Services->setTexture( NormalMap,Material.TextureLayer[1],1 );
cgSetSamplerState(NormalMap);
IlluminationMap = cgGetNamedEffectParameter(Effect, "IlluminationMap");
Services->setTexture( IlluminationMap, Material.TextureLayer[2], 2);
cgSetSamplerState(IlluminationMap);
Ambient = cgGetNamedEffectParameter(Effect, "Ambient");
Services->setParameter1f(Ambient, 10.0);
}
private:
CGparameter pWVP;
CGparameter World;
CGparameter WorldIT;
CGparameter EyePosition;
CGparameter LightVec;
CGparameter DiffuseMap;
CGparameter NormalMap;
CGparameter IlluminationMap;
CGparameter Ambient;
};
Code: Select all
[100.0%] Linking executable: bin\2024.exe
obj\Engine\Graphics\Shaders\Cg\IrrCg.o:IrrCg.cpp:(.text+0x0): multiple definition of `irr::video::COpenGLTexture::getOpenGLTextureName() const'
obj\Engine\Graphics\COpenGLTexture.o:COpenGLTexture.cpp:(.text+0xa50): first defined here
obj\Engine\Graphics\Shaders\Cg\IrrCg.o:IrrCg.cpp:(.text+0x10): multiple definition of `irr::video::COpenGLDriver::setActiveTexture(unsigned int, irr::video::ITexture const*)'
obj\Engine\Graphics\COpenGLDriver.o:COpenGLDriver.cpp:(.text+0x1000): first defined here
obj\Engine\Graphics\Shaders\Cg\IrrCg.o:IrrCg.cpp:(.text+0x120): multiple definition of `irr::video::CD3D9Texture::getDX9Texture() const'
obj\Engine\Graphics\CD3D9Texture.o:CD3D9Texture.cpp:(.text+0xeb0): first defined here
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 7 seconds)
0 errors, 0 warnings
Build log saved as:
file://E:\Scartaris Engine\Client\Scartaris_build_log.html
oh, sorry..... im new in all this, especially in shadersrootroot1 wrote:This is really noob question!!!!!!!!!!!!!!!!!!!!
Go to http://developer.nvidia.com/object/cg_download.html
Download Cg toolkit
Then setup paths(include and libs) in yours VC IDE
Code: Select all
obj\main.o:main.cpp:(.text+0x384)||undefined reference to `IrrCg::ICgProgrammingServices::ICgProgrammingServices(irr::IrrlichtDevice*, bool, bool, CGenum)'|
obj\main.o:main.cpp:(.text+0x48d)||undefined reference to `IrrCg::ICgProgrammingServices::addCgShaderMaterialFromFiles(CGenum, char const*, char const*, char const*, char const*, char const*, char const*, char const*, char const*, IrrCg::ICgShaderConstantSetCallBack*, irr::video::E_MATERIAL_TYPE, char const**)'|
obj\main.o:main.cpp:(.text+0x549)||undefined reference to `IrrCg::ICgProgrammingServices::addCgShaderMaterialFromFiles(CGenum, char const*, char const*, char const*, char const*, char const*, char const*, char const*, char const*, IrrCg::ICgShaderConstantSetCallBack*, irr::video::E_MATERIAL_TYPE, char const**)'|
obj\main.o:main.cpp:(.text+0xecd)||undefined reference to `IrrCg::ICgProgrammingServices::~ICgProgrammingServices()'|
||=== Build finished: 4 errors, 0 warnings ===|