콘텐츠로 건너뛰기

How to enable two-sided rendering in Substance Designer?

如何在 Substance Designer 中启用两侧渲染?

How can I enable Two side rendering in Substance designer?

Yesterday I was asked a question by a colleague of mine I worked with before.

My old colleague was able to figure it out on his own.

Anyway, here are a few things to clear up.

If you’re not a student or a TA, is this really annoying?

Check out the reference links for learning.

昨天,我之前共事过的一位同事问了我一个问题。

我的老同事能够自己弄清楚。

无论如何,这里有一些事情需要澄清。

如果你不是学生或助教,这真的很烦人吗?

查看参考链接进行学习。

Shader API | Substance 3D Painter (adobe.com)

This is a link to the API documentation for writing shaders in Substance Painter.

In the documentation, you will find a State section.

这是在 Substance Painter 中编写着色器的 API 文档的链接。

在文档中,您会找到一个 State 部分,例如.

Let’s check inside the file.让我们检查一下文件内部。

Here is an example state for Backface culling.

The above API is the Substance Painter Shader API.

Now, check if you can refer to the above API document.

这是背面剔除的示例状态。

上面的 API 是 Substance Painter Shader API。

现在,检查您是否可以参考上述 API 文档。

C:\Program Files\Adobe\Adobe Substance 3D Designer\resources\view3d\shaders

There is a shader file in SD in the location.

SD defines shader properties and states in XML format.

This file is usually saved as a file called .glslfx.

Open the above shader location with Open Folder in Sublime Text and search for the cull_off state keyword.

该位置的SD中有一个着色器文件。

SD 以 XML 格式定义着色器属性和状态。

该文件通常保存为名为 .glslfx 的文件。

使用 Open Folder in Sublime Text 打开上述着色器位置,然后搜索 cull_off 状态关键字。

<?xml version="1.0" encoding="UTF-8"?>
<glslfx version="1.0.0" author="Adobe" label="Metallic Roughness">
    <!-- TECHNIQUES -->
    <technique name="Tessellation" label="Tesselation + Displacement">
        <!-- PROPERTIES -->
        <property name="blend_enabled"     value="true"/>
        <property name="blend_func"        value="src_alpha,one_minus_src_alpha"/>
        <property name="cull_face_enabled" value="true"/>
        <property name="cull_face_mode"    value="back"/>
        <!-- SHADERS -->
        <shader type="vertex"       filename="common/tessellation/vs.glsl" primitiveType="patch3"/>
        <shader type="tess_control" filename="common/tessellation/tcs.glsl"/>
        <shader type="tess_eval"    filename="common/tessellation/tes.glsl"/>
        <shader type="fragment"     filename="physically_metallic_roughness/fs.glsl"/>
        <!-- UNIFORMS -->
        <uniform name="parallax_mode"       guiName="Parallax Mode" min="1" max="1" />
        <uniform name="tessellationFactor"		guiGroup="Height"       guiName="Tessellation Factor"	default="4"   min="1" max="64" guiMin="1" guiMax="16" guiStep="1"   guiWidget="slider"/>
        <uniform name="scalarZeroValue"			guiGroup="Height"       guiName="Scalar Zero Value"		default="0.5" min="0" max="1"  guiMin="0" guiMax="1"  guiStep="0.1" guiWidget="slider"/>		
        <!-- PHONG TESSELLATION UNIFORMS -->
        <uniform name="usePhongTessellation"    guiGroup="Height"  guiName="Phong Tessellation"         default="false"      guiWidget="checkbox" />
        <uniform name="phongTessellationFactor" guiGroup="Height"  guiName="Phong Tessellation Factor"  default="0.6" min="0.0" max="1.0" guiMin="0.0" guiMax="1.0" guiStep="0.05" guiWidget="slider"/>
    </technique>
	
    <technique name="Parallax Occlusion" label="Parallax Occlusion">
        <!-- PROPERTIES -->
        <property name="blend_enabled"     value="true"/>
        <property name="blend_func"        value="src_alpha,one_minus_src_alpha"/>
        <property name="cull_face_enabled" value="true"/>
        <property name="cull_face_mode"    value="back"/>
        <!-- SHADERS -->
        <shader type="vertex"   filename="common/parallax/vs.glsl"/>
        <shader type="fragment" filename="physically_metallic_roughness/fs.glsl"/>
        <!-- UNIFORMS -->
        <uniform name="parallax_mode" guiName="Parallax Mode"         min="0" max="0" />
    </technique>

You will find this XML code block. Copy one original glsl fx file and rename it. I created another file with this name.

您将找到此 XML 代码块。 复制一个原始的 glsl fx 文件并重命名。 我用这个名字创建了另一个文件。

physically_metallic_roughness_TwoSide.glslfx

Then you need to change <glslfx version=”1.0.0″ author=”Adobe” label=”Metallic Roughness”> to <glslfx version=”1.0.0″ author=”Adobe” label=”Metallic Roughness TwoSide”> . This part is used as the name of the shader list in the UI.

Then change <property name=”cull_face_enabled” value=”true”/> to <property name=”cull_face_enabled” value=”false”/> .

然后您需要将 <glslfx version=”1.0.0″ author=”Adobe” label=”Metallic Roughness”> 更改为 <glslfx version=”1.0.0″ author=”Adobe” label=”Metallic Roughness TwoSide”> 。 这部分用作 UI 中着色器列表的名称。

然后将 <property name=”cull_face_enabled” value=”true”/> 更改为 <property name=”cull_face_enabled” value=”false”/> 。

<?xml version="1.0" encoding="UTF-8"?>
<glslfx version="1.0.0" author="Adobe" label="Metallic Roughness TwoSide">
    <!-- TECHNIQUES -->
    <technique name="Tessellation" label="Tesselation + Displacement">
        <!-- PROPERTIES -->
        <property name="blend_enabled"     value="true"/>
        <property name="blend_func"        value="src_alpha,one_minus_src_alpha"/>
        <property name="cull_face_enabled" value="false"/>
        <property name="cull_face_mode"    value="back"/>
        <!-- SHADERS -->
        <shader type="vertex"       filename="common/tessellation/vs.glsl" primitiveType="patch3"/>
        <shader type="tess_control" filename="common/tessellation/tcs.glsl"/>
        <shader type="tess_eval"    filename="common/tessellation/tes.glsl"/>
        <shader type="fragment"     filename="physically_metallic_roughness/fs.glsl"/>
        <!-- UNIFORMS -->
        <uniform name="parallax_mode"       guiName="Parallax Mode" min="1" max="1" />
        <uniform name="tessellationFactor"		guiGroup="Height"       guiName="Tessellation Factor"	default="4"   min="1" max="64" guiMin="1" guiMax="16" guiStep="1"   guiWidget="slider"/>
        <uniform name="scalarZeroValue"			guiGroup="Height"       guiName="Scalar Zero Value"		default="0.5" min="0" max="1"  guiMin="0" guiMax="1"  guiStep="0.1" guiWidget="slider"/>		
        <!-- PHONG TESSELLATION UNIFORMS -->
        <uniform name="usePhongTessellation"    guiGroup="Height"  guiName="Phong Tessellation"         default="false"      guiWidget="checkbox" />
        <uniform name="phongTessellationFactor" guiGroup="Height"  guiName="Phong Tessellation Factor"  default="0.6" min="0.0" max="1.0" guiMin="0.0" guiMax="1.0" guiStep="0.05" guiWidget="slider"/>
    </technique>
	
    <technique name="Parallax Occlusion" label="Parallax Occlusion">
        <!-- PROPERTIES -->
        <property name="blend_enabled"     value="true"/>
        <property name="blend_func"        value="src_alpha,one_minus_src_alpha"/>
        <property name="cull_face_enabled" value="false"/>
        <property name="cull_face_mode"    value="back"/>
        <!-- SHADERS -->
        <shader type="vertex"   filename="common/parallax/vs.glsl"/>
        <shader type="fragment" filename="physically_metallic_roughness/fs.glsl"/>
        <!-- UNIFORMS -->
        <uniform name="parallax_mode" guiName="Parallax Mode"         min="0" max="0" />
    </technique>	

If you turn off the Substance designer and rerun it, it will be applied as shown below.

In older versions, you could update a modified shader by pressing Crtl + R.

Lately, I’ve been applying auto-corrected shader compilation (It used to be really uncomfortable.)

如果您关闭 Substance 设计器并重新运行它,它将按如下所示应用。

在旧版本中,您可以通过按 Crtl + R 来更新修改后的着色器。

最近,我一直在应用自动更正的着色器编译(以前真的很不舒服。)

3.1.1.2 Properties
----------------
Allow to set up some part of the OpenGL state.
XML Element Definition:
	- Name: 'property'
	- Attributes:
		- 'name': The name of the property to set. The name are based on the OpenGL function or glEnum name:
			- enum:
				- without the 'GL_' prefix, in lower case.
				- Ex:
					glEnable(GL_BLEND_ENABLE) => "<property name="blend_enabled" value="true"/>"
					glDisable(GL_CULL_FACE) => "<property name="cull_face_enabled" value="false"/>"
			- functions:
				- without the 'gl' prefix, in lower case and with all words separated with '_' character.
				- Ex:
					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) => "<property name="blend_func" value="src_alpha,one_minus_src_alpha"/>"
					'value': The value of the property
			- Allowed properties are:
				|-------------------|---------------------------|-------------------------------------------------------|
				| 'name' values		| 'value' values			| Description 											|
				|-------------------|---------------------------|-------------------------------------------------------|
				| blend_enabled		| boolean 					| Enable/disable the blending mode 						|
				| 					| true 						| 														|
				| 					| false 					| 														|
				|-------------------|---------------------------|-------------------------------------------------------|
				| blend_func		| string, string			| Set the sources and destination blending functions	|
				| 					| zero						| for OpenGL enum GL_ZERO								|
				| 					| one						| for OpenGL enum GL_ONE								|
				| 					| src_color					| for OpenGL enum GL_SRC_COLOR							|
				| 					| one_minus_src_color 		| for OpenGL enum GL_ONE_MINUS_SRC_COLOR				|
				| 					| dst_color					| for OpenGL enum GL_DST_COLOR							|
				| 					| one_minus_dst_color		| for OpenGL enum GL_ONE_MINUS_DST_COLOR				|
			 	| 					| src_alpha					| for OpenGL enum GL_SRC_ALPHA							|
			 	| 					| one_minus_src_alpha 		| for OpenGL enum GL_ONE_MINUS_SRC_ALPHA				|
				| 					| dst_alpha					| for OpenGL enum GL_DST_ALPHA							|
			 	|					| one_minus_dst_alpha		| for OpenGL enum GL_ONE_MINUS_DST_ALPHA				|
				| 					| constant_color			| for OpenGL enum GL_CONSTANT_COLOR						|
				| 					| one_minus_constant_color	| for OpenGL enum GL_ONE_MINUS_CONSTANT_COLOR			|
				| 					| constant_alpha			| for OpenGL enum GL_CONSTANT_ALPHA						|
			 	| 					| one_minus_constant_alpha	| for OpenGL enum GL_ONE_MINUS_CONSTANT_ALPHA			|
			 	| 					| src_alpha_saturate		| for OpenGL enum GL_SRC_ALPHA_SATURATE					|
			 	| 					| src1_color				| for OpenGL enum GL_SRC1_COLOR							|
				| 				 	| one_minus_src1_color		| for OpenGL enum GL_ONE_MINUS_SRC1_COLOR				|
				|					| src1_alpha				| for OpenGL enum GL_SRC1_ALPHA							|
				| 					| one_minus_src1_alpha		| for OpenGL enum GL_ONE_MINUS_SRC1_ALPHA				|
				|-------------------|---------------------------|-------------------------------------------------------|
				| blend_equation	| string					| Set the Blend Equation 								|
				| 					| func_add					| for OpenGL enum GL_FUNC_ADD							|
				| 					| func_subtract				| for OpenGL enum GL_FUNC_SUBTRACT						|
				| 					| func_reverse_subtract		| for OpenGL enum GL_FUNC_REVERSE_SUBTRACT				|
				| 					| min						| for OpenGL enum GL_MIN								|
				| 					| max						| for OpenGL enum GL_MAX								|
				|-------------------|---------------------------|-------------------------------------------------------|
				| cull_face_enabled	| boolean					| Enable/disable the face culling						|
			 	| 					| true						| 														|
				| 					| false						| 														|
				|-------------------|---------------------------|-------------------------------------------------------|
			 	| cull_face_mode	| string					| Set the face culling mode								|
				| 					| front						| for OpenGL enum GL_FRONT								|
				| 					| back						| for OpenGL enum GL_BACK								|
				| 					| front_and_back			| for OpenGL enum GL_FRONT_AND_BACK						|
				|-------------------|---------------------------|-------------------------------------------------------|
				| depth_test_enabled| boolean					| Enable/disable the depth test							|
			 	| 					| true						| 														|
				| 					| false						| 														|
				|-------------------|---------------------------|-------------------------------------------------------|
				| depth_func		| string					| Set the depth compare function						|
				|					| never						| for OpenGL enum GL_NEVER								|
				|					| less						| for OpenGL enum GL_LESS								|
				|					| lequal					| for OpenGL enum GL_LEQUAL								|
				|					| equal						| for OpenGL enum GL_EQUAL								|
				|					| notequal					| for OpenGL enum GL_NOTEQUAL							|
				|					| gequal					| for OpenGL enum GL_GEQUAL								|
				|					| greater					| for OpenGL enum GL_GREATER							|
				|					| always					| for OpenGL enum GL_ALWAYS								|
				|-------------------|---------------------------|-------------------------------------------------------|
    

If you look at the API Format normative book, you can see that it is bound as a property to use the gl function as it is.

To be precise, this would just mean turning off backface culling by removing Cull mode rather than Two Side vertex normal rendering.

Now that Backface Culling is applied, I apply a Two side normal sign to modify the rendering on the opposite side receiving the light to be rendered more correctly.

如果您查看 API 格式规范书,您可以看到它被绑定为一个属性,以按原样使用 gl 函数。

准确地说,这意味着通过移除剔除模式而不是两侧顶点法线渲染来关闭背面剔除。

现在应用了背面剔除,我应用了一个两侧法线符号来修改接收光的另一侧的渲染,以便更正确地渲染。

Navigate and modify the Shader path shown in the picture above. We will edit vs.glsl inside the tessellation folder.

导航并修改上图所示的着色器路径。 我们将在 tessellation 文件夹中编辑 vs.glsl。

/////////////////////////////// Vertex shader
#version 330
in vec4 iVS_Position;
in vec4 iVS_Normal;
in vec2 iVS_UV;
in vec4 iVS_Tangent;
in vec4 iVS_Binormal;
out vec4 oVS_Normal;
out vec2 oVS_UV;
out vec4 oVS_Tangent;
out vec4 oVS_Binormal;
uniform mat4 viewInverseMatrix;
void main()
{
    gl_Position = iVS_Position;
    oVS_Normal = iVS_Normal;
    vec4 viewDir = normalize(viewInverseMatrix[3] - gl_Position);
    float normalSign = sign(dot(oVS_Normal, viewDir));
    oVS_Normal *= normalSign;
    oVS_UV = iVS_UV;
    oVS_Tangent = iVS_Tangent;
    oVS_Binormal = iVS_Binormal;
}

Modifying like above code.

Rendering when only back face culling is changed to false. (There is no distinction between lighting directions)仅背面剔除更改为 false 时的渲染。 (光照方向没有区别)

Apply NormalSign to differentiate the lighting direction and darken it. I took a simple look.

应用 NormalSign 来区分照明方向并使其变暗。 我简单看了一眼。编辑于刚刚

태그:

댓글 남기기

%d 블로거가 이것을 좋아합니다: