Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3349814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:42:40+00:00 2026-05-18T01:42:40+00:00

I am using Nvidia CG and Direct3D9 and have the question about the following

  • 0

I am using Nvidia CG and Direct3D9 and have the question about the following code.

It compiles, but doesn’t “loads” (using cgLoadProgram wrapper) and the resulting failure is described simplyas D3D failure happened.

It’s a part of the pixel shader compiled with shader model set to 3.0

What may be interesting is that this shader loads fine in the following cases:

1) Manually unrolling the while statement (to many if { } statements).

2) Removing the line with the tex2D function in the loop.

3) Switching to shader model 2_X and manually unrolling the loop.


Problem part of the shader code:

float2 tex = float2(1, 1);
float2 dtex = float2(0.01, 0.01);

float h = 1.0 - tex2D(height_texture1, tex);
float height = 1.00;

while ( h < height )
{
    height -= 0.1;
    tex += dtex;

    // Remove the next line and it works (not as expected,
    // of course)
    h = tex2D( height_texture1, tex );
}

If someone knows why this can happen or could test the similiar code in non-CG environment or could help me in some other way, I’m waiting for you 😉

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:42:41+00:00Added an answer on May 18, 2026 at 1:42 am

    I think you need to determine the gradients before the loop using ddx/ddy on the texture coordinates and then use tex2D(sampler2D samp, float2 s, float2 dx, float2 dy)

    The GPU always renders quads not pixels (even on pixel borders – superfluous pixels are discarded by the render backend). This is done because it allows it to always calculate the screen space texture derivates even when you use calculated texture coordinates. It just needs to take the difference between the values at the pixel centers.

    But this doesn’t work when using dynamic branching like in the code in the question, because the shader processors at the individual pixels could diverge in control flow. So you need to calculate the derivates manually via ddx/ddy before the program flow can diverge.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with Nvidia's OpenCl/Cuda framework, but I think it is a
I'm using the following code in order to antialias only the edges of my
I'm generating two matrices using the following function (note some code is omitted): srand(2007);
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I was reading today about researchers discovering that NVidia's Phys-X libraries use x87 FP
Okay i have already been through most of the ati and nvidia guides to
using '#version 330 core' on NVIDIA, By using glBindAttribLocation(program, 0, in_Vertex); the input vertex
I'm on Ubuntu 11.10 using ghc version 7.0.3.20110330, running current-version updates of nvidia display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.