car paint glsl error material is gone

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
jiedi123
Posts: 6
Joined: Thu Dec 16, 2010 9:08 am

car paint glsl error material is gone

Post by jiedi123 »

car paint glsl error
material is gone ,is black
this is my shader coder
the shader is copy from "Dual Tone Car Shader With Fresnel And Sphere Mapping By Omaremad "

Code: Select all

//Vertex shader 

uniform vec3 fvLightPosition;
uniform vec3 fvEyePosition;

varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
//get this from irr (important for sphere mapping)
uniform mat4 matWorldInverseTranspose;
varying vec2 reflcoord;
void main( void )
{
   gl_Position = ftransform();
   Texcoord    = gl_MultiTexCoord0.xy;

   vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;

   ViewDirection  = fvEyePosition - fvObjectPosition.xyz;
   vec3 ViewDirectionn=normalize(ViewDirection);
   LightDirection = fvLightPosition - fvObjectPosition.xyz;
   Normal         = gl_NormalMatrix * gl_Normal;
   vec3 normal2=vec4(Normal,1)*matWorldInverseTranspose;

   vec3 fin=ViewDirectionn-(2*(dot(normalize(normal2),ViewDirectionn))*normal2);
   float p=sqrt(pow(fin.x,2)+pow(fin.y,2)+pow((fin.z+1),2));


   reflcoord=vec2(((fin.x/(2*p))+1/2),((fin.y/(2*p))+1/2));
}





//Fragment shader 

uniform vec4 fvLowTone;
uniform vec4 fvSpecular;
uniform vec4 fvHighTone;
uniform float fSpecularPower;

uniform sampler2D baseMap;

uniform sampler2D cube;
varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
varying vec2 reflcoord;
void main( void )
{
   vec3  fvLightDirection = normalize( LightDirection );
   vec3  fvNormal         = normalize( Normal );
   float fNDotL           = dot( fvNormal, fvLightDirection );

   vec3  fvReflection     = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection );
   vec3  fvViewDirection  = normalize( ViewDirection );
   float fRDotV           = max( 0.0, dot( fvReflection, fvViewDirection ) );

   vec4  fvBaseColor      = texture2D( baseMap, Texcoord );

   vec4  fvTotalAmbient   = fvLowTone * fvBaseColor;
   vec4  fvTotalDiffuse   = fvHighTone * (fNDotL) * fvBaseColor;
   vec4  fvTotalSpecular  = fvSpecular * ( pow( fRDotV, fSpecularPower ) );
   float fresnel =(1/dot( Normal, fvViewDirection) )/5;
   gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular )+(fresnel*texture2D(cube,reflcoord))+(fresnel /2);

}
my c++ code
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
invWorld.makeInverse();
services->setVertexShaderConstant("matWorldInverseTranspose", invWorld.pointer(), 16);
}
Image
:shock:
jiedi123
Posts: 6
Joined: Thu Dec 16, 2010 9:08 am

Post by jiedi123 »

who can help me :cry:
TCM
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Post by TCM »

You are not passing all the variables to the shader.

I only see matWorldInverseTranspose.

But the vertex shader also uses :

Code: Select all

uniform vec3 fvLightPosition;
uniform vec3 fvEyePosition; 
and the fragment shader :

Code: Select all

uniform vec4 fvLowTone;
uniform vec4 fvSpecular;
uniform vec4 fvHighTone;
uniform float fSpecularPower;
uniform sampler2D baseMap;
uniform sampler2D cube;  
Add the code to support these.
Post Reply