Luke Evans
Luke Evans

Reputation: 93

Keyboard input to control pixel shader

    //pixelcolour with ambient
    //pixelcolour = vec4( textureshade*shadescale + ambient* textureshade+ textureshade*diffuseshadescale, 1.0 );   

    //ambient           
    pixelcolour += vec4(ambient*textureshade,1.0);

    //diffuse
    //pixelcolour += vec4(textureshade*diffuseshadescale, 1.0);

    //ambient && diffuse
    //pixelcolour += vec4( ambient* textureshade+ textureshade*diffuseshadescale, 1.0 );

    //ambient && specular
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + ambient* textureshade, 1.0 );

    //specular && diffuse
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + textureshade*diffuseshadescale , 1.0 );

    //ambient && specular && diffuse
    //shadescale= pow(dot(h,nn),shinyness);
    //pixelcolour += vec4 ( textureshade*shadescale + textureshade*diffuseshadescale + ambient*textureshade, 1.0);  

The above code uses different calculations to display lighting, in the pixel shader file I have. I need to control this from the keyboard, which needs to be declared in main and, for example, VK_A will cycle through the different modes I have. How do I go about implementing this?

How do you guys normally add keyboard controll to change this? Thank you

Upvotes: 0

Views: 460

Answers (2)

Nicolas Lefebvre
Nicolas Lefebvre

Reputation: 4282

An alternative to having multiple shaders would be to use a uniform in the shader to select between different code paths and to cycle the value of that uniform based on keyboard input.

Upvotes: 0

moonshadow
moonshadow

Reputation: 89065

Compile a separate version of the shader for each mode, either hand authoring them or using string manipulation to generate each set of source code.

In your application, keep track of the current mode and set the appropriate shader on the device, each frame, before rendering the affected geometry.

Is there some more specific issue you are encountering?

Upvotes: 1

Related Questions