Ogre材质shader模版,包括如何设置uniform参数

转载自: https://www.cnblogs.com/wiki3d/p/5570918.html


参数设置:

->getSubEntity(0)->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("alpha", starAlpha);
 ->getSubEntity(0)->setCustomParameter(1, Ogre::Vector4(temp.x, temp.y, temp.z, m_fOuterRadius));

 

材质脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
vertex_program _template_VpHL hlsl
{
     source _template_.hlsl
     entry_point main_vs
     target vs_2_0
     // default_params
     // {
         // param_named_auto worldViewProj worldviewproj_matrix
     // }
}
fragment_program _template_FpHL hlsl
{
     source _template_.hlsl
     entry_point main_ps
     target ps_2_0
}
vertex_program _template_VpGL glsl
{
     source _template_Vp.glsl
}
fragment_program _template_FpGL glsl
{
     source _template_Fp.glsl
     default_params
     {
         param_named diffuseMap  int  0
     }
}
  
vertex_program _template_Vp unified
{
     delegate _template_VpGL
     delegate _template_VpHL
}
fragment_program _template_Fp unified
{
     delegate _template_FpGL
     delegate _template_FpHL
}
 
 
material mat/_template_
{ technique { pass {
     vertex_program_ref _template_Vp
     {
         param_named_auto worldViewProj worldviewproj_matrix
         
         // param_named  alpha       float 1
         // param_named  f4          float4  1 0 0 1
         // param_named  mat4        matrix4x4  1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
     }
     fragment_program_ref _template_Fp
     { }
     
     texture_unit
     {
         texture t0.jpg 2d 0
     }
     
     //polygon_mode  wireframe
     //lighting off
     
     // point_sprites on
     // point_size 11   // for opengl
     // point_size_attenuation off
     // point_size_min 1
     // point_size_max 32
     
     //scene_blend alpha_blend
     //scene_blend add
     //scene_blend src_alpha one
     
     //cull_hardware anticlockwise
     //cull_software front
     //depth_write off
     //depth_check off
 
} } }

  

HLSL脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
float  scale( float  f1, inout  float  f2)
{
     f2 = f1*2;
     return  f2+f1;
}
 
void  main_vs
(
     in float4 inPos :   POSITION,
     in float4 inColor:  COLOR,
     in float2 inUV:     TEXCOORD0,
     
     out float4 outPos:  POSITION,
     out float4 outColor:COLOR,
     out float2 outUV:   TEXCOORD0,
     //out float  outSize:   PSIZE,
     
      uniform float4x4 worldViewProj
)
{
     outPos = mul(worldViewProj, inPos);
     // if(outPos.z / outPos.w > 1)
     // {
             // outPos.z = outPos.w;
     // }
     outUV = inUV; // float2(inUV.x / 10, inUV.y);
     //outColor = inColor;
     outColor = float4(0.0, 0, 1.0, 1);
     //outSize = outColor.r * 16.0;
}
  
 
float4 main_ps(
     float2  uv :            TEXCOORD0,
     float4  inColor:        COLOR,
     
     uniform sampler2D diffuseMap :  register (s0)
) : COLOR
{
     float4 color= tex2D(diffuseMap, uv) * inColor;
     
     // float c = abs(uv.x-0.5);
     // float x = smoothstep(0, 1, c)  + 0.1;
     // float4 temp = float4(x, x, x, 1);
     
     return  color;
}

  

GLSL脚本:

_template_Vp.glsl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#version 120
 
varying vec2 uv;
 
// varying vec3 mycolor;
// varying vec3 mysecondsecolor;
 
//uniform float alpha;
//uniform vec4  v4;
//uniform mat4  worldViewProj;
 
void  main( void )
{
     //vec3 v3Pos = gl_Vertex.xyz;
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     if (gl_Position.z / gl_Position.w > 1)
     {
         gl_Position.z = gl_Position.w;
     }
  
     ///gl_FrontColor = gl_Color;
     gl_FrontColor = vec4(0, 0, 1, 1);
     //gl_FrontSecondaryColor.rgb = vec3(1, 1, 1);
     
     // float fFar = length(v3Pos);
     //gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
     uv = gl_MultiTexCoord0.xy;
      
     //float f = dot(v3, v3);
     //float f = length(v3);
}

  _template_Fp.glsl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#version 120
 
uniform sampler2D diffuseMap;
varying vec2 uv;
 
void  main(  void  )
{
     vec4 color = texture2D(diffuseMap, uv);  //gl_TexCoord[0].xy
     gl_FragColor =  color * clamp(gl_Color, 0.5, 1.0);
 
     // float b1 = 1.0-(2.0*abs(gl_PointCoord.s-0.5));
     // float x = smoothstep(0, 1, gl_Color.r) + 0.1;
     
     //gl_FragColor =  vec4(uv, 0, 1);
     //gl_FragColor = gl_Color + gl_SecondaryColor;
     //gl_FragColor = 1.0 - exp(f4Color * -1.5);
}

  

标签:  ogre glsl hlsl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值