Jump to content
  • Advertisement
Sign in to follow this  
axon

OpenGL Textures not working (CgFX + OpenGL): draws black silhoette (works ok in FXComposer)

This topic is 3770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, My first CgFX application is giving me trouble. I've managed to get some very simple shaders working but am having a lot of trouble passing textures to it. I'm trying to make use of existing libs (namely NVidia's nv::Image for loading the image data from file). The shader works fine in FX Composer (2.5b). The code is clean enough and should be logging all errors (using 'cgGetLastErrorString()' and 'glGetError()' etc). Shading appears is ok when I don't use the texture. But as soon as the texture is used, the CgFX shader compiles without warning and runs without error... but the test sphere I'm trying to draw is a black circle (which my arcball manipulator spins without any trouble). Can anyone suggest why when I use the following code all I see is a black circle? I've been chipping away at this for days (i hate to admit though it's becoming weeks...). can someone please put me out of my misery... even if it looks ok... any opinions/suggestions much a appreciated.
// simpleTextured.cgfx

// This is C2E1v_green from "The Cg Tutorial" (Addison-Wesley, ISBN
// 0321194969) by Randima Fernando and Mark J. Kilgard.  See page 38.

float4x4 modelViewProj : WorldViewProjection < string UIWidget="None"; >; 

float3 globalAmbient : Ambient    = { 0.1, 0.1, 0.1 };
float3 lightColor : Specular <
    string UIName =  "Lamp 0";
    string Object = "Pointlight0";
    string UIWidget = "Color";
> = {1.0f,1.0f,1.0f};
float3 lightPosition : Position <
    string Object = "PointLight0";
    string UIName =  "Lamp 0 Position";
    string Space = "World";
> = {0.81,-3.65,5};
float3 eyePosition   : Position   = { 0, 0, 13 };
float3 Ke : Emissive < string UIWidget = "Color"; > = {0.0, 0.0, 0.0};
float3 Ka : Ambient  = {0.0, 0.0, 0.0};
float3 Kd : Diffuse  = {0.5, 0.0, 0.0};
float3 Ks < string UIWidget = "Color"; > = {0.7, 0.6, 0.6};
float  shininess <
    string UIWidget = "slider";
    float UIMin = 0.0;
    float UIMax = 100.0;
    float UIStep = 1.0;
    string UIName =  "Specular";
> = 32.0;


//////// COLOR & TEXTURE /////////////////////

texture ColorTexture  <
    string ResourceName = "default_color.dds";
    string UIName =  "Diffuse Texture";
    string ResourceType = "2D";
>;

sampler2D ColorSampler = sampler_state {
    Texture = <ColorTexture>;
    MinFilter = LinearMipMapLinear;
    MagFilter = Linear;
    WrapS = Repeat;
    WrapT = Repeat;
};  
  
// This is C5E2v_fragmentLighting from "The Cg Tutorial" (Addison-Wesley, ISBN
// 0321194969) by Randima Fernando and Mark J. Kilgard.  See page 124.

void main(float4 position : POSITION,
             float3 normal   : NORMAL,
             float2 uv : TEXCOORD0,
             out float4 oPosition : POSITION,
             out float2 oUV : TEXCOORD0,
             out float3 objectPos : TEXCOORD1,
             out float3 oNormal   : TEXCOORD2)
{
	oPosition = mul(modelViewProj, position);
	objectPos = position.xyz;
	oNormal = normal;
    oUV = uv;
}

// This is C5E3f_basicLight from "The Cg Tutorial" (Addison-Wesley, ISBN
// 0321194969) by Randima Fernando and Mark J. Kilgard.  See page 125.

void psLight(float4 position  : TEXCOORD0,
             float2 uv : TEXCOORD1,
             float3 normal    : TEXCOORD2,
             out float4 color     : COLOR)
{
  float3 P = position.xyz;
  float3 N = normalize(normal);

  // Compute emissive term
  float3 emissive = Ke;

  // Compute ambient term
  float3 ambient = Ka * globalAmbient;

  // Compute the diffuse term
  float3 L = normalize(lightPosition - P);
  //float diffuseLight = max(dot(L, N), 0);
  float3 diffuseLight = tex2D(ColorSampler, uv) + max(dot(L, N), 0);
  float3 diffuse = Kd * lightColor * diffuseLight;

  // Compute the specular term
  float3 V = normalize(eyePosition - P);
  float3 H = normalize(L + V);
  float specularLight = pow(max(dot(H, N), 0), shininess);
  if (diffuseLight <= 0) specularLight = 0;
  float3 specular = Ks * lightColor * specularLight;

  color.xyz = emissive + ambient + diffuse + specular;
  color.w = 1;
}

technique NewTechnique <
	string Script = "Pass=p0;";
> {
    pass p0 <
	string Script = "Draw=geometry;";
    > {
        VertexProgram = compile vp40 main();
		DepthTestEnable = true;
		DepthMask = true;
		CullFaceEnable = false;
		BlendEnable = false;
		DepthFunc = LEqual;
        FragmentProgram = compile fp40 psLight();
    }
}






//  Initialize() CPP

    cgContext = cgCreateContext();
    LOG_CG("cgCreateContext", cgContext);
    cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
    cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
    cgGLSetOptimalOptions(cgVertexProfile);
    cgGLSetOptimalOptions(cgFragmentProfile);
    LOG_CG("cgGLSetOptimalOptions", cgContext);
    LOG("Cg Vertex Profile:   " << cgGetProfileString(cgVertexProfile));
    LOG("Cg Fragment Profile: " << cgGetProfileString(cgFragmentProfile));

    PathResolver pathResolver("");
    //const std::string cgFXFile = "phong.cgfx";
    //const std::string cgFXFile = "green.cg";
    //const std::string cgFXFile = "vertlight.cgfx";
    const std::string cgFXFile = "blinn.cgfx";
    std::string resolvedCgFXFile = "";
    if (pathResolver.getFilePath(cgFXFile, resolvedCgFXFile))
    {
        cgProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, resolvedCgFXFile.c_str(), cgVertexProfile, "main", 0);
        LOG_CG("cgCreateProgramFromFile(" << resolvedCgFXFile << ")", cgContext);
    }
    else
        LOG_ERROR("File not found: " << cgFXFile);

    const std::string modelFile = "cow.obj";
    std::string resolvedModelFile = "";
    if (pathResolver.getFilePath(modelFile, resolvedModelFile))
        model = Utils::LoadModel(resolvedModelFile.c_str(), &modelBBMin, &modelBBMax);
    else
        LOG_ERROR("File not found: " << modelFile);

    cgGLLoadProgram(cgProgram);
    LOG_CG("cgGLLoadProgram", cgContext);

    if(cgProgram == 0)
    {
        LOG_ERROR("Invalid Cg program. This program will now exit...");
        exit(1);
    }

    cgGLRegisterStates(cgContext); 
    LOG_CG("cgGLRegisterStates", cgContext);
    cgGLSetManageTextureParameters(cgContext, CG_TRUE); 
    LOG_CG("cgGLSetManageTextureParameters", cgContext);
    cgEffect = cgCreateEffectFromFile(cgContext, resolvedCgFXFile.c_str(), NULL); 
    LOG_CG("cgCreateEffectFromFile(" << resolvedCgFXFile << ")", cgContext);

    cgTechnique = cgGetFirstTechnique(cgEffect);
    while (cgTechnique && cgValidateTechnique(cgTechnique) == CG_FALSE) 
    {
        LOG_ERROR("Technique '" << cgGetTechniqueName(cgTechnique) << "' did not validate");
        cgTechnique = cgGetNextTechnique(cgTechnique);
    }
    
    LOG_CG("CG Techniques initialise", cgContext);

    if (cgTechnique) {
        LOG("Using Cg technique '" << cgGetTechniqueName(cgTechnique) << "' from '" << cgFXFile << "'.");
    } else {
        LOG_ERROR("Valid Cg Technique not found");
    }

    // Load the texture (if needed)
    CGparameter param = cgGetNamedParameter(cgProgram, "ColorSampler");
    LOG_CG("cgGetNamedParameter", cgContext);
    if (param != 0) {
        cgGLEnableTextureParameter(param);

        image = new nv::Image();
        const std::string texFile = "Default_color.dds";
        std::string resolvedTexFile = "";
        if (!(pathResolver.getFilePath(texFile, resolvedTexFile) && 
              image->loadImageFromFile(resolvedTexFile.c_str())))
            LOG_ERROR("File not found: " << texFile);

        LOG("Texture loaded (" << resolvedTexFile << ")");

        GLuint texName;    
        glGenTextures(1, &texName);
        glBindTexture(GL_TEXTURE_2D, texName);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	    glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
        glTexImage2D( GL_TEXTURE_2D, 0, image->getInternalFormat(), image->getWidth(), image->getHeight(), 0, image->getFormat(), image->getType(), image->getLevel(0));
        LOG_OGL("glTexImage2D()");

        cgGLSetTextureParameter(param, texName);
        LOG_CG("cgGLSetTextureParameter(param, texName)", cgContext);
    }
    else
        LOG("WARNING: No texture parameter found. Expecting 'sampler2D ColorSampler'.");

    cgGLEnableProfile(cgVertexProfile);
    cgGLEnableProfile(cgFragmentProfile);






//  Display() in CPP
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    manipulator.applyTransform();

    CGparameter param = 0;
    param = cgGetEffectParameterBySemantic(cgEffect, "WorldViewProjection");
    if (param != 0)
        cgGLSetStateMatrixParameter(param, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
    LOG_CG("cgGLSetStateMatrixParameter(WorldViewProjection)", cgContext);

    cgGLBindProgram(cgProgram);
    CGpass pass = cgGetFirstPass(cgTechnique);
    while (pass) {
        cgSetPassState(pass);

        //DrawModel(model, modelBBMin, modelBBMax);
        glutSolidSphere(0.5, 8, 8);
        cgResetPassState(pass);
        pass = cgGetNextPass(pass);
    }
    glutSwapBuffers();






[Edited by - axon on June 16, 2008 12:40:29 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well like you may have gathered from my other thread you replied to, my understanding of Cg is not great, but theres something there I have never seen before: you don't pass the sampler2D into the pixel shader, you access it globally. I didn't know this was possible! Maybe you could try:

void psLight(float4 position : TEXCOORD0,
float2 uv : TEXCOORD1,
float3 normal : TEXCOORD2,
uniform sampler2D : colorSampler,
out float4 color : COLOR)
{
...
float3 diffuseLight = tex2D(colorSampler, uv) + max(dot(L, N), 0);
...
}

technique NewTechnique <
string Script = "Pass=p0;";
> {
pass p0 <
string Script = "Draw=geometry;";
> {
VertexProgram = compile vp40 main();
DepthTestEnable = true;
DepthMask = true;
CullFaceEnable = false;
BlendEnable = false;
DepthFunc = LEqual;
FragmentProgram = compile fp40 psLight(ColorSampler);
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by bluntman
Well like you may have gathered from my other thread you replied to, my understanding of Cg is not great, but theres something there I have never seen before: you don't pass the sampler2D into the pixel shader, you access it globally. I didn't know this was possible! Maybe you could try:
*** Source Snippet Removed ***

Thanks for the suggestion. Unfortunately what you've noticed is one of the differences between Cg and CgFX. In Cg you pass samplers and other variables to the shader methods as uniforms. In CgFX you can (should?/must?) declare them as globals. (I just had a look at a few FXComposer shaders and they're all handling the sampler in the same way as the above code.)

Any other suggestions?
Maybe my OpenGL code is wrong? (I worked from the latest OpenGL Bible (6th ed) but I guess I could still have missed something???

Share this post


Link to post
Share on other sites
Well I am using CgFx in my current project and I pass everything as uniforms from the globals. It makes more sense that way, what if your vertex and fragment shaders are in different source files? I don't think CgFx resolves like that. I have never used FxComposer, but all the CgFx examples I have seen, including those in the Cg 2.0 users manual show all variables passed as uniforms. e.g. page 123 from the CgUsersManual.pdf that comes with the Cg2.0 SDK.

Share this post


Link to post
Share on other sites
Just gave it a try using the following shader but I get the same result.

/*********************************************************************NVMH3****
$Revision$

Copyright NVIDIA Corporation 2007
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY
LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


To learn more about shading, shaders, and to bounce ideas off other shader
authors and users, visit the NVIDIA Shader Library Forums at:

http://developer.nvidia.com/forums/

******************************************************************************/


// #define FLIP_TEXTURE_Y

float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "object";
string ScriptOrder = "standard";
string ScriptOutput = "color";
string Script = "Technique=Main;";
> = 0.8;

//// UN-TWEAKABLES - AUTOMATICALLY-TRACKED TRANSFORMS ////////////////

float4x4 WorldITXf : WorldInverseTranspose < string UIWidget="None"; >;
float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >;
float4x4 WorldXf : World < string UIWidget="None"; >;
float4x4 ViewIXf : ViewInverse < string UIWidget="None"; >;

//// TWEAKABLE PARAMETERS ////////////////////

/// Point Lamp 0 ////////////
float3 Lamp0Pos : Position <
string Object = "PointLight0";
string UIName = "Lamp 0 Position";
string Space = "World";
> = {-0.5f,2.0f,1.25f};
float3 Lamp0Color : Specular <
string UIName = "Lamp 0";
string Object = "Pointlight0";
string UIWidget = "Color";
> = {1.0f,1.0f,1.0f};

// Ambient Light
float3 AmbiColor : Ambient <
string UIName = "Ambient Light";
string UIWidget = "Color";
> = {0.07f,0.07f,0.07f};

float Ks <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 1.0;
float UIStep = 0.05;
string UIName = "Specular";
> = 0.4;

float Eccentricity <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 1.0;
float UIStep = 0.0001;
string UIName = "Highlight Eccentricity";
> = 0.3;


//////// COLOR & TEXTURE /////////////////////

texture ColorTexture <
string ResourceName = "default_color.dds";
string UIName = "Diffuse Texture";
string ResourceType = "2D";
>;

sampler2D ColorSampler = sampler_state {
Texture = <ColorTexture>;
MinFilter = LinearMipMapLinear;
MagFilter = Linear;
WrapS = Repeat;
WrapT = Repeat;
};

//
// #define this macro to permit the import and use of shared shadow
// maps created by COLLADA-FX. Make sure that the macro is defined
// and the code recompile *before* executing "Convert to Collada-FX"!
//
// #define USE_SHARED_SHADOW

#ifdef USE_SHARED_SHADOW
#include "include/shadowMap.cgh"
DECLARE_SHADOW_XFORMS("SpotLight0",LampViewXf,LampProjXf,ShadowViewProjXf)
DECLARE_SHADOW_BIAS
DECLARE_SHADOW_MAPS(ColorShadTarget,ColorShadSampler,DepthShadTarget,DepthShadSampler)

float ShadDens <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 1.0;
float UIStep = 0.01;
string UIName = "Shadow Density";
> = 0.7;
#endif /* USE_SHARED_SHADOW */


//////// CONNECTOR DATA STRUCTURES ///////////

/* data from application vertex buffer */
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};

/* data passed from vertex shader to pixel shader */
struct vertexOutput {
float4 HPosition : POSITION;
float2 UV : TEXCOORD0;
// The following values are passed in "World" coordinates since
// it tends to be the most flexible and easy for handling
// reflections, sky lighting, and other "global" effects.
float3 LightVec : TEXCOORD1;
float3 WorldNormal : TEXCOORD2;
float3 WorldTangent : TEXCOORD3;
float3 WorldBinormal : TEXCOORD4;
float3 WorldView : TEXCOORD5;
#ifdef USE_SHARED_SHADOW
// This optional value expresses the current location in "light"
// coordinates for use with shadow mapping.
float4 LProj : LPROJ_COORD;
#endif /* USE_SHARED_SHADOW */
};

///////// VERTEX SHADING /////////////////////

/*********** Generic Vertex Shader ******/

vertexOutput main(appdata IN) {
vertexOutput OUT = (vertexOutput)0;
OUT.WorldNormal = mul(WorldITXf,IN.Normal).xyz;
OUT.WorldTangent = mul(WorldITXf,IN.Tangent).xyz;
OUT.WorldBinormal = mul(WorldITXf,IN.Binormal).xyz;
float4 Po = float4(IN.Position.xyz,1);
float3 Pw = mul(WorldXf,Po).xyz;
OUT.LightVec = (Lamp0Pos - Pw);
#ifdef FLIP_TEXTURE_Y
OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
#else /* !FLIP_TEXTURE_Y */
OUT.UV = IN.UV.xy;
#endif /* !FLIP_TEXTURE_Y */
#ifdef USE_SHARED_SHADOW
float4 Pl = mul(ShadowViewProjXf,Pw); // "P" in light coords
float4x4 BiasXf = make_bias_mat(ShadBias);
OUT.LProj = mul(BiasXf,Pl); // bias to make texcoord
#endif /* USE_SHARED_SHADOW */
OUT.WorldView = normalize(float3(ViewIXf[0].w,ViewIXf[1].w,ViewIXf[2].w) - Pw);
OUT.HPosition = mul(WvpXf,Po);
return OUT;
}

///////// PIXEL SHADING //////////////////////

// Utility function for blinn shading

void blinn_shading(vertexOutput IN,
float3 LightColor,
float3 Nn,
float3 Ln,
float3 Vn,
uniform sampler2D colorSampler,
out float3 DiffuseContrib,
out float3 SpecularContrib)
{
float3 Hn = normalize(Vn + Ln);
float hdn = dot(Hn,Nn);
float3 R = reflect(-Ln,Nn);
float rdv = dot(R,Vn);
rdv = max(rdv,0.001);
float ldn=dot(Ln,Nn);
ldn = max(ldn,0.0);
float ndv = dot(Nn,Vn);
float hdv = dot(Hn,Vn);
float eSq = Eccentricity*Eccentricity;
float distrib = eSq / (rdv * rdv * (eSq - 1.0) + 1.0);
distrib = distrib * distrib;
float Gb = 2.0 * hdn * ndv / hdv;
float Gc = 2.0 * hdn * ldn / hdv;
float Ga = min(1.0,min(Gb,Gc));
float fresnelHack = 1.0 - pow(ndv,5.0);
hdn = distrib * Ga * fresnelHack / ndv;
DiffuseContrib = ldn * LightColor;
SpecularContrib = hdn * Ks * LightColor;
}

float4 std_PS(vertexOutput IN,
uniform sampler2D colorSampler) : COLOR {
float3 diffContrib;
float3 specContrib;
float3 Ln = normalize(IN.LightVec);
float3 Vn = normalize(IN.WorldView);
float3 Nn = normalize(IN.WorldNormal);
blinn_shading(IN,Lamp0Color,Nn,Ln,Vn,colorSampler,diffContrib,specContrib);
float3 diffuseColor = tex2D(ColorSampler,IN.UV).rgb;
#ifdef USE_SHARED_SHADOW
float shadowed = tex2Dproj(DepthShadSampler,IN.LProj).x;
float faded = 1.0-(ShadDens*(1.0-shadowed));
diffContrib *= faded;
specContrib *= shadowed;
#endif /* USE_SHARED_SHADOW */
float3 result = specContrib+(diffuseColor*(diffContrib+AmbiColor));
// return as float4
return float4(result,1);
}

///// TECHNIQUES /////////////////////////////

technique Main <
string Script = "Pass=p0;";
> {
pass p0 <
string Script = "Draw=geometry;";
> {
VertexProgram = compile vp40 main();
DepthTestEnable = true;
DepthMask = true;
CullFaceEnable = false;
BlendEnable = false;
DepthFunc = LEqual;
FragmentProgram = compile fp40 std_PS(ColorSampler);
}
}

/////////////////////////////////////// eof //



I also tried setting the texParam explicitely per-frame (in Display()) but alas... no joy :(

Share this post


Link to post
Share on other sites
You say when you try and render with the texture the sphere appears as a black circle? Do you mean completely black, from all angles, i.e. no specular or ambient? If it was just the texture that was not being set correctly then I would still expect to see specular.
Are you sure glutSphere function generates UVs? Maybe you need to enable automatic texture coord generation?

Share this post


Link to post
Share on other sites
You're right, the specular term should be there but it isn't. The sphere is absolute black when viewed from every direction. Well spotted :)

So maybe it isn't the ColourSampler (or possibly even nothing to do with the texture)?

Looks like it could be the transforms after all.

Share this post


Link to post
Share on other sites
What happens when you keep everything the same but remove the texture diffuse component from the final calculation?
like:
float3 diffuse = Kd * lightColor;
instead of:
float3 diffuse = Kd * lightColor * diffuseLight;
The only way I can think of that the a problem with the texture could cause the final colour to always be completely black is if there is a NaN value getting in there somewhere, but afaik if the texture is not set then it will return zeros not NaNs.

Share this post


Link to post
Share on other sites
Hi Axon, I saw your post on the NVIDIA forums.

I'm having similar issues, with probably the world's simplest CgFX shader. At first I thought it was a problem using Cg with Qt, but turns out it isn't.

Try using this as a test:


float4 Diffuse : COLOR
<
string UIWidget = "Color";
string UIName = "Diffuse";
> = {0.8f, 0.8f, 0.8f, 1.0f};

sampler2D DiffuseSampler = sampler_state
{
MinFilter = LinearMipMapLinear;
};

float4x4 WorldViewProj : WORLDVIEWPROJECTION;

struct VInput
{
float4 Position : POSITION;
float4 Colour : COLOR0;
float2 UVCoord : TEXCOORD0;
};

struct VOutput
{
float4 Position : POSITION;
float4 Colour : COLOR0;
float2 UVCoord : TEXCOORD0;
};


VOutput VShader(VInput IN)
{
//Create output object
VOutput OUT;

//Calculate output position
OUT.Position = mul(WorldViewProj, IN.Position);

OUT.UVCoord = IN.UVCoord;
OUT.Colour = Diffuse;

return OUT;
}

float4 PShader(VOutput IN) : COLOR
{
return tex2D(DiffuseSampler, IN.UVCoord);;
}

technique Main
{
pass p0
{
VertexProgram = compile vp40 VShader();

DepthTestEnable = true;
DepthMask = true;
CullFaceEnable = true;
BlendEnable = false;
DepthFunc = LEqual;

FragmentProgram = compile fp40 PShader();
}
}



Let's see if we can sort this out, there must be a common problem with our code, see mine here for reference: http://www.gamedev.net/community/forums/topic.asp?topic_id=497585

Share this post


Link to post
Share on other sites
Hi deadstar.

Just read your thread. Maaaaan. I feel your pain!
We're in the same boat... let's make it float.

I've had this problem for, I hate to admit it, possibly over 2 months.

I'm supposed to be good at this gear. I am good at this gear. I've read a lot of documentation including the thin PDF examples (which do all kinds of non-conventional stuff w.r.t geometry and textures) combed the PDFs. The SDK samples (both Cg/Cg-toolkit SDK and NV OpenGL SDK) and re-created some of their demos.

So where are we up to?:
1. Transforms and verts are ok. (Since your shader in the prev post uses only WorldViewProj and renders black geometry ok).
2. Shader is ok. Works in FXComposer (after you add the Texture param so that FXComposer can hook in (that could be a clue... but none of the demos seem to need to touch the Texture param)).
3. UVs are ok. (Since tex2D(sampler, float2(0.5,0.5)) returns green (center pix color of texture) in FXComposer but returns black in my app.)

I'm tempted to grab their CgFX bumdemo and start to piecewise convert it.
Step 1: Convert it to use own geom and test
Step 2: Convert it to use own tex and test
Step 3: Convert it to use own CgFX and test

Theoretically that can't go wrong... it's be great to think the solution is closer than that (since i've already done similar approaches before).

Or is it something curlier like we're linking against beta dlls at run-time???

I'll def keep this post updated... glad not to be alone on this one. I have tried for so long to figure it out methodically (as you obviously have) and yet here we are.

EDIT:
@bluntman: I rekon deadstar's shader distills the problem down. tex2D(sampler, uv) returns zeros (black) when it should look up the texture. I've also tested tex2D(sampler, float2(0.5,0.5)) and in FXComposer it returns green (from center of texture) and in my app it returns black.

[Edited by - axon on June 17, 2008 10:22:35 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!