Outline v2


#41

Does it have a different MatSpecColor value?


#42

Ahh yes.

Stone.xml

<material>
    <technique name="Techniques/DiffNormal.xml" quality="1" />
    <technique name="Techniques/Diff.xml" quality="0" />
    <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
    <texture unit="normal" name="Textures/StoneNormal.dds" />
    <shader psdefines="PACKEDNORMAL" />
    <parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
</material>

I’ve got the PBR materials sample working without error … just wanted to add a bit of hope.

Also tried with jack:

<material>
    <technique name="Techniques/DiffOutline.xml" />
    <parameter name="MatSpecColor" value="0.5 0.5 0.5 16" />
  <texture unit="diffuse" name="Textures/Smoke.dds" />
  <parameter name="OutlineBlurredMaskHInvSize" value="1 1" />
  <parameter name="OutlineWidth" value="0.2" />
  <parameter name="OutlineColor" value=".5 .5 .5 1" />
</material>

And finally, with a cone:


#43

How this should look with the HLSL shader:


#44

What’s checked in looks different. Is the semicolon supposed to be there at the end of the line?

I’ve been trying to figure out why this won’t work for me. And getting some errors now:

4:)  [Fri Feb  8 12:10:35 2019] ERROR: Failed to compile vertex shader Outline():
..\Shaders\HLSL\Outline.hlsl(1,1): error X3000: Illegal character in shader file

4:)  [Fri Feb  8 12:10:35 2019] ERROR: Failed to compile pixel shader Outline(BLURH):
..\Shaders\HLSL\Outline.hlsl(1,1): error X3000: Illegal character in shader file

4:)  [Fri Feb  8 12:10:35 2019] ERROR: Failed to compile pixel shader Outline(BLURV):
..\Shaders\HLSL\Outline.hlsl(1,1): error X3000: Illegal character in shader file

4:)  [Fri Feb  8 12:10:35 2019] ERROR: Failed to compile pixel shader Outline(OUTPUT):
..\Shaders\HLSL\Outline.hlsl(1,1): error X3000: Illegal character in shader file

Those errors were due to creating the file in Visual Studio. So deleted that file, and use VSCode to create and then added into the solution. The compile errors when away.


#45

@Miegamicis What you pasted in there is also not following the glsl shader above it.

What you have checked in, has that extra semicolon at the end of the line in two places. Otherwise, it looks like the initial glsl shader except as noted in next posts.

Am referring to this glsl from above:


#46

Also, you used iScreenPos, and according to GLSL version, that should be iTexCoord.

Here.

And this line makes it all disappear, when I run it.


#47

I actually tried both, bur iScreenPos looked a lot better when I was running some tests. But maybe my testing was bad, since I’m kinda unexperienced with shaders.


#48

Certainly you’re more experienced than I. But I do try …

I’m making some progress. Have the outline painting now, but when it does, then the main material doesn’t paint.

Here’s the shader I’m using:

#include "Uniforms.hlsl"
#include "Samplers.hlsl"
#include "Transform.hlsl"
#include "ScreenPos.hlsl"
#include "PostProcess.hlsl"

#ifdef COMPILEPS
	uniform float4 cOutlineColor;
	uniform float2 cOutlineBlurredMaskHInvSize;
	uniform bool cOutlineEnable;
#endif

void VS(float4 iPos : POSITION,
	out float2 oTexCoord : TEXCOORD0,
	out float2 oScreenPos : TEXCOORD1,
	out float4 oPos : OUTPOSITION)
{
	float4x3 modelMatrix = iModelMatrix;
	float3 worldPos = GetWorldPos(modelMatrix);
	oPos = GetClipPos(worldPos);
	oTexCoord = GetQuadTexCoord(oPos);
	oScreenPos = GetScreenPosPreDiv(oPos);
}

void PS(
	float3 iTexCoord : TEXCOORD0,
	float2 iScreenPos : TEXCOORD1,
	out float4 oColor : OUTCOLOR0)
{
#ifdef MASK
	if (!cOutlineEnable) discard;
	oColor = float4(cOutlineColor.rgb, 1);
#endif
#ifdef BLURH
	float4 rgba = Sample2D(DiffMap, iTexCoord + float2(0.0, 0.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(-1.0, 0.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(1.0, 0.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(-2.0, 0.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(2.0, 0.0) * cOutlineBlurredMaskHInvSize);
	oColor = rgba * 0.2;
#endif

#ifdef BLURV
	float4 rgba = Sample2D(DiffMap, iTexCoord + float2(0.0, 0.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(0.0, -1.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(0.0, 1.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(0.0, -2.0) * cOutlineBlurredMaskHInvSize);
	rgba += Sample2D(DiffMap, iTexCoord + float2(0.0, 2.0) * cOutlineBlurredMaskHInvSize);
	oColor = rgba * 0.2;
#endif
#ifdef OUTPUT
	float4 blurredMask = Sample2D(DiffMap, iTexCoord);
	float4 mask = Sample2D(NormalMap, iTexCoord);
	float4 viewport = Sample2D(SpecMap, iTexCoord);
	blurredMask = clamp(blurredMask - mask.a, 0.0, 1.0);
	blurredMask *= 3.0;
	oColor = viewport * (1.0 - blurredMask.a) + blurredMask;
#endif
}

Here’s the material being used:

<material>
  <technique name="Techniques/DiffOutline.xml" />
  <parameter name="MatDiffColor" value=".5 .5 .5 1" />>
  <parameter name="MatSpecColor" value="0.3 0.3 0.3 16" />
  <texture unit="diffuse" name="Textures/StoneDiffuse.dds" />
  <texture unit="normal" name="Textures/StoneNormal.dds" />
  <parameter name="OutlineWidth" value="0.1" />
  <parameter name="OutlineColor" value=".5 .5 .8 1" />
  <parameter name="OutlineEnable" value="true" />
</material>

Here’s the technique being used:

<technique vs="LitSolid" ps="LitSolid" psdefines="DIFFMAP">
  <pass name="base" />
  <pass name="litbase" psdefines="AMBIENT" />
  <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
  <pass name="prepass" psdefines="PREPASS" />
  <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />
  <pass name="deferred" psdefines="DEFERRED" />
  <pass name="depth" vs="Depth" ps="Depth" />
  <pass name="shadow" vs="Shadow1" ps="Shadow1" />
  <pass name="outline" vs="Outline" ps="Outline" psdefines="MASK" depthtest="always" depthwrite="false" />
</technique>

Here’s the rendererer, called Outline.xml:

<renderpath>
  <rendertarget name="outlineMask" sizedivisor="1 1" format="rgba" filter="true" />
  <rendertarget name="outlineBlurredMaskH" sizedivisor="2 2" format="rgba" filter="true" />
  <rendertarget name="outlineBlurredMaskV" sizedivisor="2 2" format="rgba" filter="true" />
  <command type="clear" color="fog" depth="1.0" stencil="0" />
  <command type="clear" color="0 0 0 0" output="outlineMask" />
  <command type="scenepass" pass="base" vertexlights="true" metadata="base" />
  <command type="forwardlights" pass="light" />
  <command type="scenepass" pass="postopaque" />
  <command type="scenepass" pass="refract">
    <texture unit="environment" name="viewport" />
  </command>
  <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
  <command type="scenepass" pass="postalpha" sort="backtofront" />
  <command type="scenepass" pass="outline" output="outlineMask" sort="backtofront" />
  <command type="quad" vs="Outline" ps="Outline" psdefines="BLURH" output="outlineBlurredMaskH">
    <texture unit="diffuse" name="outlineMask" />
  </command>
  <command type="quad" vs="Outline" ps="Outline" psdefines="BLURV" output="outlineBlurredMaskV">
    <texture unit="diffuse" name="outlineBlurredMaskH" />
  </command>
  <command type="quad" vs="Outline" ps="Outline" psdefines="OUTPUT" output="viewport">
    <texture unit="diffuse" name="outlineBlurredMaskV" />
    <texture unit="normal" name="outlineMask" />
    <texture unit="specular" name="viewport" />
  </command>
</renderpath>

Here are changes to the default render path, which by default only uses ‘Forward’.

var rp = ((StereoApplication)Application).Renderer.DefaultRenderPath.Clone();
rp.SetEnabled("Forward", false);
rp.Append(Application.ResourceCache.GetXmlFile("RenderPaths/Outline.xml"));
((StereoApplication)Application).Renderer.GetViewport(0).RenderPath = rp;
((StereoApplication)Application).Renderer.GetViewport(1).RenderPath = rp;

The two viewports are for the stereo rendering used by hololens, the platform used here.

Screen shot:

The following log outputs are printed:

1:)  [Fri Feb  8 16:39:35 2019] DEBUG: Good cleanup, new GameNode being returned
1:)  [Fri Feb  8 16:39:35 2019] DEBUG: Loading resource RenderPaths/Outline.xml
1:)  [Fri Feb  8 16:39:35 2019] DEBUG: Loading resource Models/Cylinder.mdl
1:)  [Fri Feb  8 16:39:35 2019] DEBUG: Loading resource Materials/StoneOutline.xml
1:)  [Fri Feb  8 16:39:35 2019] DEBUG: Loading resource Techniques/DiffOutline.xml
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 1268x720 format 28
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 1268x720 format 28
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 1268x720 format 28
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 634x360 format 28
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 634x360 format 28
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled vertex shader LitSolid(DIRLIGHT PERPIXEL)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled pixel shader LitSolid(AMBIENT DIFFMAP DIRLIGHT PACKEDNORMAL PERPIXEL SPECULAR)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled vertex shader LitSolid(PERPIXEL POINTLIGHT)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled pixel shader LitSolid(DIFFMAP PACKEDNORMAL PERPIXEL POINTLIGHT SPECULAR)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled vertex shader LitSolid(NOUV PERPIXEL POINTLIGHT)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Compiled pixel shader LitSolid(PERPIXEL POINTLIGHT)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Allocated new screen buffer size 634x360 format 44
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Loading resource Shaders/HLSL/Outline.hlsl
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Loaded cached vertex shader Outline()
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Loaded cached pixel shader Outline(BLURH)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Loaded cached pixel shader Outline(BLURV)
1:)  [Fri Feb  8 16:39:38 2019] DEBUG: Loaded cached pixel shader Outline(OUTPUT)

#49

This is the way it looked before adding the outline, with files I’m using.

Just comparing the two pics, it sort off looks like the outline coloring is the same as the material coloring in the photo, so it wouldn’t be seen. Though it is specified to be different.

In that previous pic above, also note the cursor is no longer visible, the cyan torus.

Also in the previous pic, each cylinder is transparent/black and not see through. Farther cylinders can’t be seen when looking through a closer one.