• Ogre材质shader模版


    参数设置:

    ->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));

    材质脚本:

    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脚本:

    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

    #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

    #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);
    }
    

      

  • 相关阅读:
    RSS文章订阅及生成RSS格式的xml
    一次Insert插入多条数据的方法
    构建struts2项目需要使用的最少架包
    Java 的HTML 解析器jsoup
    tomcat定时启动
    栈的实现与应用
    软件加密行业的现状和发展趋势
    InstallShield 2012 Spring新功能试用(18): Suite/Advanced UI 和 Advanced UI工程的界面编辑视图中添加了控件工具栏和语言切换功能
    BUG:InstallShield 2012 Spring之前版本的帮助文档中关于StrGetTokens示例代码的错误
    InstallShield 2012 Spring新功能试用(14): Suite/Advanced UI 和 Advanced UI工程新增加InstallScript安装包的条件检测项
  • 原文地址:https://www.cnblogs.com/wiki3d/p/5570918.html
Copyright © 2020-2023  润新知