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 8200141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:20:14+00:00 2026-06-07T06:20:14+00:00

there are three global variable g_A, g_B, g_C I want to do this; g_C

  • 0

there are three global variable g_A, g_B, g_C
I want to do this; g_C = g_A * g_B

I tried this;

technique RenderScene
{
    g_C = g_A * g_B;

    pass P0
    {          
        VertexShader = compile vs_2_0 RenderSceneVS();
        PixelShader  = compile ps_2_0 RenderScenePS(); 
    }
}

However, it’s improper syntax.
What should I do?

Must I calculate this variable in c++ code before rendering?

  • 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-06-07T06:20:18+00:00Added an answer on June 7, 2026 at 6:20 am

    DirectX 9 and 10 Effects support “preshaders”, where static expressions will be pulled out to be executed on the CPU automatically.

    See D3DXSHADER_NO_PRESHADER in the documentation, which is a flag that suppresses this behavior. Here’s a web link: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205441(v=vs.85).aspx

    Your declaration of g_C is missing both static and the type e.g. float. You’ll also need to move it into global scope.

    When you compile it with fxc, you might see something like the following (note the preshader block after the comment block):

    technique RenderScene
    {
        pass P0
        {
            vertexshader = 
                asm {
                //
                // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
                //
                // Parameters:
                //
                //   float4 g_A;
                //   float4 g_B;
                //
                //
                // Registers:
                //
                //   Name         Reg   Size
                //   ------------ ----- ----
                //   g_A          c0       1
                //   g_B          c1       1
                //
    
                    preshader
                    mul c0, c0, c1
    
                // approximately 1 instruction used
                //
                // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
                    vs_2_0
                    mov oPos, c0
    
                // approximately 1 instruction slot used
                };
    
            pixelshader = 
                asm {
                //
                // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
                    ps_2_0
                    def c0, 0, 0, 0, 0
                    mov r0, c0.x
                    mov oC0, r0
    
                // approximately 2 instruction slots used
                };
        }
    }
    

    I compiled the following:

    float4 g_A;
    float4 g_B;
    static float4 g_C = g_A * g_B;
    
    float4 RenderSceneVS() : POSITION
    {
        return g_C;
    }
    
    float4 RenderScenePS() : COLOR
    {
        return 0.0;
    }
    
    technique RenderScene
    {
        pass P0
        {          
            VertexShader = compile vs_2_0 RenderSceneVS();
            PixelShader  = compile ps_2_0 RenderScenePS();
        }
    }
    

    with fxc /Tfx_2_0 t.fx to generate the listing. They’re not very interesting shaders…

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

Sidebar

Related Questions

Is there anything similar to global variable in SSIS? I have 4 variables (FromAddress,
Is there any function / global variable in PHP that returns the current state
Isn't there another way of using global variables in a Java stlye manner in
In Ruby is there any method that lists all the global variables available at
In python, there is no way to differentiate between arguments, local variables, and global
Is there any way to use global int constants in Objective C that work
Is there a way to register for global mouse moved events in Cocoa? I
Is there a way to have different Global Configurations for each section of articles?
Is there a way to either suppress the generation of destructors for global objects
Is there any way to tell GCC to not initialize a particular global array

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.