@Kimimaru wrote:
Hello all, I have an HLSL question for a DesktopGL project. I'm making a dialogue box like in the screenshot below:
All the text in black is associated with the box.
Text prints itself on the box, and when told to, has a prompt for progressing to the next set of text (the star on the lower right).
When that happens, all previous text is moved up (the "Hello World!"), and the next set of text gets printed. If it has already been printed - you can go back to previous text - it's simply shown by moving all the text down.
Basically, I need any text not in the box to be invisible. I decided that using a shader for this would work well, as I eventually need to use it to render the text with other special effects. My approach is to check the position of the pixels, and if they're out of the textbox bounds, clip them. However, I can't seem to get the position in the pixel shader.
Here's my shader:
#if OPENGL #define SV_POSITION POSITION #define VS_SHADERMODEL vs_3_0 #define PS_SHADERMODEL ps_3_0 #else #define VS_SHADERMODEL vs_5_0 #define PS_SHADERMODEL ps_5_0 #endif matrix WorldViewProjection; struct VertexShaderInput { float4 Position : POSITION0; float4 Color : COLOR0; }; struct VertexShaderOutput { float4 Position : SV_POSITION; float4 Color : COLOR0; float2 TextureCoordinates : TEXCOORD0; }; float YMin; float YMax; VertexShaderOutput MainVS(in VertexShaderInput input) { VertexShaderOutput output = (VertexShaderOutput)0; output.Position = mul(input.Position, WorldViewProjection); output.Color = input.Color; return output; } float4 MainPS(VertexShaderOutput input) : COLOR { //This is what I want to do //if (input.Position.y <= YMin || input.Position.y >= YMax) // clip(-1); return input.Color; } technique BasicColorDrawing { pass P0 { VertexShader = compile VS_SHADERMODEL MainVS(); PixelShader = compile PS_SHADERMODEL MainPS(); } };
I've read online that specifying the position with the VPOS semantic would work for shader model 3, but I get errors whenever I try using it for either the VertexShaderInput, VertexShaderOutput, or both. I even tried defining another float4 in the VertexShaderOutput and setting the Position to that, but it ended up clipping all of the pixels even when I set YMin and YMax to impossibly low/high values (-10,000 and 10,000, respectively).
I would greatly appreciate it if anyone can point me in the right direction for handling this. Thanks in advance!
Posts: 2
Participants: 2